add test for listen event

This commit is contained in:
zixuanzh
2019-03-17 21:15:14 -04:00
committed by Stuckinaboot
parent 2cb0279b57
commit 2e437e5b8b
2 changed files with 77 additions and 12 deletions

View File

@ -29,3 +29,13 @@ async def echo_stream_handler(stream):
resp = "ack:" + read_string
await stream.write(resp.encode())
async def perform_two_host_set_up_custom_handler(handler):
transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]]
(node_a, node_b) = await set_up_nodes_by_transport_opt(transport_opt_list)
node_b.set_stream_handler("/echo/1.0.0", handler)
# Associate the peer with local ip address (see default parameters of Libp2p())
node_a.get_peerstore().add_addrs(node_b.get_id(), node_b.get_addrs(), 10)
return node_a, node_b