mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-09 22:50:54 +00:00
reorg test structure to match tox and CI jobs, drop bumpversion for bump-my-version and move config to pyproject.toml, fix docs building
This commit is contained in:
32
tests/core/security/noise/test_msg_read_writer.py
Normal file
32
tests/core/security/noise/test_msg_read_writer.py
Normal file
@ -0,0 +1,32 @@
|
||||
import pytest
|
||||
|
||||
from libp2p.security.noise.io import (
|
||||
MAX_NOISE_MESSAGE_LEN,
|
||||
NoisePacketReadWriter,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
raw_conn_factory,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"noise_msg",
|
||||
(b"", b"data", pytest.param(b"A" * MAX_NOISE_MESSAGE_LEN, id="maximum length")),
|
||||
)
|
||||
@pytest.mark.trio
|
||||
async def test_noise_msg_read_write_round_trip(nursery, noise_msg):
|
||||
async with raw_conn_factory(nursery) as conns:
|
||||
reader, writer = (
|
||||
NoisePacketReadWriter(conns[0]),
|
||||
NoisePacketReadWriter(conns[1]),
|
||||
)
|
||||
await writer.write_msg(noise_msg)
|
||||
assert (await reader.read_msg()) == noise_msg
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_noise_msg_write_too_long(nursery):
|
||||
async with raw_conn_factory(nursery) as conns:
|
||||
writer = NoisePacketReadWriter(conns[0])
|
||||
with pytest.raises(ValueError):
|
||||
await writer.write_msg(b"1" * (MAX_NOISE_MESSAGE_LEN + 1))
|
||||
38
tests/core/security/noise/test_noise.py
Normal file
38
tests/core/security/noise/test_noise.py
Normal file
@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
|
||||
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
|
||||
DATA_2 = b"data_2"
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_noise_transport(nursery):
|
||||
async with noise_conn_factory(nursery):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_noise_connection(nursery):
|
||||
async with noise_conn_factory(nursery) as conns:
|
||||
local_conn, remote_conn = conns
|
||||
await local_conn.write(DATA_0)
|
||||
await local_conn.write(DATA_1)
|
||||
assert DATA_0 == (await remote_conn.read(len(DATA_0)))
|
||||
assert DATA_1 == (await remote_conn.read(len(DATA_1)))
|
||||
await local_conn.write(DATA_2)
|
||||
assert DATA_2 == (await remote_conn.read(len(DATA_2)))
|
||||
|
||||
|
||||
def test_noise_handshake_payload():
|
||||
payload = noise_handshake_payload_factory()
|
||||
payload_serialized = payload.serialize()
|
||||
payload_deserialized = NoiseHandshakePayload.deserialize(payload_serialized)
|
||||
assert payload == payload_deserialized
|
||||
Reference in New Issue
Block a user