Make connection setup in shh_connect test more deterministic

This commit is contained in:
kdeme 2019-06-21 14:01:14 +02:00 committed by zah
parent d1eb1070fc
commit 47c7a9887e
1 changed files with 12 additions and 17 deletions

View File

@ -9,30 +9,25 @@
import import
sequtils, options, unittest, tables, chronos, eth/[keys, p2p], sequtils, options, unittest, tables, chronos, eth/[keys, p2p],
eth/p2p/rlpx_protocols/[whisper_protocol], eth/p2p/rlpx_protocols/whisper_protocol, eth/p2p/peer_pool,
./p2p_test_helper ./p2p_test_helper
proc resetMessageQueues(nodes: varargs[EthereumNode]) = proc resetMessageQueues(nodes: varargs[EthereumNode]) =
for node in nodes: for node in nodes:
node.resetMessageQueue() node.resetMessageQueue()
let bootENode = waitFor setupBootNode()
let safeTTL = 5'u32 let safeTTL = 5'u32
let waitInterval = messageInterval + 150.milliseconds let waitInterval = messageInterval + 150.milliseconds
var node1 = setupTestNode(Whisper)
var node2 = setupTestNode(Whisper)
# node2 listening and node1 not, to avoid many incoming vs outgoing
var node1Connected = node1.connectToNetwork(@[bootENode], false, true)
var node2Connected = node2.connectToNetwork(@[bootENode], true, true)
waitFor node1Connected
waitFor node2Connected
suite "Whisper connections": suite "Whisper connections":
var node1 = setupTestNode(Whisper)
var node2 = setupTestNode(Whisper)
node2.startListening()
waitFor node1.peerPool.connectToNode(newNode(initENode(node2.keys.pubKey,
node2.address)))
asyncTest "Two peers connected": asyncTest "Two peers connected":
check: check:
node1.peerPool.connectedNodes.len() == 1 node1.peerPool.connectedNodes.len() == 1
node2.peerPool.connectedNodes.len() == 1
asyncTest "Filters with encryption and signing": asyncTest "Filters with encryption and signing":
let encryptKeyPair = newKeyPair() let encryptKeyPair = newKeyPair()
@ -313,12 +308,12 @@ suite "Whisper connections":
node1.unsubscribeFilter(filter) == true node1.unsubscribeFilter(filter) == true
test "Light node posting": asyncTest "Light node posting":
var ln1 = setupTestNode(Whisper) var ln1 = setupTestNode(Whisper)
ln1.setLightNode(true) ln1.setLightNode(true)
# not listening, so will only connect to others that are listening (node2) await ln1.peerPool.connectToNode(newNode(initENode(node2.keys.pubKey,
waitFor ln1.connectToNetwork(@[bootENode], false, true) node2.address)))
let topic = [byte 0, 0, 0, 0] let topic = [byte 0, 0, 0, 0]
@ -333,7 +328,7 @@ suite "Whisper connections":
targetPeer = some(toNodeId(node2.keys.pubkey))) == true targetPeer = some(toNodeId(node2.keys.pubkey))) == true
ln1.protocolState(Whisper).queue.items.len == 0 ln1.protocolState(Whisper).queue.items.len == 0
test "Connect two light nodes": asyncTest "Connect two light nodes":
var ln1 = setupTestNode(Whisper) var ln1 = setupTestNode(Whisper)
var ln2 = setupTestNode(Whisper) var ln2 = setupTestNode(Whisper)
@ -341,6 +336,6 @@ suite "Whisper connections":
ln2.setLightNode(true) ln2.setLightNode(true)
ln2.startListening() ln2.startListening()
let peer = waitFor ln1.rlpxConnect(newNode(initENode(ln2.keys.pubKey, let peer = await ln1.rlpxConnect(newNode(initENode(ln2.keys.pubKey,
ln2.address))) ln2.address)))
check peer.isNil == true check peer.isNil == true