Skip to content

Commit

Permalink
Fix test_ping_pong in test_discovery #50
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkonrad committed Jan 18, 2017
1 parent e635bea commit ad430a9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions devp2p/tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,20 @@ def test_ping_pong():
alice = NodeDiscoveryMock(host='127.0.0.1', port=1, seed='alice')
bob = NodeDiscoveryMock(host='127.0.0.2', port=2, seed='bob')

cmd_id_map = alice.protocol.cmd_id_map
bob_node = alice.protocol.get_node(bob.protocol.pubkey, bob.address)
alice.protocol.kademlia.ping(bob_node)
assert len(NodeDiscoveryMock.messages) == 1
# inspect message in queue
msg = NodeDiscoveryMock.messages[0][2]
remote_pubkey, cmd_id, payload, mdc = bob.protocol.unpack(msg)
assert cmd_id == alice.protocol.cmd_id_map['ping']
bob.poll() # receives ping, sends pong
assert len(NodeDiscoveryMock.messages) == 1
alice.poll() # receives pong
# process the ping pong handshake
assert bob.poll() == cmd_id_map['ping'] # receives ping, sends pong
assert len(NodeDiscoveryMock.messages) == 2
assert alice.poll() == cmd_id_map['ping'] # receives ping, sends pong
assert bob.poll() == cmd_id_map['pong'] # receives pong
assert alice.poll() == cmd_id_map['pong'] # receives pong
assert len(NodeDiscoveryMock.messages) == 0


Expand Down

0 comments on commit ad430a9

Please sign in to comment.