Skip to content

Commit 9ce4c3c

Browse files
committed
[test] Add P2P_SERVICES to p2p.py
The messages.py module should contain code and helpers for [de]serializing p2p messages. Specific usage of those messages should be in p2p.py. Therefore specify the nServices value in the calling code, not in the messages.py module.
1 parent 0105426 commit 9ce4c3c

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

test/functional/p2p_filter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222
from test_framework.p2p import (
2323
P2PInterface,
24+
P2P_SERVICES,
2425
P2P_SUBVERSION,
2526
P2P_VERSION,
2627
p2p_lock,
@@ -225,6 +226,7 @@ def run_test(self):
225226
version_without_fRelay = msg_version()
226227
version_without_fRelay.nVersion = P2P_VERSION
227228
version_without_fRelay.strSubVer = P2P_SUBVERSION
229+
version_without_fRelay.nServices = P2P_SERVICES
228230
version_without_fRelay.relay = 0
229231
filter_peer_without_nrelay.send_message(version_without_fRelay)
230232
filter_peer_without_nrelay.wait_for_verack()

test/functional/p2p_leak.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from test_framework.p2p import (
2121
P2PInterface,
2222
P2P_SUBVERSION,
23+
P2P_SERVICES,
2324
P2P_VERSION_RELAY,
2425
)
2526
from test_framework.test_framework import BitcoinTestFramework
@@ -136,6 +137,7 @@ def run_test(self):
136137
old_version_msg = msg_version()
137138
old_version_msg.nVersion = 31799
138139
old_version_msg.strSubVer = P2P_SUBVERSION
140+
old_version_msg.nServices = P2P_SERVICES
139141
old_version_msg.relay = P2P_VERSION_RELAY
140142
with self.nodes[0].assert_debug_log(['peer=3 using obsolete version 31799; disconnecting']):
141143
p2p_old_peer.send_message(old_version_msg)

test/functional/test_framework/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ class msg_version:
10221022

10231023
def __init__(self):
10241024
self.nVersion = 0
1025-
self.nServices = NODE_NETWORK | NODE_WITNESS
1025+
self.nServices = 0
10261026
self.nTime = int(time.time())
10271027
self.addrTo = CAddress()
10281028
self.addrFrom = CAddress()

test/functional/test_framework/p2p.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
# The P2P version that this test framework implements and sends in its `version` message
8484
# Version 70016 supports wtxid relay
8585
P2P_VERSION = 70016
86+
# The services that this test framework offers in its `version` message
87+
P2P_SERVICES = NODE_NETWORK | NODE_WITNESS
8688
# The P2P user agent string that this test framework sends in its `version` message
8789
P2P_SUBVERSION = "/python-p2p-tester:0.0.3/"
8890
# Value for relay that this test framework sends in its `version` message
@@ -346,7 +348,7 @@ def peer_connect_send_version(self, services):
346348
vt.addrFrom.port = 0
347349
self.on_connection_send_msg = vt # Will be sent in connection_made callback
348350

349-
def peer_connect(self, *args, services=NODE_NETWORK | NODE_WITNESS, send_version=True, **kwargs):
351+
def peer_connect(self, *args, services=P2P_SERVICES, send_version=True, **kwargs):
350352
create_conn = super().peer_connect(*args, **kwargs)
351353

352354
if send_version:

0 commit comments

Comments
 (0)