2019-07-27 11:49:03 +08:00
|
|
|
import functools
|
|
|
|
|
2019-05-07 11:44:13 +08:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from libp2p import new_node
|
|
|
|
from libp2p.pubsub.gossipsub import GossipSub
|
|
|
|
from libp2p.pubsub.pubsub import Pubsub
|
2019-07-26 18:35:25 +08:00
|
|
|
|
2019-05-07 11:44:13 +08:00
|
|
|
from tests.utils import cleanup
|
|
|
|
|
2019-07-27 11:49:03 +08:00
|
|
|
from .configs import (
|
|
|
|
FLOODSUB_PROTOCOL_ID,
|
|
|
|
LISTEN_MADDR,
|
|
|
|
)
|
|
|
|
from .floodsub_integration_test_settings import (
|
|
|
|
perform_test_from_obj,
|
|
|
|
floodsub_protocol_pytest_params,
|
2019-07-26 18:35:25 +08:00
|
|
|
)
|
2019-05-07 11:44:13 +08:00
|
|
|
|
2019-07-26 18:35:25 +08:00
|
|
|
|
|
|
|
# pylint: disable=too-many-locals
|
2019-05-07 11:44:13 +08:00
|
|
|
@pytest.mark.asyncio
|
2019-07-27 11:49:03 +08:00
|
|
|
async def test_gossipsub_initialize_with_floodsub_protocol():
|
|
|
|
node = await new_node(transport_opt=[str(LISTEN_MADDR)])
|
2019-05-07 11:44:13 +08:00
|
|
|
|
2019-07-27 11:49:03 +08:00
|
|
|
await node.get_network().listen(LISTEN_MADDR)
|
2019-05-07 11:44:13 +08:00
|
|
|
|
2019-07-27 11:49:03 +08:00
|
|
|
gossipsub = GossipSub([FLOODSUB_PROTOCOL_ID], 3, 2, 4, 30)
|
2019-05-07 11:44:13 +08:00
|
|
|
pubsub = Pubsub(node, gossipsub, "a")
|
|
|
|
|
|
|
|
# Did it work?
|
|
|
|
assert gossipsub and pubsub
|
|
|
|
|
|
|
|
await cleanup()
|
|
|
|
|
2019-07-26 18:35:25 +08:00
|
|
|
|
2019-07-27 11:49:03 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"test_case_obj",
|
|
|
|
floodsub_protocol_pytest_params,
|
|
|
|
)
|
2019-05-07 11:44:13 +08:00
|
|
|
@pytest.mark.asyncio
|
2019-07-27 11:49:03 +08:00
|
|
|
async def test_gossipsub_run_with_floodsub_tests(test_case_obj):
|
|
|
|
await perform_test_from_obj(
|
|
|
|
test_case_obj,
|
|
|
|
functools.partial(
|
|
|
|
GossipSub,
|
|
|
|
degree=3,
|
|
|
|
degree_low=2,
|
|
|
|
degree_high=4,
|
|
|
|
time_to_live=30,
|
|
|
|
)
|
|
|
|
)
|