Skip to content

Commit 86c3b84

Browse files
committed
Merge bitcoin/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
2 parents 8bda5e0 + b69a106 commit 86c3b84

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

test/functional/p2p_addr_relay.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
Test addr relay
77
"""
88

9+
import random
10+
import time
11+
912
from test_framework.messages import (
1013
CAddress,
11-
NODE_NETWORK,
12-
NODE_WITNESS,
1314
msg_addr,
1415
msg_getaddr,
15-
msg_verack
16+
msg_verack,
1617
)
1718
from test_framework.p2p import (
1819
P2PInterface,
1920
p2p_lock,
21+
P2P_SERVICES,
2022
)
2123
from test_framework.test_framework import BitcoinTestFramework
2224
from test_framework.util import assert_equal, assert_greater_than
23-
import random
24-
import time
2525

2626

2727
class AddrReceiver(P2PInterface):
@@ -96,7 +96,7 @@ def setup_addr_msg(self, num):
9696
for i in range(num):
9797
addr = CAddress()
9898
addr.time = self.mocktime + i
99-
addr.nServices = NODE_NETWORK | NODE_WITNESS
99+
addr.nServices = P2P_SERVICES
100100
addr.ip = f"123.123.123.{self.counter % 256}"
101101
addr.port = 8333 + i
102102
addrs.append(addr)
@@ -111,7 +111,7 @@ def setup_rand_addr_msg(self, num):
111111
for i in range(num):
112112
addr = CAddress()
113113
addr.time = self.mocktime + i
114-
addr.nServices = NODE_NETWORK | NODE_WITNESS
114+
addr.nServices = P2P_SERVICES
115115
addr.ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}"
116116
addr.port = 8333
117117
addrs.append(addr)

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, NODE_WITNESS
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 | NODE_WITNESS
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
from test_framework.messages import (
1212
CAddress,
1313
msg_addrv2,
14-
NODE_NETWORK,
15-
NODE_WITNESS,
1614
)
17-
from test_framework.p2p import P2PInterface
15+
from test_framework.p2p import (
16+
P2PInterface,
17+
P2P_SERVICES,
18+
)
1819
from test_framework.test_framework import BitcoinTestFramework
1920
from test_framework.util import assert_equal
2021

@@ -24,7 +25,7 @@
2425
for i in range(10):
2526
addr = CAddress()
2627
addr.time = int(time.time()) + i
27-
addr.nServices = NODE_NETWORK | NODE_WITNESS
28+
addr.nServices = P2P_SERVICES
2829
# Add one I2P address at an arbitrary position.
2930
if i == 5:
3031
addr.net = addr.NET_I2P

test/functional/p2p_segwit.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from test_framework.p2p import (
4444
P2PInterface,
4545
p2p_lock,
46+
P2P_SERVICES,
4647
)
4748
from test_framework.script import (
4849
CScript,
@@ -224,14 +225,14 @@ def update_witness_block_with_transactions(self, block, tx_list, nonce=0):
224225

225226
def run_test(self):
226227
# Setup the p2p connections
227-
# self.test_node sets NODE_WITNESS|NODE_NETWORK
228-
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
228+
# self.test_node sets P2P_SERVICES, i.e. NODE_WITNESS | NODE_NETWORK
229+
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=P2P_SERVICES)
229230
# self.old_node sets only NODE_NETWORK
230231
self.old_node = self.nodes[0].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK)
231232
# self.std_node is for testing node1 (fRequireStandard=true)
232-
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=NODE_NETWORK | NODE_WITNESS)
233+
self.std_node = self.nodes[1].add_p2p_connection(TestP2PConn(), services=P2P_SERVICES)
233234
# self.std_wtx_node is for testing node1 with wtxid relay
234-
self.std_wtx_node = self.nodes[1].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=NODE_NETWORK | NODE_WITNESS)
235+
self.std_wtx_node = self.nodes[1].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=P2P_SERVICES)
235236

236237
assert self.test_node.nServices & NODE_WITNESS != 0
237238

@@ -2017,8 +2018,8 @@ def serialize(self):
20172018
@subtest # type: ignore
20182019
def test_wtxid_relay(self):
20192020
# Use brand new nodes to avoid contamination from earlier tests
2020-
self.wtx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=NODE_NETWORK | NODE_WITNESS)
2021-
self.tx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=False), services=NODE_NETWORK | NODE_WITNESS)
2021+
self.wtx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=P2P_SERVICES)
2022+
self.tx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=False), services=P2P_SERVICES)
20222023

20232024
# Check wtxidrelay feature negotiation message through connecting a new peer
20242025
def received_wtxidrelay():

test/functional/rpc_net.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
import time
1313

1414
from test_framework.blocktools import COINBASE_MATURITY
15-
from test_framework.p2p import P2PInterface
1615
import test_framework.messages
17-
from test_framework.messages import (
18-
NODE_NETWORK,
19-
NODE_WITNESS,
16+
from test_framework.p2p import (
17+
P2PInterface,
18+
P2P_SERVICES,
2019
)
2120
from test_framework.test_framework import BitcoinTestFramework
2221
from test_framework.util import (
@@ -189,7 +188,6 @@ def test_service_flags(self):
189188
def test_getnodeaddresses(self):
190189
self.log.info("Test getnodeaddresses")
191190
self.nodes[0].add_p2p_connection(P2PInterface())
192-
services = NODE_NETWORK | NODE_WITNESS
193191

194192
# Add an IPv6 address to the address manager.
195193
ipv6_addr = "1233:3432:2434:2343:3234:2345:6546:4534"
@@ -217,7 +215,7 @@ def test_getnodeaddresses(self):
217215
assert_greater_than(10000, len(node_addresses))
218216
for a in node_addresses:
219217
assert_greater_than(a["time"], 1527811200) # 1st June 2018
220-
assert_equal(a["services"], services)
218+
assert_equal(a["services"], P2P_SERVICES)
221219
assert a["address"] in imported_addrs
222220
assert_equal(a["port"], 8333)
223221
assert_equal(a["network"], "ipv4")
@@ -228,7 +226,7 @@ def test_getnodeaddresses(self):
228226
assert_equal(res[0]["address"], ipv6_addr)
229227
assert_equal(res[0]["network"], "ipv6")
230228
assert_equal(res[0]["port"], 8333)
231-
assert_equal(res[0]["services"], services)
229+
assert_equal(res[0]["services"], P2P_SERVICES)
232230

233231
# Test for the absence of onion and I2P addresses.
234232
for network in ["onion", "i2p"]:

test/functional/test_framework/p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def peer_connect(self, *args, services=P2P_SERVICES, send_version=True, **kwargs
356356

357357
return create_conn
358358

359-
def peer_accept_connection(self, *args, services=NODE_NETWORK | NODE_WITNESS, **kwargs):
359+
def peer_accept_connection(self, *args, services=P2P_SERVICES, **kwargs):
360360
create_conn = super().peer_accept_connection(*args, **kwargs)
361361
self.peer_connect_send_version(services)
362362

0 commit comments

Comments
 (0)