2020 wait_until ,
2121)
2222from 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
2550class 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 ())
0 commit comments