Add helper functions

This commit is contained in:
mhchia
2019-09-02 21:01:13 +08:00
parent a883816881
commit 3717dc9adf
5 changed files with 60 additions and 26 deletions

View File

@ -1,7 +1,11 @@
from typing import NamedTuple
FLOODSUB_PROTOCOL_ID = "/floodsub/1.0.0"
GOSSIPSUB_PROTOCOL_ID = "/gossipsub/1.0.0"
from libp2p.pubsub import floodsub
from libp2p.pubsub import gossipsub
FLOODSUB_PROTOCOL_ID = floodsub.PROTOCOL_ID
GOSSIPSUB_PROTOCOL_ID = gossipsub.PROTOCOL_ID
class GossipsubParams(NamedTuple):

View File

@ -70,8 +70,7 @@ async def test_peers_subscribe(pubsubs_fsub):
@pytest.mark.asyncio
async def test_get_hello_packet(pubsubs_fsub):
def _get_hello_packet_topic_ids():
packet = rpc_pb2.RPC()
packet.ParseFromString(pubsubs_fsub[0].get_hello_packet())
packet = pubsubs_fsub[0].get_hello_packet()
return tuple(sub.topicid for sub in packet.subscriptions)
# Test: No subscription, so there should not be any topic ids in the hello packet.