Skip to content

Commit ffe6a56

Browse files
committed
[test] Check whether v2 TestNode performs downgrading
1 parent ba73735 commit ffe6a56

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

test/functional/p2p_v2_encrypted.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ def run_test(self):
6868
assert not peer3.supports_v2_p2p
6969
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1")
7070

71+
# v2 TestNode performs downgrading here
72+
self.log.info("Check outbound connection from v2 TestNode to v1 P2PConnection advertised as v2 is v1")
73+
peer4 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, supports_v2_p2p=False, advertise_v2_p2p=True)
74+
assert not peer4.supports_v2_p2p
75+
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1")
76+
7177
self.log.info("Check outbound connection from v2 TestNode to v2 P2PConnection advertised as v2 is v2")
7278
peer5 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=2, supports_v2_p2p=True, advertise_v2_p2p=True)
7379
assert peer5.supports_v2_p2p
7480
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v2")
7581

7682
self.log.info("Check if version is sent and verack is received in inbound/outbound connections")
77-
assert_equal(len(node0.getpeerinfo()), 4) # check if above 4 connections are present in node0's getpeerinfo()
83+
assert_equal(len(node0.getpeerinfo()), 5) # check if above 5 connections are present in node0's getpeerinfo()
7884
for peer in node0.getpeerinfo():
7985
assert_greater_than(peer['bytessent_per_msg']['version'], 0)
8086
assert_greater_than(peer['bytesrecv_per_msg']['verack'], 0)
@@ -114,7 +120,7 @@ def run_test(self):
114120
self.disconnect_nodes(0, 1)
115121

116122
self.log.info("Check the connections opened as expected")
117-
check_node_connections(node=node0, num_in=4, num_out=2)
123+
check_node_connections(node=node0, num_in=4, num_out=3)
118124

119125
self.log.info("Check inbound connection to v1 TestNode from v2 P2PConnection is v1")
120126
self.restart_node(0, ["-v2transport=0"])

test/functional/test_framework/p2p.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,13 @@ def wait_for_disconnect(self, timeout=60):
590590
test_function = lambda: not self.is_connected
591591
self.wait_until(test_function, timeout=timeout, check_connected=False)
592592

593+
def wait_for_reconnect(self, timeout=60):
594+
def test_function():
595+
if not (self.is_connected and self.last_message.get('version') and self.v2_state is None):
596+
return False
597+
return True
598+
self.wait_until(test_function, timeout=timeout, check_connected=False)
599+
593600
# Message receiving helper methods
594601

595602
def wait_for_tx(self, txid, timeout=60):

test/functional/test_framework/test_node.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ def addconnection_callback(address, port):
736736
supports_v2_p2p = supports_v2_p2p and advertise_v2_p2p
737737
p2p_conn.peer_accept_connection(connect_cb=addconnection_callback, connect_id=p2p_idx + 1, net=self.chain, timeout_factor=self.timeout_factor, supports_v2_p2p=supports_v2_p2p, reconnect=reconnect, **kwargs)()
738738

739+
if reconnect:
740+
p2p_conn.wait_for_reconnect()
741+
739742
if connection_type == "feeler":
740743
# feeler connections are closed as soon as the node receives a `version` message
741744
p2p_conn.wait_until(lambda: p2p_conn.message_count["version"] == 1, check_connected=False)

0 commit comments

Comments
 (0)