diff options
author | gluk256 <gluk256@users.noreply.github.com> | 2018-01-12 19:11:22 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2018-01-12 19:11:22 +0800 |
commit | fd869dc839e2b3696e130224a43b9b25455ceb46 (patch) | |
tree | f19c5db8acac542f451cceac216333f7a75a2ef5 /whisper/whisperv6/whisper_test.go | |
parent | 56152b31ac251d1cc68fcddbdad159ba5234c415 (diff) | |
download | dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.tar dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.tar.gz dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.tar.bz2 dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.tar.lz dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.tar.xz dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.tar.zst dexon-fd869dc839e2b3696e130224a43b9b25455ceb46.zip |
whisper/whisperv6: implement pow/bloom exchange protocol (#15802)
This is the main feature of v6.
Diffstat (limited to 'whisper/whisperv6/whisper_test.go')
-rw-r--r-- | whisper/whisperv6/whisper_test.go | 61 |
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") + } +} |