mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 07:30:55 +00:00
Add connect utility function
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user