Add connect utility function

This commit is contained in:
mhchia
2019-09-02 18:40:12 +08:00
parent 56ef0b962c
commit a883816881
3 changed files with 52 additions and 10 deletions

View File

@ -1,8 +1,7 @@
import asyncio
from multiaddr import Multiaddr
import pytest
from .utils import connect
@pytest.mark.parametrize("num_hosts", (1,))
@pytest.mark.asyncio
@ -11,19 +10,15 @@ async def test_connect(hosts, p2pds):
host = hosts[0]
assert len(await p2pd.control.list_peers()) == 0
# Test: connect from Py
await host.connect(p2pd.peer_info)
await connect(host, p2pd)
assert len(await p2pd.control.list_peers()) == 1
# Test: `disconnect` from Py
await host.disconnect(p2pd.peer_id)
assert len(await p2pd.control.list_peers()) == 0
# Test: connect from Go
py_peer_id = host.get_id()
await p2pd.control.connect(
host.get_id(),
[host.get_addrs()[0].decapsulate(Multiaddr(f"/p2p/{py_peer_id.to_string()}"))],
)
await connect(p2pd, host)
assert len(host.get_network().connections) == 1
# Test: `disconnect` from Go
await p2pd.control.disconnect(py_peer_id)
await p2pd.control.disconnect(host.get_id())
# FIXME: Failed to handle disconnect
# assert len(host.get_network().connections) == 0