github.com/status-im/status-go@v1.1.0/wakuv2/api_test.go (about) 1 // Copyright 2019 The Waku Library Authors. 2 // 3 // The Waku library is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Lesser General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // The Waku library is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty off 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Lesser General Public License for more details. 12 // 13 // You should have received a copy of the GNU Lesser General Public License 14 // along with the Waku library. If not, see <http://www.gnu.org/licenses/>. 15 // 16 // This software uses the go-ethereum library, which is licensed 17 // under the GNU Lesser General Public Library, version 3 or any later. 18 19 package wakuv2 20 21 import ( 22 "testing" 23 "time" 24 25 "golang.org/x/exp/maps" 26 27 "github.com/status-im/status-go/protocol/common/shard" 28 "github.com/status-im/status-go/wakuv2/common" 29 ) 30 31 func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) { 32 w, err := New(nil, "", nil, nil, nil, nil, nil, nil) 33 if err != nil { 34 t.Fatalf("Error creating WakuV2 client: %v", err) 35 } 36 37 keyID, err := w.GenerateSymKey() 38 if err != nil { 39 t.Fatalf("Error generating symmetric key: %v", err) 40 } 41 api := PublicWakuAPI{ 42 w: w, 43 lastUsed: make(map[string]time.Time), 44 } 45 46 t1 := common.TopicType([4]byte{0xde, 0xea, 0xbe, 0xef}) 47 t2 := common.TopicType([4]byte{0xca, 0xfe, 0xde, 0xca}) 48 49 crit := Criteria{ 50 SymKeyID: keyID, 51 ContentTopics: []common.TopicType{t1, t2}, 52 } 53 54 _, err = api.NewMessageFilter(crit) 55 if err != nil { 56 t.Fatalf("Error creating the filter: %v", err) 57 } 58 59 found := false 60 candidates := w.filters.GetWatchersByTopic(shard.DefaultShardPubsubTopic(), t1) 61 for _, f := range candidates { 62 if maps.Equal(f.ContentTopics, common.NewTopicSet(crit.ContentTopics)) { 63 found = true 64 break 65 } 66 } 67 68 if !found { 69 t.Fatalf("Could not find filter with both topics") 70 } 71 }