github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/whisper/whisperv6/api_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:46</date> 10 //</624450125091049472> 11 12 13 package whisperv6 14 15 import ( 16 "bytes" 17 "testing" 18 "time" 19 ) 20 21 func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) { 22 w := New(nil) 23 24 keyID, err := w.GenerateSymKey() 25 if err != nil { 26 t.Fatalf("Error generating symmetric key: %v", err) 27 } 28 api := PublicWhisperAPI{ 29 w: w, 30 lastUsed: make(map[string]time.Time), 31 } 32 33 t1 := [4]byte{0xde, 0xea, 0xbe, 0xef} 34 t2 := [4]byte{0xca, 0xfe, 0xde, 0xca} 35 36 crit := Criteria{ 37 SymKeyID: keyID, 38 Topics: []TopicType{TopicType(t1), TopicType(t2)}, 39 } 40 41 _, err = api.NewMessageFilter(crit) 42 if err != nil { 43 t.Fatalf("Error creating the filter: %v", err) 44 } 45 46 found := false 47 candidates := w.filters.getWatchersByTopic(TopicType(t1)) 48 for _, f := range candidates { 49 if len(f.Topics) == 2 { 50 if bytes.Equal(f.Topics[0], t1[:]) && bytes.Equal(f.Topics[1], t2[:]) { 51 found = true 52 } 53 } 54 } 55 56 if !found { 57 t.Fatalf("Could not find filter with both topics") 58 } 59 } 60