whisperv6: remove duplicated code from api_test.go

This commit is contained in:
CoreyLin 2018-12-03 20:49:25 +08:00
parent 2e9d1502d4
commit 373b95a833
2 changed files with 12 additions and 17 deletions

View file

@ -23,8 +23,7 @@ import (
)
func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
w := newDefaultWhisper()
w.filters = NewFilters(w)
w := New(nil)
keyID, err := w.GenerateSymKey()
if err != nil {

View file

@ -96,7 +96,17 @@ func New(cfg *Config) *Whisper {
cfg = &DefaultConfig
}
whisper := newDefaultWhisper()
whisper := &Whisper{
privateKeys: make(map[string]*ecdsa.PrivateKey),
symKeys: make(map[string][]byte),
envelopes: make(map[common.Hash]*Envelope),
expirations: make(map[uint32]mapset.Set),
peers: make(map[*Peer]struct{}),
messageQueue: make(chan *Envelope, messageQueueLimit),
p2pMsgQueue: make(chan *Envelope, messageQueueLimit),
quit: make(chan struct{}),
syncAllowance: DefaultSyncAllowance,
}
whisper.filters = NewFilters(whisper)
@ -123,20 +133,6 @@ func New(cfg *Config) *Whisper {
return whisper
}
func newDefaultWhisper() *Whisper {
return &Whisper{
privateKeys: make(map[string]*ecdsa.PrivateKey),
symKeys: make(map[string][]byte),
envelopes: make(map[common.Hash]*Envelope),
expirations: make(map[uint32]mapset.Set),
peers: make(map[*Peer]struct{}),
messageQueue: make(chan *Envelope, messageQueueLimit),
p2pMsgQueue: make(chan *Envelope, messageQueueLimit),
quit: make(chan struct{}),
syncAllowance: DefaultSyncAllowance,
}
}
// MinPow returns the PoW value required by this node.
func (whisper *Whisper) MinPow() float64 {
val, exist := whisper.settings.Load(minPowIdx)