Noise: add noise option in the factories and tests

This commit is contained in:
mhchia
2020-02-19 23:15:03 +08:00
parent 1d2a976597
commit 13e8f496a7
21 changed files with 331 additions and 212 deletions

View File

@ -8,18 +8,22 @@ from libp2p.tools.factories import (
@pytest.fixture
async def net_stream_pair(is_host_secure):
async with net_stream_pair_factory(is_host_secure) as net_stream_pair:
async def net_stream_pair(security_protocol):
async with net_stream_pair_factory(
security_protocol=security_protocol
) as net_stream_pair:
yield net_stream_pair
@pytest.fixture
async def swarm_pair(is_host_secure):
async with swarm_pair_factory(is_host_secure) as swarms:
async def swarm_pair(security_protocol):
async with swarm_pair_factory(security_protocol=security_protocol) as swarms:
yield swarms
@pytest.fixture
async def swarm_conn_pair(is_host_secure):
async with swarm_conn_pair_factory(is_host_secure) as swarm_conn_pair:
async def swarm_conn_pair(security_protocol):
async with swarm_conn_pair_factory(
security_protocol=security_protocol
) as swarm_conn_pair:
yield swarm_conn_pair

View File

@ -55,8 +55,8 @@ class MyNotifee(INotifee):
@pytest.mark.trio
async def test_notify(is_host_secure):
swarms = [SwarmFactory(is_secure=is_host_secure) for _ in range(2)]
async def test_notify(security_protocol):
swarms = [SwarmFactory(security_protocol=security_protocol) for _ in range(2)]
events_0_0 = []
events_1_0 = []

View File

@ -9,8 +9,10 @@ from libp2p.tools.utils import connect_swarm
@pytest.mark.trio
async def test_swarm_dial_peer(is_host_secure):
async with SwarmFactory.create_batch_and_listen(is_host_secure, 3) as swarms:
async def test_swarm_dial_peer(security_protocol):
async with SwarmFactory.create_batch_and_listen(
3, security_protocol=security_protocol
) as swarms:
# Test: No addr found.
with pytest.raises(SwarmException):
await swarms[0].dial_peer(swarms[1].get_peer_id())
@ -38,8 +40,10 @@ async def test_swarm_dial_peer(is_host_secure):
@pytest.mark.trio
async def test_swarm_close_peer(is_host_secure):
async with SwarmFactory.create_batch_and_listen(is_host_secure, 3) as swarms:
async def test_swarm_close_peer(security_protocol):
async with SwarmFactory.create_batch_and_listen(
3, security_protocol=security_protocol
) as swarms:
# 0 <> 1 <> 2
await connect_swarm(swarms[0], swarms[1])
await connect_swarm(swarms[1], swarms[2])
@ -90,8 +94,10 @@ async def test_swarm_remove_conn(swarm_pair):
@pytest.mark.trio
async def test_swarm_multiaddr(is_host_secure):
async with SwarmFactory.create_batch_and_listen(is_host_secure, 3) as swarms:
async def test_swarm_multiaddr(security_protocol):
async with SwarmFactory.create_batch_and_listen(
3, security_protocol=security_protocol
) as swarms:
def clear():
swarms[0].peerstore.clear_addrs(swarms[1].get_peer_id())