api_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. package whisperv6
  17. import (
  18. "bytes"
  19. "testing"
  20. "time"
  21. )
  22. func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
  23. stack, w := newNodeWithWhisper(t)
  24. defer stack.Close()
  25. keyID, err := w.GenerateSymKey()
  26. if err != nil {
  27. t.Fatalf("Error generating symmetric key: %v", err)
  28. }
  29. api := PublicWhisperAPI{
  30. w: w,
  31. lastUsed: make(map[string]time.Time),
  32. }
  33. t1 := [4]byte{0xde, 0xea, 0xbe, 0xef}
  34. t2 := [4]byte{0xca, 0xfe, 0xde, 0xca}
  35. crit := Criteria{
  36. SymKeyID: keyID,
  37. Topics: []TopicType{TopicType(t1), TopicType(t2)},
  38. }
  39. _, err = api.NewMessageFilter(crit)
  40. if err != nil {
  41. t.Fatalf("Error creating the filter: %v", err)
  42. }
  43. found := false
  44. candidates := w.filters.getWatchersByTopic(TopicType(t1))
  45. for _, f := range candidates {
  46. if len(f.Topics) == 2 {
  47. if bytes.Equal(f.Topics[0], t1[:]) && bytes.Equal(f.Topics[1], t2[:]) {
  48. found = true
  49. }
  50. }
  51. }
  52. if !found {
  53. t.Fatalf("Could not find filter with both topics")
  54. }
  55. }