diff options
author | gluk256 <gluk256@users.noreply.github.com> | 2016-12-02 03:09:22 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-12-02 03:09:22 +0800 |
commit | 2dcf75a722f193ef5528f5af8fb4fd7c5824fded (patch) | |
tree | a30e617df7e75bc8afd3d38cf3388b2bb986479a /whisper/whisperv5/peer_test.go | |
parent | 671fd94e256fb33761dc3b0ae2b8b6374d1d9576 (diff) | |
download | go-tangerine-2dcf75a722f193ef5528f5af8fb4fd7c5824fded.tar.gz go-tangerine-2dcf75a722f193ef5528f5af8fb4fd7c5824fded.tar.zst go-tangerine-2dcf75a722f193ef5528f5af8fb4fd7c5824fded.zip |
whisper/shhapi, whisper/whisperv5: refactoring (#3364)
* Filter refactoring
* API tests added + bugfix
* fixed the error logs
* FilterID fixed
* test cases fixed
* key generation updated
* POW updated
* got rid of redundant stuff
Diffstat (limited to 'whisper/whisperv5/peer_test.go')
-rw-r--r-- | whisper/whisperv5/peer_test.go | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/whisper/whisperv5/peer_test.go b/whisper/whisperv5/peer_test.go index 03c4725d8..082e7f446 100644 --- a/whisper/whisperv5/peer_test.go +++ b/whisper/whisperv5/peer_test.go @@ -79,7 +79,7 @@ type TestNode struct { shh *Whisper id *ecdsa.PrivateKey server *p2p.Server - filerId int + filerId uint32 } var result TestData @@ -94,19 +94,19 @@ var expectedMessage []byte = []byte("per rectum ad astra") // 3. each node sends a number of random (undecryptable) messages, // 4. first node sends one expected (decryptable) message, // 5. checks if each node have received and decrypted exactly one message. -func TestSimulation(x *testing.T) { - initialize(x) +func TestSimulation(t *testing.T) { + initialize(t) for i := 0; i < NumNodes; i++ { - sendMsg(x, false, i) + sendMsg(t, false, i) } - sendMsg(x, true, 0) - checkPropagation(x) + sendMsg(t, true, 0) + checkPropagation(t) stopServers() } -func initialize(x *testing.T) { +func initialize(t *testing.T) { //glog.SetV(6) //glog.SetToStderr(true) @@ -118,14 +118,13 @@ func initialize(x *testing.T) { var node TestNode node.shh = NewWhisper(nil) node.shh.test = true - tt := make([]TopicType, 0) - tt = append(tt, sharedTopic) - f := Filter{KeySym: sharedKey, Topics: tt} + topics := make([]TopicType, 0) + topics = append(topics, sharedTopic) + f := Filter{KeySym: sharedKey, Topics: topics} node.filerId = node.shh.Watch(&f) node.id, err = crypto.HexToECDSA(keys[i]) if err != nil { - x.Errorf("failed convert the key: %s.", keys[i]) - return + t.Fatalf("failed convert the key: %s.", keys[i]) } port := port0 + i addr := fmt.Sprintf(":%d", port) // e.g. ":30303" @@ -155,8 +154,7 @@ func initialize(x *testing.T) { err = node.server.Start() if err != nil { - x.Errorf("failed to start server %d.", i) - return + t.Fatalf("failed to start server %d.", i) } nodes[i] = &node @@ -173,8 +171,8 @@ func stopServers() { } } -func checkPropagation(x *testing.T) { - if x.Failed() { +func checkPropagation(t *testing.T) { + if t.Failed() { return } @@ -187,26 +185,24 @@ func checkPropagation(x *testing.T) { for i := 0; i < NumNodes; i++ { f := nodes[i].shh.GetFilter(nodes[i].filerId) if f == nil { - x.Errorf("failed to get filterId %d from node %d.", nodes[i].filerId, i) - return + t.Fatalf("failed to get filterId %d from node %d.", nodes[i].filerId, i) } mail := f.Retrieve() - if !validateMail(x, i, mail) { + if !validateMail(t, i, mail) { return } if isTestComplete() { - return } } } - x.Errorf("Test was not complete: timeout %d seconds.", iterations*cycle/1000) + t.Fatalf("Test was not complete: timeout %d seconds.", iterations*cycle/1000) } -func validateMail(x *testing.T, index int, mail []*ReceivedMessage) bool { +func validateMail(t *testing.T, index int, mail []*ReceivedMessage) bool { var cnt int for _, m := range mail { if bytes.Compare(m.Payload, expectedMessage) == 0 { @@ -219,7 +215,7 @@ func validateMail(x *testing.T, index int, mail []*ReceivedMessage) bool { return true } if cnt > 1 { - x.Errorf("node %d received %d.", index, cnt) + t.Fatalf("node %d received %d.", index, cnt) return false } @@ -228,8 +224,7 @@ func validateMail(x *testing.T, index int, mail []*ReceivedMessage) bool { defer result.mutex.Unlock() result.counter[index] += cnt if result.counter[index] > 1 { - x.Errorf("node %d accumulated %d.", index, result.counter[index]) - return false + t.Fatalf("node %d accumulated %d.", index, result.counter[index]) } } return true @@ -255,8 +250,8 @@ func isTestComplete() bool { return true } -func sendMsg(x *testing.T, expected bool, id int) { - if x.Failed() { +func sendMsg(t *testing.T, expected bool, id int) { + if t.Failed() { return } @@ -270,38 +265,33 @@ func sendMsg(x *testing.T, expected bool, id int) { msg := NewSentMessage(&opt) envelope, err := msg.Wrap(&opt) if err != nil { - x.Errorf("failed to seal message.") - return + t.Fatalf("failed to seal message.") } err = nodes[id].shh.Send(envelope) if err != nil { - x.Errorf("failed to send message.") - return + t.Fatalf("failed to send message.") } } -func TestPeerBasic(x *testing.T) { +func TestPeerBasic(t *testing.T) { InitSingleTest() params, err := generateMessageParams() if err != nil { - x.Errorf("failed 1 with seed %d.", seed) - return + t.Fatalf("failed generateMessageParams with seed %d.", seed) } params.PoW = 0.001 msg := NewSentMessage(params) env, err := msg.Wrap(params) if err != nil { - x.Errorf("failed 2 with seed %d.", seed) - return + t.Fatalf("failed Wrap with seed %d.", seed) } p := newPeer(nil, nil, nil) p.mark(env) if !p.marked(env) { - x.Errorf("failed 3 with seed %d.", seed) - return + t.Fatalf("failed mark with seed %d.", seed) } } |