diff --git a/test/functional/p2p_v2_encrypted.py b/test/functional/p2p_v2_encrypted.py index 0444cffed7..05755dece0 100755 --- a/test/functional/p2p_v2_encrypted.py +++ b/test/functional/p2p_v2_encrypted.py @@ -68,13 +68,19 @@ class P2PEncrypted(BitcoinTestFramework): assert not peer3.supports_v2_p2p assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1") + # v2 TestNode performs downgrading here + self.log.info("Check outbound connection from v2 TestNode to v1 P2PConnection advertised as v2 is v1") + peer4 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, supports_v2_p2p=False, advertise_v2_p2p=True) + assert not peer4.supports_v2_p2p + assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1") + self.log.info("Check outbound connection from v2 TestNode to v2 P2PConnection advertised as v2 is v2") peer5 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=2, supports_v2_p2p=True, advertise_v2_p2p=True) assert peer5.supports_v2_p2p assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v2") self.log.info("Check if version is sent and verack is received in inbound/outbound connections") - assert_equal(len(node0.getpeerinfo()), 4) # check if above 4 connections are present in node0's getpeerinfo() + assert_equal(len(node0.getpeerinfo()), 5) # check if above 5 connections are present in node0's getpeerinfo() for peer in node0.getpeerinfo(): assert_greater_than(peer['bytessent_per_msg']['version'], 0) assert_greater_than(peer['bytesrecv_per_msg']['verack'], 0) @@ -114,7 +120,7 @@ class P2PEncrypted(BitcoinTestFramework): self.disconnect_nodes(0, 1) self.log.info("Check the connections opened as expected") - check_node_connections(node=node0, num_in=4, num_out=2) + check_node_connections(node=node0, num_in=4, num_out=3) self.log.info("Check inbound connection to v1 TestNode from v2 P2PConnection is v1") self.restart_node(0, ["-v2transport=0"]) diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 1194c7c88d..c41abec42d 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -590,6 +590,13 @@ class P2PInterface(P2PConnection): test_function = lambda: not self.is_connected self.wait_until(test_function, timeout=timeout, check_connected=False) + def wait_for_reconnect(self, timeout=60): + def test_function(): + if not (self.is_connected and self.last_message.get('version') and self.v2_state is None): + return False + return True + self.wait_until(test_function, timeout=timeout, check_connected=False) + # Message receiving helper methods def wait_for_tx(self, txid, timeout=60): diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 8662391b93..29796865c2 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -736,6 +736,9 @@ class TestNode(): supports_v2_p2p = supports_v2_p2p and advertise_v2_p2p 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)() + if reconnect: + p2p_conn.wait_for_reconnect() + if connection_type == "feeler": # feeler connections are closed as soon as the node receives a `version` message p2p_conn.wait_until(lambda: p2p_conn.message_count["version"] == 1, check_connected=False)