Skip to content

Commit 2dbfa24

Browse files
committed
refactor
1 parent baed5ed commit 2dbfa24

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/functional/p2p_v2_encrypted.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
from test_framework.crypto.chacha20 import REKEY_INTERVAL
2323

2424

25+
def check_v2_connection_info(node, peer):
26+
peerinfo = node.getpeerinfo()[-1]
27+
protocol_type = peerinfo["transport_protocol_type"]
28+
if peer.supports_v2_p2p:
29+
assert_equal(protocol_type, "v2")
30+
assert_equal(peer.v2_state.peer['session_id'].hex(), peerinfo["session_id"])
31+
else:
32+
assert_equal(protocol_type, "v1")
33+
34+
2535
class P2PEncrypted(BitcoinTestFramework):
2636
def set_test_params(self):
2737
self.num_nodes = 2
@@ -56,28 +66,29 @@ def run_test(self):
5666
self.log.info("Check inbound connection to v2 TestNode from v2 P2PConnection is v2")
5767
peer1 = node0.add_p2p_connection(P2PInterface(), wait_for_verack=True, supports_v2_p2p=True)
5868
assert peer1.supports_v2_p2p
59-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v2")
69+
check_v2_connection_info(node0, peer1)
6070

6171
self.log.info("Check inbound connection to v2 TestNode from v1 P2PConnection is v1")
6272
peer2 = node0.add_p2p_connection(P2PInterface(), wait_for_verack=True, supports_v2_p2p=False)
6373
assert not peer2.supports_v2_p2p
64-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1")
74+
check_v2_connection_info(node0, peer2)
6575

6676
self.log.info("Check outbound connection from v2 TestNode to v1 P2PConnection advertised as v1 is v1")
6777
peer3 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, supports_v2_p2p=False, advertise_v2_p2p=False)
6878
assert not peer3.supports_v2_p2p
69-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1")
79+
check_v2_connection_info(node0, peer3)
7080

7181
# v2 TestNode performs downgrading here
7282
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)
83+
with node0.assert_debug_log(['retrying with v1 transport protocol for peer'], timeout=5):
84+
peer4 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, supports_v2_p2p=False, advertise_v2_p2p=True)
7485
assert not peer4.supports_v2_p2p
75-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1")
86+
check_v2_connection_info(node0, peer4)
7687

7788
self.log.info("Check outbound connection from v2 TestNode to v2 P2PConnection advertised as v2 is v2")
7889
peer5 = node0.add_outbound_p2p_connection(P2PInterface(), p2p_idx=2, supports_v2_p2p=True, advertise_v2_p2p=True)
7990
assert peer5.supports_v2_p2p
80-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v2")
91+
check_v2_connection_info(node0, peer5)
8192

8293
self.log.info("Check if version is sent and verack is received in inbound/outbound connections")
8394
assert_equal(len(node0.getpeerinfo()), 5) # check if above 5 connections are present in node0's getpeerinfo()
@@ -92,7 +103,7 @@ def run_test(self):
92103
for i in range(2):
93104
peer6 = node0.add_p2p_connection(P2PDataStore(), supports_v2_p2p=True)
94105
assert peer6.supports_v2_p2p
95-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v2")
106+
check_v2_connection_info(node0, peer6)
96107

97108
# Consider: node0 <-- peer6. node0 and node1 aren't connected here.
98109
# Construct the following topology: node1 <--> node0 <-- peer6
@@ -126,7 +137,7 @@ def run_test(self):
126137
self.restart_node(0, ["-v2transport=0"])
127138
peer1 = node0.add_p2p_connection(P2PInterface(), wait_for_verack=True, supports_v2_p2p=True)
128139
assert not peer1.supports_v2_p2p
129-
assert_equal(node0.getpeerinfo()[-1]["transport_protocol_type"], "v1")
140+
check_v2_connection_info(node0, peer1)
130141
check_node_connections(node=node0, num_in=1, num_out=0)
131142

132143

0 commit comments

Comments
 (0)