aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/mailserver/server_test.go
diff options
context:
space:
mode:
authorVlad <gluk256@gmail.com>2018-03-01 23:04:09 +0800
committerVlad <gluk256@gmail.com>2018-03-01 23:04:09 +0800
commitee75a90ab41fd9a2e5676a2371e529ac2908befa (patch)
tree4545344b40b16757115b081b6bedd610ceb591e1 /whisper/mailserver/server_test.go
parent5a150e1b7724c91009a237ab0879cd64844b390d (diff)
downloaddexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar
dexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.gz
dexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.bz2
dexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.lz
dexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.xz
dexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.tar.zst
dexon-ee75a90ab41fd9a2e5676a2371e529ac2908befa.zip
whisper: topics replaced by bloom filters
Diffstat (limited to 'whisper/mailserver/server_test.go')
-rw-r--r--whisper/mailserver/server_test.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/whisper/mailserver/server_test.go b/whisper/mailserver/server_test.go
index 63864c1e6..d5b993afb 100644
--- a/whisper/mailserver/server_test.go
+++ b/whisper/mailserver/server_test.go
@@ -17,6 +17,7 @@
package mailserver
import (
+ "bytes"
"crypto/ecdsa"
"encoding/binary"
"io/ioutil"
@@ -61,7 +62,7 @@ func generateEnvelope(t *testing.T) *whisper.Envelope {
h := crypto.Keccak256Hash([]byte("test sample data"))
params := &whisper.MessageParams{
KeySym: h[:],
- Topic: whisper.TopicType{},
+ Topic: whisper.TopicType{0x1F, 0x7E, 0xA1, 0x7F},
Payload: []byte("test payload"),
PoW: powRequirement,
WorkTime: 2,
@@ -121,6 +122,7 @@ func deliverTest(t *testing.T, server *WMailServer, env *whisper.Envelope) {
upp: birth + 1,
key: testPeerID,
}
+
singleRequest(t, server, env, p, true)
p.low, p.upp = birth+1, 0xffffffff
@@ -131,14 +133,14 @@ func deliverTest(t *testing.T, server *WMailServer, env *whisper.Envelope) {
p.low = birth - 1
p.upp = birth + 1
- p.topic[0]++
+ p.topic[0] = 0xFF
singleRequest(t, server, env, p, false)
}
func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *ServerTestParams, expect bool) {
request := createRequest(t, p)
src := crypto.FromECDSAPub(&p.key.PublicKey)
- ok, lower, upper, topic := server.validateRequest(src, request)
+ ok, lower, upper, bloom := server.validateRequest(src, request)
if !ok {
t.Fatalf("request validation failed, seed: %d.", seed)
}
@@ -148,12 +150,13 @@ func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *
if upper != p.upp {
t.Fatalf("request validation failed (upper bound), seed: %d.", seed)
}
- if topic != p.topic {
+ expectedBloom := whisper.TopicToBloom(p.topic)
+ if !bytes.Equal(bloom, expectedBloom) {
t.Fatalf("request validation failed (topic), seed: %d.", seed)
}
var exist bool
- mail := server.processRequest(nil, p.low, p.upp, p.topic)
+ mail := server.processRequest(nil, p.low, p.upp, bloom)
for _, msg := range mail {
if msg.Hash() == env.Hash() {
exist = true
@@ -166,7 +169,7 @@ func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *
}
src[0]++
- ok, lower, upper, topic = server.validateRequest(src, request)
+ ok, lower, upper, bloom = server.validateRequest(src, request)
if !ok {
// request should be valid regardless of signature
t.Fatalf("request validation false negative, seed: %d (lower: %d, upper: %d).", seed, lower, upper)
@@ -174,10 +177,11 @@ func singleRequest(t *testing.T, server *WMailServer, env *whisper.Envelope, p *
}
func createRequest(t *testing.T, p *ServerTestParams) *whisper.Envelope {
- data := make([]byte, 8+whisper.TopicLength)
+ bloom := whisper.TopicToBloom(p.topic)
+ data := make([]byte, 8)
binary.BigEndian.PutUint32(data, p.low)
binary.BigEndian.PutUint32(data[4:], p.upp)
- copy(data[8:], p.topic[:])
+ data = append(data, bloom...)
key, err := shh.GetSymKey(keyID)
if err != nil {