diff options
author | gluk256 <gluk256@users.noreply.github.com> | 2018-01-30 16:55:08 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-01-30 16:55:08 +0800 |
commit | a9e4a90d57d3c072fb727ee62b71002325e23934 (patch) | |
tree | 45b0cd4885ebfb562fe0dbeb8b8b9d6859875401 /whisper/whisperv6/peer_test.go | |
parent | 59a852e4188e18e587b6d54f646a6780f4d1f12c (diff) | |
download | dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.tar dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.tar.gz dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.tar.bz2 dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.tar.lz dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.tar.xz dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.tar.zst dexon-a9e4a90d57d3c072fb727ee62b71002325e23934.zip |
whisper: change the whisper message format so as to add the payload size (#15870)
* whisper: message format changed
* whisper: tests fixed
* whisper: style fixes
* whisper: fixed names, fixed failing tests
* whisper: fix merge issue in #15870
Occured while using the github online merge tool. Lesson learned.
* whisper: fix a gofmt error for #15870
Diffstat (limited to 'whisper/whisperv6/peer_test.go')
-rw-r--r-- | whisper/whisperv6/peer_test.go | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/whisper/whisperv6/peer_test.go b/whisper/whisperv6/peer_test.go index b0709c927..17f70129b 100644 --- a/whisper/whisperv6/peer_test.go +++ b/whisper/whisperv6/peer_test.go @@ -27,6 +27,7 @@ import ( "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" @@ -85,7 +86,7 @@ type TestNode struct { var result TestData var nodes [NumNodes]*TestNode -var sharedKey = []byte("some arbitrary data here") +var sharedKey = hexutil.MustDecode("0x03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31") var sharedTopic = TopicType{0xF, 0x1, 0x2, 0} var expectedMessage = []byte("per rectum ad astra") var masterBloomFilter []byte @@ -122,11 +123,6 @@ func TestSimulation(t *testing.T) { // check if each node (except node #0) have received and decrypted exactly one message checkPropagation(t, false) - for i := 1; i < NumNodes; i++ { - time.Sleep(20 * time.Millisecond) - sendMsg(t, true, i) - } - // check if corresponding protocol-level messages were correctly decoded checkPowExchangeForNodeZero(t) checkBloomFilterExchange(t) @@ -389,20 +385,37 @@ func TestPeerBasic(t *testing.T) { } func checkPowExchangeForNodeZero(t *testing.T) { + const iterations = 200 + for j := 0; j < iterations; j++ { + lastCycle := (j == iterations-1) + ok := checkPowExchangeForNodeZeroOnce(t, lastCycle) + if ok { + break + } + time.Sleep(50 * time.Millisecond) + } +} + +func checkPowExchangeForNodeZeroOnce(t *testing.T, mustPass bool) bool { cnt := 0 for i, node := range nodes { for peer := range node.shh.peers { if peer.peer.ID() == discover.PubkeyID(&nodes[0].id.PublicKey) { cnt++ if peer.powRequirement != masterPow { - t.Fatalf("node %d: failed to set the new pow requirement.", i) + if mustPass { + t.Fatalf("node %d: failed to set the new pow requirement for node zero.", i) + } else { + return false + } } } } } if cnt == 0 { - t.Fatalf("no matching peers found.") + t.Fatalf("looking for node zero: no matching peers found.") } + return true } func checkPowExchange(t *testing.T) { @@ -418,13 +431,31 @@ func checkPowExchange(t *testing.T) { } } -func checkBloomFilterExchange(t *testing.T) { +func checkBloomFilterExchangeOnce(t *testing.T, mustPass bool) bool { for i, node := range nodes { for peer := range node.shh.peers { if !bytes.Equal(peer.bloomFilter, masterBloomFilter) { - t.Fatalf("node %d: failed to exchange bloom filter requirement in round %d. \n%x expected \n%x got", - i, round, masterBloomFilter, peer.bloomFilter) + if mustPass { + t.Fatalf("node %d: failed to exchange bloom filter requirement in round %d. \n%x expected \n%x got", + i, round, masterBloomFilter, peer.bloomFilter) + } else { + return false + } } } } + + return true +} + +func checkBloomFilterExchange(t *testing.T) { + const iterations = 200 + for j := 0; j < iterations; j++ { + lastCycle := (j == iterations-1) + ok := checkBloomFilterExchangeOnce(t, lastCycle) + if ok { + break + } + time.Sleep(50 * time.Millisecond) + } } |