2020-02-07 17:47:50 +08:00
|
|
|
import pytest
|
|
|
|
|
2020-02-16 00:42:49 +08:00
|
|
|
from libp2p.security.noise.messages import NoiseHandshakePayload
|
|
|
|
from libp2p.tools.factories import noise_conn_factory, noise_handshake_payload_factory
|
2020-02-07 17:47:50 +08:00
|
|
|
|
2020-02-07 18:17:15 +08:00
|
|
|
DATA = b"testing_123"
|
|
|
|
|
|
|
|
|
2020-02-07 17:47:50 +08:00
|
|
|
@pytest.mark.trio
|
|
|
|
async def test_noise_transport(nursery):
|
|
|
|
async with noise_conn_factory(nursery):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.trio
|
2020-02-07 18:17:15 +08:00
|
|
|
async def test_noise_connection(nursery):
|
|
|
|
async with noise_conn_factory(nursery) as conns:
|
2020-02-07 17:47:50 +08:00
|
|
|
local_conn, remote_conn = conns
|
2020-02-07 18:17:15 +08:00
|
|
|
await local_conn.write(DATA)
|
|
|
|
read_data = await remote_conn.read(len(DATA))
|
|
|
|
assert read_data == DATA
|
2020-02-16 00:42:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_noise_handshake_payload():
|
|
|
|
payload = noise_handshake_payload_factory()
|
|
|
|
payload_serialized = payload.serialize()
|
|
|
|
payload_deserialized = NoiseHandshakePayload.deserialize(payload_serialized)
|
|
|
|
assert payload == payload_deserialized
|