Skip to content

Commit d6faa2a

Browse files
fanquakeknst
authored andcommitted
Merge bitcoin#23036: test: use test_framework.p2p P2P_SERVICES constant in functional tests
b69a106 test: use test_framework.p2p P2P_SERVICES in functional tests (Jon Atack) Pull request description: `P2P_SERVICES` is defined in `test/functional/test_framework/p2p.py`, so we can use it as a single definition for our functional tests. It may also be a tiny bit more efficient to use the constant rather than calculating `NODE_NETWORK | NODE_WITNESS` every time we need it in the tests. ACKs for top commit: laanwj: Code review ACK b69a106 klementtan: crACK b69a106 fanquake: ACK b69a106 - didn't look at the formatting changes. Tree-SHA512: f83e593663a69182986325d9ba2b4b787b87896d6648973f4f802f191a2573201b9e7d7e10e69662ef1965fa63268845726ed1aa5742a2e38dcccf4aebc6a961
1 parent bb7589a commit d6faa2a

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

test/functional/p2p_addr_relay.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010

1111
from test_framework.messages import (
1212
CAddress,
13-
NODE_NETWORK,
1413
msg_addr,
1514
msg_getaddr,
16-
msg_verack
15+
msg_verack,
1716
)
1817
from test_framework.p2p import (
1918
P2PInterface,
2019
p2p_lock,
20+
P2P_SERVICES,
2121
)
2222
from test_framework.test_framework import BitcoinTestFramework
2323
from test_framework.util import (
2424
assert_equal,
2525
assert_greater_than,
26-
assert_greater_than_or_equal
26+
assert_greater_than_or_equal,
2727
)
2828

2929
ONE_MINUTE = 60
@@ -51,7 +51,7 @@ def on_addr(self, message):
5151
if(self.test_addr_contents):
5252
# relay_tests checks the content of the addr messages match
5353
# expectations based on the message creation in setup_addr_msg
54-
assert_equal(addr.nServices, 1)
54+
assert_equal(addr.nServices, 2049)
5555
if not 8333 <= addr.port < 8343:
5656
raise AssertionError("Invalid addr.port of {} (8333-8342 expected)".format(addr.port))
5757
assert addr.ip.startswith('123.123.')
@@ -109,7 +109,7 @@ def setup_addr_msg(self, num, sequential_ips=True):
109109
for i in range(num):
110110
addr = CAddress()
111111
addr.time = self.mocktime + random.randrange(-100, 100)
112-
addr.nServices = NODE_NETWORK
112+
addr.nServices = P2P_SERVICES
113113
if sequential_ips:
114114
assert self.counter < 256 ** 2 # Don't allow the returned ip addresses to wrap.
115115
addr.ip = f"123.123.{self.counter // 256}.{self.counter % 256}"

test/functional/p2p_addrfetch.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88

99
import time
1010

11-
from test_framework.messages import msg_addr, CAddress, NODE_NETWORK
12-
from test_framework.p2p import P2PInterface, p2p_lock
11+
from test_framework.messages import (
12+
CAddress,
13+
msg_addr,
14+
)
15+
from test_framework.p2p import (
16+
P2PInterface,
17+
p2p_lock,
18+
P2P_SERVICES,
19+
)
1320
from test_framework.test_framework import BitcoinTestFramework
1421
from test_framework.util import assert_equal
1522

1623
ADDR = CAddress()
1724
ADDR.time = int(time.time())
18-
ADDR.nServices = NODE_NETWORK
25+
ADDR.nServices = P2P_SERVICES
1926
ADDR.ip = "192.0.0.8"
2027
ADDR.port = 18444
2128

test/functional/p2p_addrv2_relay.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
from test_framework.messages import (
1212
CAddress,
1313
msg_addrv2,
14-
NODE_NETWORK,
1514
)
16-
from test_framework.p2p import P2PInterface
15+
from test_framework.p2p import (
16+
P2PInterface,
17+
P2P_SERVICES,
18+
)
1719
from test_framework.test_framework import BitcoinTestFramework
1820
from test_framework.util import assert_equal
1921

@@ -42,7 +44,7 @@ def calc_addrv2_msg_size(addrs):
4244
size = 1 # vector length byte
4345
for addr in addrs:
4446
size += 4 # time
45-
size += 1 # services, COMPACTSIZE(P2P_SERVICES)
47+
size += 3 # services, COMPACTSIZE(P2P_SERVICES)
4648
size += 1 # network id
4749
size += 1 # address length byte
4850
size += addr.ADDRV2_ADDRESS_LENGTH[addr.net] # address
@@ -60,7 +62,7 @@ def run_test(self):
6062
addr = CAddress()
6163
addr.time = int(self.mocktime) + i
6264
addr.port = 8333 + i
63-
addr.nServices = NODE_NETWORK
65+
addr.nServices = P2P_SERVICES
6466
# Add one I2P and one onion V3 address at an arbitrary position.
6567
if i == 5:
6668
addr.net = addr.NET_I2P

test/functional/rpc_net.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
Tests correspond to code in rpc/net.cpp.
88
"""
99

10-
from test_framework.p2p import P2PInterface
1110
import test_framework.messages
1211
from test_framework.messages import (
1312
MAX_PROTOCOL_MESSAGE_LENGTH,
14-
NODE_NETWORK,
13+
)
14+
from test_framework.p2p import (
15+
P2PInterface,
1516
)
1617

1718
from itertools import product
@@ -270,7 +271,6 @@ def test_service_flags(self):
270271
def test_getnodeaddresses(self):
271272
self.log.info("Test getnodeaddresses")
272273
self.nodes[0].add_p2p_connection(P2PInterface())
273-
services = NODE_NETWORK
274274

275275
# Add an IPv6 address to the address manager.
276276
ipv6_addr = "1233:3432:2434:2343:3234:2345:6546:4534"
@@ -298,7 +298,7 @@ def test_getnodeaddresses(self):
298298
assert_greater_than(10000, len(node_addresses))
299299
for a in node_addresses:
300300
assert_equal(a["time"], self.mocktime)
301-
assert_equal(a["services"], services)
301+
assert_equal(a["services"], 1)
302302
assert a["address"] in imported_addrs
303303
assert_equal(a["port"], 8333)
304304
assert_equal(a["network"], "ipv4")
@@ -309,7 +309,7 @@ def test_getnodeaddresses(self):
309309
assert_equal(res[0]["address"], ipv6_addr)
310310
assert_equal(res[0]["network"], "ipv6")
311311
assert_equal(res[0]["port"], 8333)
312-
assert_equal(res[0]["services"], services)
312+
assert_equal(res[0]["services"], 1)
313313

314314
# Test for the absence of onion, I2P and CJDNS addresses.
315315
for network in ["onion", "i2p", "cjdns"]:

test/functional/test_framework/p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def peer_connect(self, *, services=P2P_SERVICES, send_version, **kwargs):
540540

541541
return create_conn
542542

543-
def peer_accept_connection(self, *args, services=NODE_NETWORK | NODE_HEADERS_COMPRESSED, **kwargs):
543+
def peer_accept_connection(self, *args, services=P2P_SERVICES, **kwargs):
544544
create_conn = super().peer_accept_connection(*args, **kwargs)
545545
self.peer_connect_send_version(services)
546546

0 commit comments

Comments
 (0)