aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv6/filter_test.go
diff options
context:
space:
mode:
authorb00ris <b00ris@mail.ru>2018-01-26 19:41:53 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-01-26 19:41:53 +0800
commit2ef3815af41c7a12dd798416b4a5ae74c09706c8 (patch)
treedbddf454c44306cdf6f223f155c7ae7e08f0b32d /whisper/whisperv6/filter_test.go
parent4dd0727c393fcade1a6835db2f753f0a365ed073 (diff)
downloadgo-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.tar
go-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.tar.gz
go-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.tar.bz2
go-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.tar.lz
go-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.tar.xz
go-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.tar.zst
go-tangerine-2ef3815af41c7a12dd798416b4a5ae74c09706c8.zip
whisper: fix empty topic (#15811)
* whisper: fix empty topic * whisper: add check to matchSingleTopic * whisper: add tests * whisper: fix gosimple * whisper: added lastTopicByte const
Diffstat (limited to 'whisper/whisperv6/filter_test.go')
-rw-r--r--whisper/whisperv6/filter_test.go44
1 files changed, 39 insertions, 5 deletions
diff --git a/whisper/whisperv6/filter_test.go b/whisper/whisperv6/filter_test.go
index e2877b233..9c7fdad95 100644
--- a/whisper/whisperv6/filter_test.go
+++ b/whisper/whisperv6/filter_test.go
@@ -800,6 +800,7 @@ func TestWatchers(t *testing.T) {
func TestVariableTopics(t *testing.T) {
InitSingleTest()
+ const lastTopicByte = 3
var match bool
params, err := generateMessageParams()
if err != nil {
@@ -820,19 +821,52 @@ func TestVariableTopics(t *testing.T) {
}
for i := 0; i < 4; i++ {
- arr := make([]byte, i+1, 4)
- copy(arr, env.Topic[:i+1])
-
- f.Topics[4] = arr
+ env.Topic = BytesToTopic(f.Topics[i])
match = f.MatchEnvelope(env)
if !match {
t.Fatalf("failed MatchEnvelope symmetric with seed %d, step %d.", seed, i)
}
- f.Topics[4][i]++
+ f.Topics[i][lastTopicByte]++
match = f.MatchEnvelope(env)
if match {
t.Fatalf("MatchEnvelope symmetric with seed %d, step %d: false positive.", seed, i)
}
}
}
+
+func TestMatchSingleTopic_ReturnTrue(t *testing.T) {
+ bt := []byte("test")
+ topic := BytesToTopic(bt)
+
+ if !matchSingleTopic(topic, bt) {
+ t.FailNow()
+ }
+}
+
+func TestMatchSingleTopic_WithTail_ReturnTrue(t *testing.T) {
+ bt := []byte("test with tail")
+ topic := BytesToTopic([]byte("test"))
+
+ if !matchSingleTopic(topic, bt) {
+ t.FailNow()
+ }
+}
+
+func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) {
+ bt := []byte("tes")
+ topic := BytesToTopic(bt)
+
+ if matchSingleTopic(topic, bt) {
+ t.FailNow()
+ }
+}
+
+func TestMatchSingleTopic_InsufficientLength_ReturnFalse(t *testing.T) {
+ bt := []byte("test")
+ topic := BytesToTopic([]byte("not_equal"))
+
+ if matchSingleTopic(topic, bt) {
+ t.FailNow()
+ }
+}