Skip to content
Bitcoin Roots

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. 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
@@ -16,9 +17,18 @@ from test_framework.messages import (
16
  NODE_NONE,
17
  NODE_P2P_V2,
18
  NODE_WITNESS,
 
 
 
 
 
 
 
 
 
 
 
19
  )
20
- from test_framework.p2p import P2PInterface
21
- from test_framework.util import p2p_port
22
 
23
 
24
  # Desirable service flags for outbound non-pruned and pruned peers. Note that
@@ -65,6 +75,20 @@ class P2PHandshakeTest(BitcoinTestFramework):
65
  assert (services & desirable_service_flags) == desirable_service_flags
66
  self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  def generate_at_mocktime(self, time):
69
  self.nodes[0].setmocktime(time)
70
  self.generate(self.nodes[0], 1)
@@ -96,6 +120,9 @@ class P2PHandshakeTest(BitcoinTestFramework):
96
  node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
97
  self.wait_until(lambda: len(node.getpeerinfo()) == 0)
98
 
 
 
 
99
 
100
  if __name__ == '__main__':
101
  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
 
17
  NODE_NONE,
18
  NODE_P2P_V2,
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,
31
  )
 
 
32
 
33
 
34
  # Desirable service flags for outbound non-pruned and pruned peers. Note that
 
75
  assert (services & desirable_service_flags) == desirable_service_flags
76
  self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
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
+
92
  def generate_at_mocktime(self, time):
93
  self.nodes[0].setmocktime(time)
94
  self.generate(self.nodes[0], 1)
 
120
  node.addconnection(node_listen_addr, "outbound-full-relay", self.options.v2transport)
121
  self.wait_until(lambda: len(node.getpeerinfo()) == 0)
122
 
123
+ self.log.info("Check that peer's announced starting height is remembered")
124
+ self.test_startingheight(node)
125
+
126
 
127
  if __name__ == '__main__':
128
  P2PHandshakeTest(__file__).main()