From 2edfa6e47219c1d6494cbd1e3abbb0a42a77db1e Mon Sep 17 00:00:00 2001 From: Konrad Feldmeier Date: Mon, 16 Jan 2017 16:08:35 +0100 Subject: [PATCH] Fix `test_bootstrap` with delayed `find_node` #50 KademliaProtocol delays `find_node` requests until bonding succeeded. This is now reflected in the test. --- devp2p/tests/test_kademlia_protocol.py | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/devp2p/tests/test_kademlia_protocol.py b/devp2p/tests/test_kademlia_protocol.py index 5bb6eb8..b2fd6ca 100644 --- a/devp2p/tests/test_kademlia_protocol.py +++ b/devp2p/tests/test_kademlia_protocol.py @@ -136,22 +136,33 @@ def test_bootstrap(protos): msg = wire.process_single(other.this_node, protos) assert msg[:2] == ('ping', proto.routing.this_node) # bonding should be followed up by find_node - # FIXME: find_node must be delayed until bonding succeeded! + # find_node must be delayed until bonding succeeded! + msg = wire.process_single(other.this_node, protos) - assert msg == ('find_node', proto.routing.this_node, proto.routing.this_node.id) - assert wire.process_single(other.this_node, protos) is None + assert msg is None + + # let bonding proceed + messages = list(wire.process(protos, steps=3)) + # ping, pong, ping(consumed), pong + assert [m[0] for m in messages] == ['ping', 'pong', 'pong'] + assert proto.routing.get_node(other.this_node).bonded - # bonding is not completed - from_routing = proto.routing.get_node(other.this_node) - assert not from_routing.bonded + assert wire.process_single(other.this_node, protos) == ('find_node', proto.routing.this_node, proto.routing.this_node.id) + assert len(wire.messages) + # nothing left to be done from other + assert wire.process_single(other.this_node, protos) is None - # After the remote follows protocol bonding will succeed - wire.process(protos) + messages = list(wire.process(protos)) assert wire.messages == [] - # After bootstrap the node should be in routing and bonded + + assert len(messages) + assert messages[0] == ('neighbours', other.this_node, [proto.this_node]) + # After bootstrap each node should be in others routing and bonded assert other.this_node in proto.routing - from_routing = proto.routing.get_node(other.this_node) - assert from_routing.bonded + assert proto.routing.get_node(other.this_node).bonded + + assert proto.this_node in other.routing + assert other.routing.get_node(proto.this_node).bonded def test_setup(proto):