mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-10 23:20:55 +00:00
Tested against subscriptions and publish
This commit is contained in:
@ -2,18 +2,31 @@ import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
|
||||
from .utils import connect
|
||||
|
||||
|
||||
TOPIC = "TOPIC_0123"
|
||||
DATA = b"DATA_0123"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("num_hosts", (1,))
|
||||
@pytest.mark.asyncio
|
||||
async def test_pubsub_peers(pubsubs_gsub, p2pds):
|
||||
async def test_pubsub_subscribe(pubsubs_gsub, p2pds):
|
||||
# await connect(pubsubs_gsub[0].host, p2pds[0])
|
||||
await connect(p2pds[0], pubsubs_gsub[0].host)
|
||||
peers = await p2pds[0].control.pubsub_list_peers("")
|
||||
assert pubsubs_gsub[0].host.get_id() in peers
|
||||
# FIXME:
|
||||
assert p2pds[0].peer_id in pubsubs_gsub[0].peers
|
||||
|
||||
sub = await pubsubs_gsub[0].subscribe(TOPIC)
|
||||
await asyncio.sleep(1)
|
||||
peers = await p2pds[0].control.pubsub_list_peers(TOPIC)
|
||||
print(f"!@# peers={peers}")
|
||||
peers_topic = await p2pds[0].control.pubsub_list_peers(TOPIC)
|
||||
await asyncio.sleep(0.1)
|
||||
assert pubsubs_gsub[0].host.get_id() in peers_topic
|
||||
|
||||
await p2pds[0].control.pubsub_publish(TOPIC, DATA)
|
||||
msg = await sub.get()
|
||||
assert ID(msg.from_id) == p2pds[0].peer_id
|
||||
assert msg.data == DATA
|
||||
assert len(msg.topicIDs) == 1 and msg.topicIDs[0] == TOPIC
|
||||
|
||||
@ -4,8 +4,8 @@ from typing import Union
|
||||
from multiaddr import Multiaddr
|
||||
|
||||
from libp2p.host.host_interface import IHost
|
||||
from libp2p.peer.peerinfo import PeerInfo
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.peer.peerinfo import PeerInfo
|
||||
|
||||
from .daemon import Daemon
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
from typing import NamedTuple
|
||||
|
||||
from libp2p.pubsub import floodsub
|
||||
from libp2p.pubsub import gossipsub
|
||||
|
||||
from libp2p.pubsub import floodsub, gossipsub
|
||||
|
||||
FLOODSUB_PROTOCOL_ID = floodsub.PROTOCOL_ID
|
||||
GOSSIPSUB_PROTOCOL_ID = gossipsub.PROTOCOL_ID
|
||||
|
||||
Reference in New Issue
Block a user