Skip to content

Commit

Permalink
Fix test_bootstrap with delayed find_node ethereum#50
Browse files Browse the repository at this point in the history
KademliaProtocol delays `find_node` requests until bonding succeeded. This is
now reflected in the test.
  • Loading branch information
konradkonrad committed Jan 18, 2017
1 parent d90aef3 commit 2edfa6e
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions devp2p/tests/test_kademlia_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2edfa6e

Please sign in to comment.