v29.4-roots.2 · Commit 3: [PATCH 03/21] 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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/p2p_handshake.py
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
Test P2P behaviour during the handshake phase (VERSION, VERACK messages).
|
| 7 |
"""
|
| 8 |
import itertools
|
|
|
|
| 9 |
import time
|
| 10 |
|
| 11 |
from test_framework.test_framework import BitcoinTestFramework
|
|
@@ -15,9 +16,18 @@ from test_framework.messages import (
|
|
| 15 |
NODE_NONE,
|
| 16 |
NODE_P2P_V2,
|
| 17 |
NODE_WITNESS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
-
from test_framework.p2p import P2PInterface
|
| 20 |
-
from test_framework.util import p2p_port
|
| 21 |
|
| 22 |
|
| 23 |
# Desirable service flags for outbound non-pruned and pruned peers. Note that
|
|
@@ -64,6 +74,20 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
|
| 64 |
assert (services & desirable_service_flags) == desirable_service_flags
|
| 65 |
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
def generate_at_mocktime(self, time):
|
| 68 |
self.nodes[0].setmocktime(time)
|
| 69 |
self.generate(self.nodes[0], 1)
|
|
@@ -95,6 +119,9 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
|
| 95 |
node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
|
| 96 |
self.wait_until(lambda: len(node.getpeerinfo()) == 0)
|
| 97 |
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
if __name__ == '__main__':
|
| 100 |
P2PHandshakeTest(__file__).main()
|
|
|
|
| 6 |
Test P2P behaviour during the handshake phase (VERSION, VERACK messages).
|
| 7 |
"""
|
| 8 |
import itertools
|
| 9 |
+
import random
|
| 10 |
import time
|
| 11 |
|
| 12 |
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
| 16 |
NODE_NONE,
|
| 17 |
NODE_P2P_V2,
|
| 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,
|
| 30 |
)
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
# Desirable service flags for outbound non-pruned and pruned peers. Note that
|
|
|
|
| 74 |
assert (services & desirable_service_flags) == desirable_service_flags
|
| 75 |
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
|
| 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 |
+
|
| 91 |
def generate_at_mocktime(self, time):
|
| 92 |
self.nodes[0].setmocktime(time)
|
| 93 |
self.generate(self.nodes[0], 1)
|
|
|
|
| 119 |
node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
|
| 120 |
self.wait_until(lambda: len(node.getpeerinfo()) == 0)
|
| 121 |
|
| 122 |
+
self.log.info("Check that peer's announced starting height is remembered")
|
| 123 |
+
self.test_startingheight(node)
|
| 124 |
+
|
| 125 |
|
| 126 |
if __name__ == '__main__':
|
| 127 |
P2PHandshakeTest(__file__).main()
|