mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 05:45:05 +01:00
[test] Check whether v2 TestNode performs downgrading
This commit is contained in:
parent
ba737358a3
commit
ffe6a56d75
@ -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"])
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user