Skip to content

Commit 04d9939

Browse files
committed
Merge #16850: test: servicesnames field in getpeerinfo and getnetworkinfo
1d524c6 tests: rename 'test_getnetworkinginfo' in 'test_getnetworkinfo' (darosior) 07a8f65 tests: add a test for the 'servicesnames' RPC field (darosior) Pull request description: As per bitcoin/bitcoin#16787 (comment), fixes #16844. This adds a test for both commands in the first commit and renames the test for `getnetworkinfo` in the second commit. ACKs for top commit: laanwj: ACK 1d524c6 Tree-SHA512: 8267dce4d54356debab75014e6f9ba885b892da605ed32f26a5446c232992fcae761861bb678adbdb942815d4706f3768c70deee6afec68f219b23605475be01
2 parents 2324aa1 + 1d524c6 commit 04d9939

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

test/functional/rpc_net.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,32 @@
2020
wait_until,
2121
)
2222
from test_framework.mininode import P2PInterface
23-
from test_framework.messages import CAddress, msg_addr, NODE_NETWORK, NODE_WITNESS
23+
from test_framework.messages import (
24+
CAddress,
25+
msg_addr,
26+
NODE_NETWORK,
27+
NODE_WITNESS,
28+
NODE_GETUTXO,NODE_BLOOM,
29+
NODE_NETWORK_LIMITED,
30+
)
31+
32+
def assert_net_servicesnames(servicesflag, servicenames):
33+
"""Utility that checks if all flags are correctly decoded in
34+
`getpeerinfo` and `getnetworkinfo`.
35+
36+
:param servicesflag: The services as an integer.
37+
:param servicesnames: The list of decoded services names, as strings.
38+
"""
39+
if servicesflag & NODE_NETWORK:
40+
assert "NETWORK" in servicenames
41+
if servicesflag & NODE_GETUTXO:
42+
assert "GETUTXO" in servicenames
43+
if servicesflag & NODE_BLOOM:
44+
assert "BLOOM" in servicenames
45+
if servicesflag & NODE_WITNESS:
46+
assert "WITNESS" in servicenames
47+
if servicesflag & NODE_NETWORK_LIMITED:
48+
assert "NETWORK_LIMITED" in servicenames
2449

2550
class NetTest(BitcoinTestFramework):
2651
def set_test_params(self):
@@ -31,7 +56,7 @@ def set_test_params(self):
3156
def run_test(self):
3257
self._test_connection_count()
3358
self._test_getnettotals()
34-
self._test_getnetworkinginfo()
59+
self._test_getnetworkinfo()
3560
self._test_getaddednodeinfo()
3661
self._test_getpeerinfo()
3762
self._test_getnodeaddresses()
@@ -70,7 +95,7 @@ def _test_getnettotals(self):
7095
assert_greater_than_or_equal(after['bytesrecv_per_msg'].get('pong', 0), before['bytesrecv_per_msg'].get('pong', 0) + 32)
7196
assert_greater_than_or_equal(after['bytessent_per_msg'].get('ping', 0), before['bytessent_per_msg'].get('ping', 0) + 32)
7297

73-
def _test_getnetworkinginfo(self):
98+
def _test_getnetworkinfo(self):
7499
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
75100
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
76101

@@ -84,6 +109,11 @@ def _test_getnetworkinginfo(self):
84109
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
85110
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
86111

112+
# check the `servicesnames` field
113+
network_info = [node.getnetworkinfo() for node in self.nodes]
114+
for info in network_info:
115+
assert_net_servicesnames(int(info["localservices"]), info["localservicesnames"])
116+
87117
def _test_getaddednodeinfo(self):
88118
assert_equal(self.nodes[0].getaddednodeinfo(), [])
89119
# add a node (node2) to node0
@@ -104,6 +134,9 @@ def _test_getpeerinfo(self):
104134
assert_equal(peer_info[1][0]['addrbind'], peer_info[0][0]['addr'])
105135
assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500"))
106136
assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000"))
137+
# check the `servicesnames` field
138+
for info in peer_info:
139+
assert_net_servicesnames(int(info[0]["services"]), info[0]["servicesnames"])
107140

108141
def _test_getnodeaddresses(self):
109142
self.nodes[0].add_p2p_connection(P2PInterface())

test/functional/test_framework/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
BIP125_SEQUENCE_NUMBER = 0xfffffffd # Sequence number that is BIP 125 opt-in and BIP 68-opt-out
4444

4545
NODE_NETWORK = (1 << 0)
46-
# NODE_GETUTXO = (1 << 1)
47-
# NODE_BLOOM = (1 << 2)
46+
NODE_GETUTXO = (1 << 1)
47+
NODE_BLOOM = (1 << 2)
4848
NODE_WITNESS = (1 << 3)
4949
NODE_NETWORK_LIMITED = (1 << 10)
5050

0 commit comments

Comments
 (0)