|
| 1 | +// Copyright 2018 The go-ethereum Authors |
| 2 | +// This file is part of the go-ethereum library. |
| 3 | +// |
| 4 | +// The go-ethereum library is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// The go-ethereum library is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package whisperv6 |
| 18 | + |
| 19 | +import ( |
| 20 | + "bytes" |
| 21 | + "crypto/ecdsa" |
| 22 | + "testing" |
| 23 | + "time" |
| 24 | + |
| 25 | + "github.com/ethereum/go-ethereum/common" |
| 26 | + set "gopkg.in/fatih/set.v0" |
| 27 | +) |
| 28 | + |
| 29 | +func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) { |
| 30 | + w := &Whisper{ |
| 31 | + privateKeys: make(map[string]*ecdsa.PrivateKey), |
| 32 | + symKeys: make(map[string][]byte), |
| 33 | + envelopes: make(map[common.Hash]*Envelope), |
| 34 | + expirations: make(map[uint32]*set.SetNonTS), |
| 35 | + peers: make(map[*Peer]struct{}), |
| 36 | + messageQueue: make(chan *Envelope, messageQueueLimit), |
| 37 | + p2pMsgQueue: make(chan *Envelope, messageQueueLimit), |
| 38 | + quit: make(chan struct{}), |
| 39 | + syncAllowance: DefaultSyncAllowance, |
| 40 | + } |
| 41 | + w.filters = NewFilters(w) |
| 42 | + |
| 43 | + keyID, err := w.GenerateSymKey() |
| 44 | + if err != nil { |
| 45 | + t.Fatalf("Error generating symmetric key: %v", err) |
| 46 | + } |
| 47 | + api := PublicWhisperAPI{ |
| 48 | + w: w, |
| 49 | + lastUsed: make(map[string]time.Time), |
| 50 | + } |
| 51 | + |
| 52 | + t1 := [4]byte{0xde, 0xea, 0xbe, 0xef} |
| 53 | + t2 := [4]byte{0xca, 0xfe, 0xde, 0xca} |
| 54 | + |
| 55 | + crit := Criteria{ |
| 56 | + SymKeyID: keyID, |
| 57 | + Topics: []TopicType{TopicType(t1), TopicType(t2)}, |
| 58 | + } |
| 59 | + |
| 60 | + _, err = api.NewMessageFilter(crit) |
| 61 | + if err != nil { |
| 62 | + t.Fatalf("Error creating the filter: %v", err) |
| 63 | + } |
| 64 | + |
| 65 | + found := false |
| 66 | + candidates := w.filters.getWatchersByTopic(TopicType(t1)) |
| 67 | + for _, f := range candidates { |
| 68 | + if len(f.Topics) == 2 { |
| 69 | + if bytes.Equal(f.Topics[0], t1[:]) && bytes.Equal(f.Topics[1], t2[:]) { |
| 70 | + found = true |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + if !found { |
| 76 | + t.Fatalf("Could not find filter with both topics") |
| 77 | + } |
| 78 | +} |
0 commit comments