Skip to content

Commit 9b4054c

Browse files
committed
[test] Move MY_SUBVERSION 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 move MY_SUBVERSION to p2p.py. Also rename to P2P_SUBVERSION.
1 parent 7e158a6 commit 9b4054c

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
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_SUBVERSION,
2425
P2P_VERSION,
2526
p2p_lock,
2627
)
@@ -223,6 +224,7 @@ def run_test(self):
223224
# Send version with fRelay=False
224225
version_without_fRelay = msg_version()
225226
version_without_fRelay.nVersion = P2P_VERSION
227+
version_without_fRelay.strSubVer = P2P_SUBVERSION
226228
version_without_fRelay.nRelay = 0
227229
filter_peer_without_nrelay.send_message(version_without_fRelay)
228230
filter_peer_without_nrelay.wait_for_verack()

test/functional/p2p_leak.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
msg_ping,
1818
msg_version,
1919
)
20-
from test_framework.p2p import P2PInterface
20+
from test_framework.p2p import (
21+
P2PInterface,
22+
P2P_SUBVERSION,
23+
)
2124
from test_framework.test_framework import BitcoinTestFramework
2225
from test_framework.util import (
2326
assert_equal,
@@ -131,6 +134,7 @@ def run_test(self):
131134
p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
132135
old_version_msg = msg_version()
133136
old_version_msg.nVersion = 31799
137+
old_version_msg.strSubVer = P2P_SUBVERSION
134138
with self.nodes[0].assert_debug_log(['peer=3 using obsolete version 31799; disconnecting']):
135139
p2p_old_peer.send_message(old_version_msg)
136140
p2p_old_peer.wait_for_disconnect()

test/functional/test_framework/messages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from test_framework.siphash import siphash256
3232
from test_framework.util import hex_str_to_bytes, assert_equal
3333

34-
MY_SUBVERSION = "/python-p2p-tester:0.0.3/"
3534
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
3635

3736
MAX_LOCATOR_SZ = 101
@@ -1030,7 +1029,7 @@ def __init__(self):
10301029
self.addrTo = CAddress()
10311030
self.addrFrom = CAddress()
10321031
self.nNonce = random.getrandbits(64)
1033-
self.strSubVer = MY_SUBVERSION
1032+
self.strSubVer = ''
10341033
self.nStartingHeight = -1
10351034
self.nRelay = MY_RELAY
10361035

test/functional/test_framework/p2p.py

Lines changed: 3 additions & 0 deletions
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 P2P user agent string that this test framework sends in its `version` message
87+
P2P_SUBVERSION = "/python-p2p-tester:0.0.3/"
8688

8789
MESSAGEMAP = {
8890
b"addr": msg_addr,
@@ -333,6 +335,7 @@ def peer_connect_send_version(self, services):
333335
# Send a version msg
334336
vt = msg_version()
335337
vt.nVersion = P2P_VERSION
338+
vt.strSubVer = P2P_SUBVERSION
336339
vt.nServices = services
337340
vt.addrTo.ip = self.dstaddr
338341
vt.addrTo.port = self.dstport

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from .authproxy import JSONRPCException
2525
from .descriptors import descsum_create
26-
from .messages import MY_SUBVERSION
26+
from .p2p import P2P_SUBVERSION
2727
from .util import (
2828
MAX_NODES,
2929
append_config,
@@ -572,7 +572,7 @@ def addconnection_callback(address, port):
572572

573573
def num_test_p2p_connections(self):
574574
"""Return number of test framework p2p connections to the node."""
575-
return len([peer for peer in self.getpeerinfo() if peer['subver'] == MY_SUBVERSION])
575+
return len([peer for peer in self.getpeerinfo() if peer['subver'] == P2P_SUBVERSION])
576576

577577
def disconnect_p2ps(self):
578578
"""Close all p2p connections to the node."""

0 commit comments

Comments
 (0)