v29.4-roots.1 · Commit 3: [PATCH 03/13] policy: restore conservative relay and network controls
test/functional/p2p_handshake.py
Before: test/functional/p2p_handshake.py · After: test/functional/p2p_handshake.py
File metadata
index 4148790c196b6f785a63f18e92551241bef99fe3..31149fb1ae50a1092ce509d33b055f9310eaf149 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
|
|
@@ -15,9 +16,18 @@ from test_framework.messages import (
|
|
|
15
16
|
NODE_NONE,
|
|
16
17
|
NODE_P2P_V2,
|
|
17
18
|
NODE_WITNESS,
|
|
19
|
+
msg_version,
|
|
20
|
+
)
|
|
21
|
+
from test_framework.p2p import (
|
|
22
|
+
P2PInterface,
|
|
23
|
+
P2P_SERVICES,
|
|
24
|
+
P2P_SUBVERSION,
|
|
25
|
+
P2P_VERSION,
|
|
26
|
+
)
|
|
27
|
+
from test_framework.util import (
|
|
28
|
+
assert_equal,
|
|
29
|
+
p2p_port,
|
|
18
30
|
)
|
|
19
|
-
from test_framework.p2p import P2PInterface
|
|
20
|
-
from test_framework.util import p2p_port
|
|
21
31
|
|
|
22
32
|
|
|
23
33
|
# Desirable service flags for outbound non-pruned and pruned peers. Note that
|
|
@@ -64,6 +74,20 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
|
|
64
74
|
assert (services & desirable_service_flags) == desirable_service_flags
|
|
65
75
|
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
|
|
66
76
|
|
|
77
|
+
def test_startingheight(self, node):
|
|
78
|
+
for fake_startheight in [-2**31, -1, 0, 1000000, 2**31-1] + [random.randint(-2**31, 2**31) for _ in range(5)]:
|
|
79
|
+
peer = node.add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
|
|
80
|
+
version = msg_version()
|
|
81
|
+
version.nVersion = P2P_VERSION
|
|
82
|
+
version.strSubVer = P2P_SUBVERSION
|
|
83
|
+
version.nServices = P2P_SERVICES
|
|
84
|
+
version.nStartingHeight = fake_startheight
|
|
85
|
+
peer.send_message(version)
|
|
86
|
+
peer.wait_for_verack()
|
|
87
|
+
peer_info = node.getpeerinfo()[-1]
|
|
88
|
+
assert_equal(peer_info['startingheight'], fake_startheight)
|
|
89
|
+
peer.peer_disconnect()
|
|
90
|
+
|
|
67
91
|
def generate_at_mocktime(self, time):
|
|
68
92
|
self.nodes[0].setmocktime(time)
|
|
69
93
|
self.generate(self.nodes[0], 1)
|
|
@@ -95,6 +119,9 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
|
|
95
119
|
node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
|
|
96
120
|
self.wait_until(lambda: len(node.getpeerinfo()) == 0)
|
|
97
121
|
|
|
122
|
+
self.log.info("Check that peer's announced starting height is remembered")
|
|
123
|
+
self.test_startingheight(node)
|
|
124
|
+
|
|
98
125
|
|
|
99
126
|
if __name__ == '__main__':
|
|
100
127
|
P2PHandshakeTest(__file__).main()
|