waku-interop-tests/tests/peer_exchange/test_peer_exchange.py
Roman Zajic 6aa7716793
Test/peer exchange (#51)
* test: establish basic node setup for pe

* test: debug peer retrieval error with nwaku

* fix: disable discovery v5 on the requester node

* fix: assert node3 peer store to exact content

* test: get peers for filter node

* test: get peers after node1 was restarted

* fix: allow tests to run only when Node2 is Go-waku

* fix: revert NODE_1 to its original default
2024-07-09 14:07:48 +02:00

69 lines
2.8 KiB
Python

import pytest
from src.env_vars import NODE_2
from src.libs.common import delay
from src.node.waku_node import peer_info2multiaddr, multiaddr2id
from src.steps.peer_exchange import StepsPeerExchange
@pytest.mark.skipif("go-waku" not in NODE_2, reason="Test works only with go-waku as responder - https://github.com/waku-org/nwaku/issues/2875")
class TestPeerExchange(StepsPeerExchange):
def test_get_peers_for_blank_node(self):
self.setup_first_relay_node(relay_peer_exchange="true")
self.setup_second_relay_node(peer_exchange="true")
delay(1)
node1_peers = self.node1.get_peers()
assert len(node1_peers) == 1
self.responder_multiaddr = peer_info2multiaddr(node1_peers[0], self.node1.is_nwaku())
self.setup_third_node_as_peer_exchange_requester(discv5_discovery="false")
others = {self.node1.get_id(), self.node2.get_id()}
own = set()
for peer_info in self.node3.get_peers():
peer_id = multiaddr2id(peer_info2multiaddr(peer_info, self.node3.is_nwaku()))
own.add(peer_id)
assert own == others, f"Not all nodes found as expected in peer store of Node3"
def test_get_peers_for_filter_node(self):
self.setup_first_relay_node(filter="true", relay_peer_exchange="true")
self.setup_second_relay_node(filter="true", peer_exchange="true")
delay(1)
node1_peers = self.node1.get_peers()
assert len(node1_peers) == 1
self.responder_multiaddr = peer_info2multiaddr(node1_peers[0], self.node1.is_nwaku())
self.setup_third_node_as_peer_exchange_requester(discv5_discovery="false")
suitable_peers = []
for peer_info in self.node3.get_peers():
multiaddr = peer_info2multiaddr(peer_info, self.node3.is_nwaku())
suitable_peers.append(multiaddr)
assert len(suitable_peers) == 2
self.setup_fourth_node_as_filter(filternode=suitable_peers[0])
def test_get_peers_after_node1_was_restarted(self):
self.setup_first_relay_node(relay_peer_exchange="true")
self.setup_second_relay_node(peer_exchange="true")
delay(1)
node1_peers = self.node1.get_peers()
assert len(node1_peers) == 1
self.responder_multiaddr = peer_info2multiaddr(node1_peers[0], self.node1.is_nwaku())
self.node1.restart()
# Give Node2 time to update its peer store
delay(1)
# Start Node3
self.setup_third_node_as_peer_exchange_requester(discv5_discovery="false")
others = {self.node1.get_id(), self.node2.get_id()}
own = set()
for peer_info in self.node3.get_peers():
peer_id = multiaddr2id(peer_info2multiaddr(peer_info, self.node3.is_nwaku()))
own.add(peer_id)
assert own == others, f"Two nodes are expected in peer store of Node3"