mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
whisper: fixed the tests
This commit is contained in:
parent
4bd592a70c
commit
8b96630df6
4 changed files with 19 additions and 14 deletions
|
|
@ -118,7 +118,7 @@ func (api *PublicWhisperAPI) SetMaxMessageSize(ctx context.Context, size uint32)
|
||||||
|
|
||||||
// SetMinPow sets the minimum PoW for a message before it is accepted.
|
// SetMinPow sets the minimum PoW for a message before it is accepted.
|
||||||
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
|
func (api *PublicWhisperAPI) SetMinPoW(ctx context.Context, pow float64) (bool, error) {
|
||||||
return true, api.w.SetMinimumPoW(pow)
|
return true, api.w.SetMinimumPoW(pow, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkTrustedPeer marks a peer trusted. , which will allow it to send historic (expired) messages.
|
// MarkTrustedPeer marks a peer trusted. , which will allow it to send historic (expired) messages.
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ func initialize(t *testing.T) {
|
||||||
for i := 0; i < NumNodes; i++ {
|
for i := 0; i < NumNodes; i++ {
|
||||||
var node TestNode
|
var node TestNode
|
||||||
node.shh = New(&DefaultConfig)
|
node.shh = New(&DefaultConfig)
|
||||||
node.shh.SetMinimumPoW(0.00000001)
|
node.shh.SetMinimumPoW(0.00000001, true)
|
||||||
node.shh.Start(nil)
|
node.shh.Start(nil)
|
||||||
topics := make([]TopicType, 0)
|
topics := make([]TopicType, 0)
|
||||||
topics = append(topics, sharedTopic)
|
topics = append(topics, sharedTopic)
|
||||||
|
|
|
||||||
|
|
@ -181,17 +181,22 @@ func (w *Whisper) SetMaxMessageSize(size uint32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMinimumPoW sets the minimal PoW required by this node
|
// SetMinimumPoW sets the minimal PoW required by this node
|
||||||
func (w *Whisper) SetMinimumPoW(val float64) error {
|
func (w *Whisper) SetMinimumPoW(val float64, testMode bool) error {
|
||||||
if val <= 0.0 {
|
if val <= 0.0 {
|
||||||
return fmt.Errorf("invalid PoW: %f", val)
|
return fmt.Errorf("invalid PoW: %f", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.notifyPeersAboutPowRequirementChange(val)
|
w.notifyPeersAboutPowRequirementChange(val)
|
||||||
|
|
||||||
|
if testMode {
|
||||||
|
w.settings.Store(minPowIdx, val)
|
||||||
|
} else {
|
||||||
go func() {
|
go func() {
|
||||||
// allow some time before all the peers have processed the notification
|
// // allow some time before all the peers have processed the notification
|
||||||
time.Sleep(time.Duration(w.reactionAllowance) * time.Second)
|
time.Sleep(time.Duration(w.reactionAllowance) * time.Second)
|
||||||
w.settings.Store(minPowIdx, val)
|
w.settings.Store(minPowIdx, val)
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -472,8 +472,8 @@ func TestExpiry(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
w.SetMinimumPoW(0.0000001)
|
w.SetMinimumPoW(0.0000001, true)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW)
|
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
||||||
|
|
@ -529,7 +529,7 @@ func TestCustomization(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW)
|
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
@ -563,7 +563,7 @@ func TestCustomization(t *testing.T) {
|
||||||
t.Fatalf("successfully sent envelope with PoW %.06f, false positive (seed %d).", env.PoW(), seed)
|
t.Fatalf("successfully sent envelope with PoW %.06f, false positive (seed %d).", env.PoW(), seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.SetMinimumPoW(smallPoW / 2)
|
w.SetMinimumPoW(smallPoW/2, true)
|
||||||
err = w.Send(env)
|
err = w.Send(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
|
t.Fatalf("failed to send envelope with seed %d: %s.", seed, err)
|
||||||
|
|
@ -625,7 +625,7 @@ func TestSymmetricSendCycle(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW)
|
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
@ -714,7 +714,7 @@ func TestSymmetricSendWithoutAKey(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW)
|
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
@ -782,7 +782,7 @@ func TestSymmetricSendKeyMismatch(t *testing.T) {
|
||||||
InitSingleTest()
|
InitSingleTest()
|
||||||
|
|
||||||
w := New(&DefaultConfig)
|
w := New(&DefaultConfig)
|
||||||
defer w.SetMinimumPoW(DefaultMinimumPoW)
|
defer w.SetMinimumPoW(DefaultMinimumPoW, true)
|
||||||
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
defer w.SetMaxMessageSize(DefaultMaxMessageSize)
|
||||||
w.Start(nil)
|
w.Start(nil)
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue