update test for identify and ping using new test fixture via PR feedback
This commit is contained in:
parent
30dee28ef2
commit
29873584dc
|
@ -4,19 +4,12 @@ import secrets
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from libp2p.host.ping import ID, PING_LENGTH
|
from libp2p.host.ping import ID, PING_LENGTH
|
||||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
from tests.factories import pair_of_connected_hosts
|
||||||
from tests.utils import set_up_nodes_by_transport_opt
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_ping_once():
|
async def test_ping_once():
|
||||||
transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]]
|
async with pair_of_connected_hosts() as (host_a, host_b):
|
||||||
(host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list)
|
|
||||||
|
|
||||||
addr = host_a.get_addrs()[0]
|
|
||||||
info = info_from_p2p_addr(addr)
|
|
||||||
await host_b.connect(info)
|
|
||||||
|
|
||||||
stream = await host_b.new_stream(host_a.get_id(), (ID,))
|
stream = await host_b.new_stream(host_a.get_id(), (ID,))
|
||||||
some_ping = secrets.token_bytes(PING_LENGTH)
|
some_ping = secrets.token_bytes(PING_LENGTH)
|
||||||
await stream.write(some_ping)
|
await stream.write(some_ping)
|
||||||
|
@ -30,13 +23,7 @@ SOME_PING_COUNT = 3
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_ping_several():
|
async def test_ping_several():
|
||||||
transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]]
|
async with pair_of_connected_hosts() as (host_a, host_b):
|
||||||
(host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list)
|
|
||||||
|
|
||||||
addr = host_a.get_addrs()[0]
|
|
||||||
info = info_from_p2p_addr(addr)
|
|
||||||
await host_b.connect(info)
|
|
||||||
|
|
||||||
stream = await host_b.new_stream(host_a.get_id(), (ID,))
|
stream = await host_b.new_stream(host_a.get_id(), (ID,))
|
||||||
for _ in range(SOME_PING_COUNT):
|
for _ in range(SOME_PING_COUNT):
|
||||||
some_ping = secrets.token_bytes(PING_LENGTH)
|
some_ping = secrets.token_bytes(PING_LENGTH)
|
||||||
|
|
|
@ -2,19 +2,12 @@ import pytest
|
||||||
|
|
||||||
from libp2p.identity.identify.pb.identify_pb2 import Identify
|
from libp2p.identity.identify.pb.identify_pb2 import Identify
|
||||||
from libp2p.identity.identify.protocol import ID, _mk_identify_protobuf
|
from libp2p.identity.identify.protocol import ID, _mk_identify_protobuf
|
||||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
from tests.factories import pair_of_connected_hosts
|
||||||
from tests.utils import set_up_nodes_by_transport_opt
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_identify_protocol():
|
async def test_identify_protocol():
|
||||||
transport_opt_list = [["/ip4/127.0.0.1/tcp/0"], ["/ip4/127.0.0.1/tcp/0"]]
|
async with pair_of_connected_hosts() as (host_a, host_b):
|
||||||
(host_a, host_b) = await set_up_nodes_by_transport_opt(transport_opt_list)
|
|
||||||
|
|
||||||
addr = host_a.get_addrs()[0]
|
|
||||||
info = info_from_p2p_addr(addr)
|
|
||||||
await host_b.connect(info)
|
|
||||||
|
|
||||||
stream = await host_b.new_stream(host_a.get_id(), (ID,))
|
stream = await host_b.new_stream(host_a.get_id(), (ID,))
|
||||||
response = await stream.read()
|
response = await stream.read()
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user