2019-10-15 07:01:16 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from libp2p.host.exceptions import ConnectionFailure
|
|
|
|
from libp2p.peer.peerinfo import PeerInfo
|
2019-12-24 02:19:43 +08:00
|
|
|
from libp2p.tools.factories import HostFactory, RoutedHostFactory
|
2019-10-15 07:01:16 +08:00
|
|
|
|
|
|
|
|
2019-12-24 02:19:43 +08:00
|
|
|
@pytest.mark.trio
|
2019-10-15 07:01:16 +08:00
|
|
|
async def test_host_routing_success():
|
2019-12-24 02:19:43 +08:00
|
|
|
async with RoutedHostFactory.create_batch_and_listen(False, 2) as hosts:
|
|
|
|
# forces to use routing as no addrs are provided
|
|
|
|
await hosts[0].connect(PeerInfo(hosts[1].get_id(), []))
|
|
|
|
await hosts[1].connect(PeerInfo(hosts[0].get_id(), []))
|
2019-10-15 07:01:16 +08:00
|
|
|
|
|
|
|
|
2019-12-24 02:19:43 +08:00
|
|
|
@pytest.mark.trio
|
2019-10-15 07:01:16 +08:00
|
|
|
async def test_host_routing_fail():
|
2019-12-24 02:19:43 +08:00
|
|
|
is_secure = False
|
|
|
|
async with RoutedHostFactory.create_batch_and_listen(
|
|
|
|
is_secure, 2
|
|
|
|
) as routed_hosts, HostFactory.create_batch_and_listen(is_secure, 1) as basic_hosts:
|
|
|
|
# routing fails because host_c does not use routing
|
|
|
|
with pytest.raises(ConnectionFailure):
|
|
|
|
await routed_hosts[0].connect(PeerInfo(basic_hosts[0].get_id(), []))
|
|
|
|
with pytest.raises(ConnectionFailure):
|
|
|
|
await routed_hosts[1].connect(PeerInfo(basic_hosts[0].get_id(), []))
|