v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3
test/functional/p2p_handshake.py
Before: test/functional/p2p_handshake.py · After: test/functional/p2p_handshake.py
File metadata
index f509ece4f22437009885f3c15b5edd9883c47821..a47809cba3e425650bf654e4b64a0f523e31d243 100755
Download original patch · Release notes
Diff rows 1–56 of 56. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
test/functional/p2p_handshake.py
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
Test P2P behaviour during the handshake phase (VERSION, VERACK messages).
|
|
7
7
|
"""
|
|
8
8
|
import itertools
|
|
9
|
+
import random
|
|
9
10
|
import time
|
|
10
11
|
|
|
11
12
|
from test_framework.test_framework import BitcoinTestFramework
|
|
@@ -16,9 +17,18 @@ from test_framework.messages import (
|
|
|
16
17
|
NODE_NONE,
|
|
17
18
|
NODE_P2P_V2,
|
|
18
19
|
NODE_WITNESS,
|
|
20
|
+
msg_version,
|
|
21
|
+
)
|
|
22
|
+
from test_framework.p2p import (
|
|
23
|
+
P2PInterface,
|
|
24
|
+
P2P_SERVICES,
|
|
25
|
+
P2P_SUBVERSION,
|
|
26
|
+
P2P_VERSION,
|
|
27
|
+
)
|
|
28
|
+
from test_framework.util import (
|
|
29
|
+
assert_equal,
|
|
30
|
+
p2p_port,
|
|
19
31
|
)
|
|
20
|
-
from test_framework.p2p import P2PInterface
|
|
21
|
-
from test_framework.util import p2p_port
|
|
22
32
|
|
|
23
33
|
|
|
24
34
|
# Desirable service flags for outbound non-pruned and pruned peers. Note that
|
|
@@ -65,6 +75,20 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
|
|
65
75
|
assert (services & desirable_service_flags) == desirable_service_flags
|
|
66
76
|
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
|
|
67
77
|
|
|
78
|
+
def test_startingheight(self, node):
|
|
79
|
+
for fake_startheight in [-2**31, -1, 0, 1000000, 2**31-1] + [random.randint(-2**31, 2**31) for _ in range(5)]:
|
|
80
|
+
peer = node.add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
|
|
81
|
+
version = msg_version()
|
|
82
|
+
version.nVersion = P2P_VERSION
|
|
83
|
+
version.strSubVer = P2P_SUBVERSION
|
|
84
|
+
version.nServices = P2P_SERVICES
|
|
85
|
+
version.nStartingHeight = fake_startheight
|
|
86
|
+
peer.send_message(version)
|
|
87
|
+
peer.wait_for_verack()
|
|
88
|
+
peer_info = node.getpeerinfo()[-1]
|
|
89
|
+
assert_equal(peer_info['startingheight'], fake_startheight)
|
|
90
|
+
peer.peer_disconnect()
|
|
91
|
+
|
|
68
92
|
def generate_at_mocktime(self, time):
|
|
69
93
|
self.nodes[0].setmocktime(time)
|
|
70
94
|
self.generate(self.nodes[0], 1)
|
|
@@ -96,6 +120,9 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
|
|
96
120
|
node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
|
|
97
121
|
self.wait_until(lambda: len(node.getpeerinfo()) == 0)
|
|
98
122
|
|
|
123
|
+
self.log.info("Check that peer's announced starting height is remembered")
|
|
124
|
+
self.test_startingheight(node)
|
|
125
|
+
|
|
99
126
|
|
|
100
127
|
if __name__ == '__main__':
|
|
101
128
|
P2PHandshakeTest(__file__).main()
|