Skip to content

Commit 07a8f65

Browse files
committed
tests: add a test for the 'servicesnames' RPC field
In getpeerinfo and getnetworkinfo
1 parent 1985c4e commit 07a8f65

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

test/functional/rpc_net.py

Lines changed: 34 additions & 1 deletion
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):
@@ -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)