aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/whisperv6/whisper_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/whisperv6/whisper_test.go')
-rw-r--r--whisper/whisperv6/whisper_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/whisper/whisperv6/whisper_test.go b/whisper/whisperv6/whisper_test.go
index b391a1161..fa14acb1b 100644
--- a/whisper/whisperv6/whisper_test.go
+++ b/whisper/whisperv6/whisper_test.go
@@ -843,3 +843,64 @@ func TestSymmetricSendKeyMismatch(t *testing.T) {
t.Fatalf("received a message when keys weren't matching")
}
}
+
+func TestBloom(t *testing.T) {
+ topic := TopicType{0, 0, 255, 6}
+ b := TopicToBloom(topic)
+ x := make([]byte, bloomFilterSize)
+ x[0] = byte(1)
+ x[32] = byte(1)
+ x[bloomFilterSize-1] = byte(128)
+ if !bloomFilterMatch(x, b) || !bloomFilterMatch(b, x) {
+ t.Fatalf("bloom filter does not match the mask")
+ }
+
+ _, err := mrand.Read(b)
+ if err != nil {
+ t.Fatalf("math rand error")
+ }
+ _, err = mrand.Read(x)
+ if err != nil {
+ t.Fatalf("math rand error")
+ }
+ if !bloomFilterMatch(b, b) {
+ t.Fatalf("bloom filter does not match self")
+ }
+ x = addBloom(x, b)
+ if !bloomFilterMatch(x, b) {
+ t.Fatalf("bloom filter does not match combined bloom")
+ }
+ if !isFullNode(nil) {
+ t.Fatalf("isFullNode did not recognize nil as full node")
+ }
+ x[17] = 254
+ if isFullNode(x) {
+ t.Fatalf("isFullNode false positive")
+ }
+ for i := 0; i < bloomFilterSize; i++ {
+ b[i] = byte(255)
+ }
+ if !isFullNode(b) {
+ t.Fatalf("isFullNode false negative")
+ }
+ if bloomFilterMatch(x, b) {
+ t.Fatalf("bloomFilterMatch false positive")
+ }
+ if !bloomFilterMatch(b, x) {
+ t.Fatalf("bloomFilterMatch false negative")
+ }
+
+ w := New(&DefaultConfig)
+ f := w.BloomFilter()
+ if f != nil {
+ t.Fatalf("wrong bloom on creation")
+ }
+ err = w.SetBloomFilter(x)
+ if err != nil {
+ t.Fatalf("failed to set bloom filter: %s", err)
+ }
+ f = w.BloomFilter()
+ if !bloomFilterMatch(f, x) || !bloomFilterMatch(x, f) {
+ t.Fatalf("retireved wrong bloom filter")
+ }
+}