mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
run lint and fix errors, except mypy
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.tools.factories import HostFactory
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
def test_import_and_version():
|
||||
import libp2p
|
||||
|
||||
|
||||
assert isinstance(libp2p.__version__, str)
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
from libp2p.crypto.ed25519 import create_new_key_pair
|
||||
from libp2p.crypto.serialization import deserialize_private_key, deserialize_public_key
|
||||
from libp2p.crypto.ed25519 import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.crypto.serialization import (
|
||||
deserialize_private_key,
|
||||
deserialize_public_key,
|
||||
)
|
||||
|
||||
|
||||
def test_public_key_serialize_deserialize_round_trip():
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
from libp2p.crypto.secp256k1 import create_new_key_pair
|
||||
from libp2p.crypto.serialization import deserialize_private_key, deserialize_public_key
|
||||
from libp2p.crypto.secp256k1 import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.crypto.serialization import (
|
||||
deserialize_private_key,
|
||||
deserialize_public_key,
|
||||
)
|
||||
|
||||
|
||||
def test_public_key_serialize_deserialize_round_trip():
|
||||
|
||||
@ -1,10 +1,18 @@
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.host.exceptions import StreamFailure
|
||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
||||
from libp2p.tools.factories import HostFactory
|
||||
from libp2p.tools.utils import MAX_READ_LEN
|
||||
from libp2p.host.exceptions import (
|
||||
StreamFailure,
|
||||
)
|
||||
from libp2p.peer.peerinfo import (
|
||||
info_from_p2p_addr,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
|
||||
PROTOCOL_ID = "/chat/1.0.0"
|
||||
|
||||
|
||||
@ -1,7 +1,15 @@
|
||||
from libp2p import new_swarm
|
||||
from libp2p.crypto.rsa import create_new_key_pair
|
||||
from libp2p.host.basic_host import BasicHost
|
||||
from libp2p.host.defaults import get_default_protocols
|
||||
from libp2p import (
|
||||
new_swarm,
|
||||
)
|
||||
from libp2p.crypto.rsa import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.host.basic_host import (
|
||||
BasicHost,
|
||||
)
|
||||
from libp2p.host.defaults import (
|
||||
get_default_protocols,
|
||||
)
|
||||
|
||||
|
||||
def test_default_protocols():
|
||||
@ -11,6 +19,6 @@ def test_default_protocols():
|
||||
|
||||
mux = host.get_mux()
|
||||
handlers = mux.handlers
|
||||
# NOTE: comparing keys for equality as handlers may be closures that do not compare in the way
|
||||
# this test is concerned with
|
||||
# NOTE: comparing keys for equality as handlers may be closures that do not compare
|
||||
# in the way this test is concerned with
|
||||
assert handlers.keys() == get_default_protocols(host).keys()
|
||||
|
||||
@ -3,8 +3,13 @@ import secrets
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.host.ping import ID, PING_LENGTH
|
||||
from libp2p.tools.factories import host_pair_factory
|
||||
from libp2p.host.ping import (
|
||||
ID,
|
||||
PING_LENGTH,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
host_pair_factory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.host.exceptions import ConnectionFailure
|
||||
from libp2p.peer.peerinfo import PeerInfo
|
||||
from libp2p.tools.factories import HostFactory, RoutedHostFactory
|
||||
from libp2p.host.exceptions import (
|
||||
ConnectionFailure,
|
||||
)
|
||||
from libp2p.peer.peerinfo import (
|
||||
PeerInfo,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
RoutedHostFactory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.identity.identify.pb.identify_pb2 import Identify
|
||||
from libp2p.identity.identify.protocol import ID, _mk_identify_protobuf
|
||||
from libp2p.tools.factories import host_pair_factory
|
||||
from libp2p.identity.identify.pb.identify_pb2 import (
|
||||
Identify,
|
||||
)
|
||||
from libp2p.identity.identify.protocol import (
|
||||
ID,
|
||||
_mk_identify_protobuf,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
host_pair_factory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,11 +1,22 @@
|
||||
import multiaddr
|
||||
import pytest
|
||||
|
||||
from libp2p.network.stream.exceptions import StreamError
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.tools.factories import HostFactory
|
||||
from libp2p.tools.utils import connect, create_echo_stream_handler
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.network.stream.exceptions import (
|
||||
StreamError,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
connect,
|
||||
create_echo_stream_handler,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
PROTOCOL_ID_0 = TProtocol("/echo/0")
|
||||
PROTOCOL_ID_1 = TProtocol("/echo/1")
|
||||
@ -84,7 +95,8 @@ async def test_double_response(security_protocol):
|
||||
@pytest.mark.trio
|
||||
async def test_multiple_streams(security_protocol):
|
||||
# hosts[0] should be able to open a stream with hosts[1] and then vice versa.
|
||||
# Stream IDs should be generated uniquely so that the stream state is not overwritten
|
||||
# Stream IDs should be generated uniquely so that the stream state is not
|
||||
# overwritten
|
||||
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
2, security_protocol=security_protocol
|
||||
@ -125,7 +137,6 @@ async def test_multiple_streams_same_initiator_different_protocols(security_prot
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
2, security_protocol=security_protocol
|
||||
) as hosts:
|
||||
|
||||
hosts[1].set_stream_handler(
|
||||
PROTOCOL_ID_0, create_echo_stream_handler(ACK_STR_0)
|
||||
)
|
||||
@ -231,7 +242,6 @@ async def test_triangle_nodes_connection(security_protocol):
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
3, security_protocol=security_protocol
|
||||
) as hosts:
|
||||
|
||||
hosts[0].set_stream_handler(
|
||||
PROTOCOL_ID_0, create_echo_stream_handler(ACK_STR_0)
|
||||
)
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.network.stream.exceptions import StreamClosed, StreamEOF, StreamReset
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.network.stream.exceptions import (
|
||||
StreamClosed,
|
||||
StreamEOF,
|
||||
StreamReset,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
|
||||
DATA = b"data_123"
|
||||
|
||||
|
||||
@ -10,14 +10,24 @@ features are implemented in swarm
|
||||
"""
|
||||
import enum
|
||||
|
||||
from async_service import background_trio_service
|
||||
from async_service import (
|
||||
background_trio_service,
|
||||
)
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.network.notifee_interface import INotifee
|
||||
from libp2p.tools.constants import LISTEN_MADDR
|
||||
from libp2p.tools.factories import SwarmFactory
|
||||
from libp2p.tools.utils import connect_swarm
|
||||
from libp2p.network.notifee_interface import (
|
||||
INotifee,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
LISTEN_MADDR,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
SwarmFactory,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
connect_swarm,
|
||||
)
|
||||
|
||||
|
||||
class Event(enum.Enum):
|
||||
@ -63,8 +73,8 @@ async def test_notify(security_protocol):
|
||||
events_0_without_listen = []
|
||||
# Run swarms.
|
||||
async with background_trio_service(swarms[0]), background_trio_service(swarms[1]):
|
||||
# Register events before listening, to allow `MyNotifee` is notified with the event
|
||||
# `listen`.
|
||||
# Register events before listening, to allow `MyNotifee` is notified with the
|
||||
# event `listen`.
|
||||
swarms[0].register_notifee(MyNotifee(events_0_0))
|
||||
swarms[1].register_notifee(MyNotifee(events_1_0))
|
||||
|
||||
|
||||
@ -1,11 +1,21 @@
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
import pytest
|
||||
import trio
|
||||
from trio.testing import wait_all_tasks_blocked
|
||||
from trio.testing import (
|
||||
wait_all_tasks_blocked,
|
||||
)
|
||||
|
||||
from libp2p.network.exceptions import SwarmException
|
||||
from libp2p.tools.factories import SwarmFactory
|
||||
from libp2p.tools.utils import connect_swarm
|
||||
from libp2p.network.exceptions import (
|
||||
SwarmException,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
SwarmFactory,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
connect_swarm,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
import trio
|
||||
from trio.testing import wait_all_tasks_blocked
|
||||
from trio.testing import (
|
||||
wait_all_tasks_blocked,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.peer.peerstore import PeerStore, PeerStoreError
|
||||
from libp2p.peer.peerstore import (
|
||||
PeerStore,
|
||||
PeerStoreError,
|
||||
)
|
||||
|
||||
# Testing methods from IAddrBook base class.
|
||||
|
||||
@ -51,8 +54,8 @@ def test_peers_with_addrs():
|
||||
store.add_addrs("peer2", ["/foo"], 10)
|
||||
store.add_addrs("peer3", ["/bar"], 10)
|
||||
|
||||
assert set(store.peers_with_addrs()) == set(["peer2", "peer3"])
|
||||
assert set(store.peers_with_addrs()) == {"peer2", "peer3"}
|
||||
|
||||
store.clear_addrs("peer2")
|
||||
|
||||
assert set(store.peers_with_addrs()) == set(["peer3"])
|
||||
assert set(store.peers_with_addrs()) == {"peer3"}
|
||||
|
||||
@ -3,8 +3,12 @@ import base64
|
||||
import Crypto.PublicKey.RSA as RSA
|
||||
|
||||
from libp2p.crypto.pb import crypto_pb2 as pb
|
||||
from libp2p.crypto.rsa import RSAPrivateKey
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.crypto.rsa import (
|
||||
RSAPrivateKey,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
|
||||
# ``PRIVATE_KEY_PROTOBUF_SERIALIZATION`` is a protobuf holding an RSA private key.
|
||||
PRIVATE_KEY_PROTOBUF_SERIALIZATION = """
|
||||
|
||||
@ -3,9 +3,13 @@ import random
|
||||
import base58
|
||||
import multihash
|
||||
|
||||
from libp2p.crypto.rsa import create_new_key_pair
|
||||
from libp2p.crypto.rsa import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
import libp2p.peer.id as PeerID
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
|
||||
ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
|
||||
|
||||
@ -3,8 +3,14 @@ import random
|
||||
import multiaddr
|
||||
import pytest
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.peer.peerinfo import InvalidAddrError, PeerInfo, info_from_p2p_addr
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.peer.peerinfo import (
|
||||
InvalidAddrError,
|
||||
PeerInfo,
|
||||
info_from_p2p_addr,
|
||||
)
|
||||
|
||||
ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||
VALID_MULTI_ADDR_STR = "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" # noqa: E501
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.peer.peerstore import PeerStore, PeerStoreError
|
||||
from libp2p.peer.peerstore import (
|
||||
PeerStore,
|
||||
PeerStoreError,
|
||||
)
|
||||
|
||||
# Testing methods from IPeerMetadata base class.
|
||||
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.peer.peerstore import PeerStore, PeerStoreError
|
||||
from libp2p.peer.peerstore import (
|
||||
PeerStore,
|
||||
PeerStoreError,
|
||||
)
|
||||
|
||||
# Testing methods from IPeerStore base class.
|
||||
|
||||
@ -25,8 +28,8 @@ def test_add_get_protocols_basic():
|
||||
store.add_protocols("peer1", ["p1", "p2"])
|
||||
store.add_protocols("peer2", ["p3"])
|
||||
|
||||
assert set(store.get_protocols("peer1")) == set(["p1", "p2"])
|
||||
assert set(store.get_protocols("peer2")) == set(["p3"])
|
||||
assert set(store.get_protocols("peer1")) == {"p1", "p2"}
|
||||
assert set(store.get_protocols("peer2")) == {"p3"}
|
||||
|
||||
|
||||
def test_add_get_protocols_extend():
|
||||
@ -34,7 +37,7 @@ def test_add_get_protocols_extend():
|
||||
store.add_protocols("peer1", ["p1", "p2"])
|
||||
store.add_protocols("peer1", ["p3"])
|
||||
|
||||
assert set(store.get_protocols("peer1")) == set(["p1", "p2", "p3"])
|
||||
assert set(store.get_protocols("peer1")) == {"p1", "p2", "p3"}
|
||||
|
||||
|
||||
def test_set_protocols():
|
||||
@ -45,8 +48,8 @@ def test_set_protocols():
|
||||
store.set_protocols("peer1", ["p4"])
|
||||
store.set_protocols("peer2", [])
|
||||
|
||||
assert set(store.get_protocols("peer1")) == set(["p4"])
|
||||
assert set(store.get_protocols("peer2")) == set([])
|
||||
assert set(store.get_protocols("peer1")) == {"p4"}
|
||||
assert set(store.get_protocols("peer2")) == set()
|
||||
|
||||
|
||||
# Test with methods from other Peer interfaces.
|
||||
@ -56,4 +59,4 @@ def test_peers():
|
||||
store.put("peer2", "key", "val")
|
||||
store.add_addr("peer3", "/foo", 10)
|
||||
|
||||
assert set(store.peer_ids()) == set(["peer1", "peer2", "peer3"])
|
||||
assert set(store.peer_ids()) == {"peer1", "peer2", "peer3"}
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.host.exceptions import StreamFailure
|
||||
from libp2p.tools.factories import HostFactory
|
||||
from libp2p.tools.utils import create_echo_stream_handler
|
||||
from libp2p.host.exceptions import (
|
||||
StreamFailure,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
create_echo_stream_handler,
|
||||
)
|
||||
|
||||
PROTOCOL_ECHO = "/echo/1.0.0"
|
||||
PROTOCOL_POTATO = "/potato/1.0.0"
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.tools.pubsub.dummy_account_node import DummyAccountNode
|
||||
from libp2p.tools.utils import connect
|
||||
from libp2p.tools.pubsub.dummy_account_node import (
|
||||
DummyAccountNode,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
connect,
|
||||
)
|
||||
|
||||
|
||||
async def perform_test(num_nodes, adjacency_map, action_func, assertion_func):
|
||||
|
||||
@ -3,13 +3,19 @@ import functools
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.tools.factories import PubsubFactory
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
PubsubFactory,
|
||||
)
|
||||
from libp2p.tools.pubsub.floodsub_integration_test_settings import (
|
||||
floodsub_protocol_pytest_params,
|
||||
perform_test_from_obj,
|
||||
)
|
||||
from libp2p.tools.utils import connect
|
||||
from libp2p.tools.utils import (
|
||||
connect,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -3,10 +3,20 @@ import random
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.pubsub.gossipsub import PROTOCOL_ID
|
||||
from libp2p.tools.factories import IDFactory, PubsubFactory
|
||||
from libp2p.tools.pubsub.utils import dense_connect, one_to_all_connect
|
||||
from libp2p.tools.utils import connect
|
||||
from libp2p.pubsub.gossipsub import (
|
||||
PROTOCOL_ID,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
IDFactory,
|
||||
PubsubFactory,
|
||||
)
|
||||
from libp2p.tools.pubsub.utils import (
|
||||
dense_connect,
|
||||
one_to_all_connect,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
connect,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
@ -353,11 +363,11 @@ async def test_mesh_heartbeat(initial_mesh_peer_count, monkeypatch):
|
||||
1, heartbeat_initial_delay=100
|
||||
) as pubsubs_gsub:
|
||||
# It's difficult to set up the initial peer subscription condition.
|
||||
# Ideally I would like to have initial mesh peer count that's below ``GossipSubDegree``
|
||||
# so I can test if `mesh_heartbeat` return correct peers to GRAFT.
|
||||
# The problem is that I can not set it up so that we have peers subscribe to the topic
|
||||
# but not being part of our mesh peers (as these peers are the peers to GRAFT).
|
||||
# So I monkeypatch the peer subscriptions and our mesh peers.
|
||||
# Ideally I would like to have initial mesh peer count that's below
|
||||
# ``GossipSubDegree`` so I can test if `mesh_heartbeat` return correct peers to
|
||||
# GRAFT. The problem is that I can not set it up so that we have peers subscribe
|
||||
# to the topic but not being part of our mesh peers (as these peers are the
|
||||
# peers to GRAFT). So I monkeypatch the peer subscriptions and our mesh peers.
|
||||
total_peer_count = 14
|
||||
topic = "TEST_MESH_HEARTBEAT"
|
||||
|
||||
@ -408,9 +418,9 @@ async def test_gossip_heartbeat(initial_peer_count, monkeypatch):
|
||||
async with PubsubFactory.create_batch_with_gossipsub(
|
||||
1, heartbeat_initial_delay=100
|
||||
) as pubsubs_gsub:
|
||||
# The problem is that I can not set it up so that we have peers subscribe to the topic
|
||||
# but not being part of our mesh peers (as these peers are the peers to GRAFT).
|
||||
# So I monkeypatch the peer subscriptions and our mesh peers.
|
||||
# The problem is that I can not set it up so that we have peers subscribe to the
|
||||
# topic but not being part of our mesh peers (as these peers are the peers to
|
||||
# GRAFT). So I monkeypatch the peer subscriptions and our mesh peers.
|
||||
total_peer_count = 28
|
||||
topic_mesh = "TEST_GOSSIP_HEARTBEAT_1"
|
||||
topic_fanout = "TEST_GOSSIP_HEARTBEAT_2"
|
||||
@ -455,8 +465,8 @@ async def test_gossip_heartbeat(initial_peer_count, monkeypatch):
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router.mcache, "window", window)
|
||||
|
||||
peers_to_gossip = pubsubs_gsub[0].router.gossip_heartbeat()
|
||||
# If our mesh peer count is less than `GossipSubDegree`, we should gossip to up to
|
||||
# `GossipSubDegree` peers (exclude mesh peers).
|
||||
# If our mesh peer count is less than `GossipSubDegree`, we should gossip to up
|
||||
# to `GossipSubDegree` peers (exclude mesh peers).
|
||||
if topic_mesh_peer_count - initial_peer_count < pubsubs_gsub[0].router.degree:
|
||||
# The same goes for fanout so it's two times the number of peers to gossip.
|
||||
assert len(peers_to_gossip) == 2 * (
|
||||
|
||||
@ -2,8 +2,12 @@ import functools
|
||||
|
||||
import pytest
|
||||
|
||||
from libp2p.tools.constants import FLOODSUB_PROTOCOL_ID
|
||||
from libp2p.tools.factories import PubsubFactory
|
||||
from libp2p.tools.constants import (
|
||||
FLOODSUB_PROTOCOL_ID,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
PubsubFactory,
|
||||
)
|
||||
from libp2p.tools.pubsub.floodsub_integration_test_settings import (
|
||||
floodsub_protocol_pytest_params,
|
||||
perform_test_from_obj,
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
from libp2p.pubsub.mcache import MessageCache
|
||||
from libp2p.pubsub.mcache import (
|
||||
MessageCache,
|
||||
)
|
||||
|
||||
|
||||
class Msg:
|
||||
|
||||
@ -1,17 +1,40 @@
|
||||
from contextlib import contextmanager
|
||||
from typing import NamedTuple
|
||||
from contextlib import (
|
||||
contextmanager,
|
||||
)
|
||||
from typing import (
|
||||
NamedTuple,
|
||||
)
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.exceptions import ValidationError
|
||||
from libp2p.pubsub.pb import rpc_pb2
|
||||
from libp2p.pubsub.pubsub import PUBSUB_SIGNING_PREFIX, SUBSCRIPTION_CHANNEL_SIZE
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.tools.factories import IDFactory, PubsubFactory, net_stream_pair_factory
|
||||
from libp2p.tools.pubsub.utils import make_pubsub_msg
|
||||
from libp2p.tools.utils import connect
|
||||
from libp2p.utils import encode_varint_prefixed
|
||||
from libp2p.exceptions import (
|
||||
ValidationError,
|
||||
)
|
||||
from libp2p.pubsub.pb import (
|
||||
rpc_pb2,
|
||||
)
|
||||
from libp2p.pubsub.pubsub import (
|
||||
PUBSUB_SIGNING_PREFIX,
|
||||
SUBSCRIPTION_CHANNEL_SIZE,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
IDFactory,
|
||||
PubsubFactory,
|
||||
net_stream_pair_factory,
|
||||
)
|
||||
from libp2p.tools.pubsub.utils import (
|
||||
make_pubsub_msg,
|
||||
)
|
||||
from libp2p.tools.utils import (
|
||||
connect,
|
||||
)
|
||||
from libp2p.utils import (
|
||||
encode_varint_prefixed,
|
||||
)
|
||||
|
||||
TESTING_TOPIC = "TEST_SUBSCRIBE"
|
||||
TESTING_DATA = b"data"
|
||||
@ -77,7 +100,8 @@ async def test_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.
|
||||
# Test: No subscription, so there should not be any topic ids in the
|
||||
# hello packet.
|
||||
assert len(_get_hello_packet_topic_ids()) == 0
|
||||
|
||||
# Test: After subscriptions, topic ids should be in the hello packet.
|
||||
@ -469,7 +493,8 @@ async def test_subscribe_and_publish_full_channel():
|
||||
for data in list_data:
|
||||
await pubsub.publish(TESTING_TOPIC, data)
|
||||
|
||||
# Publish `extra_data_0` which should be dropped since the channel is already full.
|
||||
# Publish `extra_data_0` which should be dropped since the channel is
|
||||
# already full.
|
||||
await pubsub.publish(TESTING_TOPIC, extra_data_0)
|
||||
# Consume a message and there is an empty slot in the channel.
|
||||
assert (await subscription.get()).data == expected_list_data.pop(0)
|
||||
@ -520,7 +545,6 @@ async def test_push_msg(monkeypatch):
|
||||
|
||||
@contextmanager
|
||||
def mock_router_publish():
|
||||
|
||||
event = trio.Event()
|
||||
|
||||
async def router_publish(*args, **kwargs):
|
||||
|
||||
@ -3,8 +3,12 @@ import math
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.pubsub.pb import rpc_pb2
|
||||
from libp2p.pubsub.subscription import TrioSubscriptionAPI
|
||||
from libp2p.pubsub.pb import (
|
||||
rpc_pb2,
|
||||
)
|
||||
from libp2p.pubsub.subscription import (
|
||||
TrioSubscriptionAPI,
|
||||
)
|
||||
|
||||
GET_TIMEOUT = 0.001
|
||||
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.security.noise.io import MAX_NOISE_MESSAGE_LEN, NoisePacketReadWriter
|
||||
from libp2p.tools.factories import raw_conn_factory
|
||||
from libp2p.security.noise.io import (
|
||||
MAX_NOISE_MESSAGE_LEN,
|
||||
NoisePacketReadWriter,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
raw_conn_factory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.security.noise.messages import NoiseHandshakePayload
|
||||
from libp2p.tools.factories import noise_conn_factory, noise_handshake_payload_factory
|
||||
from libp2p.security.noise.messages import (
|
||||
NoiseHandshakePayload,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
noise_conn_factory,
|
||||
noise_handshake_payload_factory,
|
||||
)
|
||||
|
||||
DATA_0 = b"data_0"
|
||||
DATA_1 = b"1" * 1000
|
||||
|
||||
@ -1,11 +1,22 @@
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.crypto.secp256k1 import create_new_key_pair
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secio.transport import NONCE_SIZE, create_secure_session
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.tools.factories import raw_conn_factory
|
||||
from libp2p.crypto.secp256k1 import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.security.secio.transport import (
|
||||
NONCE_SIZE,
|
||||
create_secure_session,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
raw_conn_factory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,11 +1,20 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.crypto.rsa import create_new_key_pair
|
||||
from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID, InsecureSession
|
||||
from libp2p.crypto.rsa import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.security.insecure.transport import (
|
||||
PLAINTEXT_PROTOCOL_ID,
|
||||
InsecureSession,
|
||||
)
|
||||
from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID
|
||||
from libp2p.security.secio.transport import ID as SECIO_PROTOCOL_ID
|
||||
from libp2p.security.secure_session import SecureSession
|
||||
from libp2p.tools.factories import host_pair_factory
|
||||
from libp2p.security.secure_session import (
|
||||
SecureSession,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
host_pair_factory,
|
||||
)
|
||||
|
||||
initiator_key_pair = create_new_key_pair()
|
||||
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.tools.factories import mplex_conn_pair_factory, mplex_stream_pair_factory
|
||||
from libp2p.tools.factories import (
|
||||
mplex_conn_pair_factory,
|
||||
mplex_stream_pair_factory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@ -1,14 +1,20 @@
|
||||
import pytest
|
||||
import trio
|
||||
from trio.testing import wait_all_tasks_blocked
|
||||
from trio.testing import (
|
||||
wait_all_tasks_blocked,
|
||||
)
|
||||
|
||||
from libp2p.stream_muxer.mplex.exceptions import (
|
||||
MplexStreamClosed,
|
||||
MplexStreamEOF,
|
||||
MplexStreamReset,
|
||||
)
|
||||
from libp2p.stream_muxer.mplex.mplex import MPLEX_MESSAGE_CHANNEL_SIZE
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.stream_muxer.mplex.mplex import (
|
||||
MPLEX_MESSAGE_CHANNEL_SIZE,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
|
||||
DATA = b"data_123"
|
||||
|
||||
|
||||
@ -1,11 +1,21 @@
|
||||
from multiaddr import Multiaddr
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.network.connection.raw_connection import RawConnection
|
||||
from libp2p.tools.constants import LISTEN_MADDR
|
||||
from libp2p.transport.exceptions import OpenConnectionError
|
||||
from libp2p.transport.tcp.tcp import TCP
|
||||
from libp2p.network.connection.raw_connection import (
|
||||
RawConnection,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
LISTEN_MADDR,
|
||||
)
|
||||
from libp2p.transport.exceptions import (
|
||||
OpenConnectionError,
|
||||
)
|
||||
from libp2p.transport.tcp.tcp import (
|
||||
TCP,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
Reference in New Issue
Block a user