2019-09-03 16:49:00 +08:00
|
|
|
import pytest
|
|
|
|
|
2019-11-21 11:47:54 +08:00
|
|
|
from libp2p.tools.constants import GOSSIPSUB_PARAMS
|
|
|
|
from libp2p.tools.factories import FloodsubFactory, GossipsubFactory, PubsubFactory
|
2019-09-03 16:49:00 +08:00
|
|
|
|
|
|
|
|
2019-11-26 16:12:50 +08:00
|
|
|
@pytest.fixture
|
|
|
|
def is_strict_signing():
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def _make_pubsubs(hosts, pubsub_routers, cache_size, is_strict_signing):
|
2019-09-03 16:49:00 +08:00
|
|
|
if len(pubsub_routers) != len(hosts):
|
|
|
|
raise ValueError(
|
|
|
|
f"lenght of pubsub_routers={pubsub_routers} should be equaled to the "
|
|
|
|
f"length of hosts={len(hosts)}"
|
|
|
|
)
|
|
|
|
return tuple(
|
2019-11-26 16:12:50 +08:00
|
|
|
PubsubFactory(
|
|
|
|
host=host,
|
|
|
|
router=router,
|
|
|
|
cache_size=cache_size,
|
|
|
|
strict_signing=is_strict_signing,
|
|
|
|
)
|
2019-09-03 16:49:00 +08:00
|
|
|
for host, router in zip(hosts, pubsub_routers)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def pubsub_cache_size():
|
|
|
|
return None # default
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def gossipsub_params():
|
|
|
|
return GOSSIPSUB_PARAMS
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2019-11-26 16:12:50 +08:00
|
|
|
def pubsubs_fsub(num_hosts, hosts, pubsub_cache_size, is_strict_signing):
|
2019-09-03 16:49:00 +08:00
|
|
|
floodsubs = FloodsubFactory.create_batch(num_hosts)
|
2019-11-26 16:12:50 +08:00
|
|
|
_pubsubs_fsub = _make_pubsubs(
|
|
|
|
hosts, floodsubs, pubsub_cache_size, is_strict_signing
|
|
|
|
)
|
2019-09-03 16:49:00 +08:00
|
|
|
yield _pubsubs_fsub
|
|
|
|
# TODO: Clean up
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2019-11-26 16:12:50 +08:00
|
|
|
def pubsubs_gsub(
|
|
|
|
num_hosts, hosts, pubsub_cache_size, gossipsub_params, is_strict_signing
|
|
|
|
):
|
2019-09-03 16:49:00 +08:00
|
|
|
gossipsubs = GossipsubFactory.create_batch(num_hosts, **gossipsub_params._asdict())
|
2019-11-26 16:12:50 +08:00
|
|
|
_pubsubs_gsub = _make_pubsubs(
|
|
|
|
hosts, gossipsubs, pubsub_cache_size, is_strict_signing
|
|
|
|
)
|
2019-09-03 16:49:00 +08:00
|
|
|
yield _pubsubs_gsub
|
|
|
|
# TODO: Clean up
|