Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_net.py
Show All 14 Lines | from test_framework.util import ( | ||||
assert_greater_than_or_equal, | assert_greater_than_or_equal, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes, | connect_nodes, | ||||
p2p_port, | p2p_port, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
from test_framework.mininode import P2PInterface | from test_framework.mininode import P2PInterface | ||||
import test_framework.messages | |||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CAddress, | CAddress, | ||||
msg_addr, | msg_addr, | ||||
NODE_NETWORK, | NODE_NETWORK, | ||||
NODE_GETUTXO, | |||||
NODE_BLOOM, | |||||
NODE_XTHIN, | |||||
NODE_BITCOIN_CASH, | |||||
NODE_NETWORK_LIMITED, | |||||
NODE_AVALANCHE, | |||||
) | ) | ||||
def assert_net_servicesnames(servicesflag, servicenames): | def assert_net_servicesnames(servicesflag, servicenames): | ||||
"""Utility that checks if all flags are correctly decoded in | """Utility that checks if all flags are correctly decoded in | ||||
`getpeerinfo` and `getnetworkinfo`. | `getpeerinfo` and `getnetworkinfo`. | ||||
:param servicesflag: The services as an integer. | :param servicesflag: The services as an integer. | ||||
:param servicesnames: The list of decoded services names, as strings. | :param servicesnames: The list of decoded services names, as strings. | ||||
""" | """ | ||||
if servicesflag & NODE_NETWORK: | servicesflag_generated = 0 | ||||
assert "NETWORK" in servicenames | for servicename in servicenames: | ||||
if servicesflag & NODE_GETUTXO: | servicesflag_generated |= getattr( | ||||
assert "GETUTXO" in servicenames | test_framework.messages, 'NODE_' + servicename) | ||||
if servicesflag & NODE_BLOOM: | assert servicesflag_generated == servicesflag | ||||
assert "BLOOM" in servicenames | |||||
if servicesflag & NODE_XTHIN: | |||||
assert "XTHIN" in servicenames | |||||
if servicesflag & NODE_BITCOIN_CASH: | |||||
assert "BITCOIN_CASH" in servicenames | |||||
if servicesflag & NODE_NETWORK_LIMITED: | |||||
assert "NETWORK_LIMITED" in servicenames | |||||
if servicesflag & NODE_AVALANCHE: | |||||
assert "AVALANCHE" in servicenames | |||||
class NetTest(BitcoinTestFramework): | class NetTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-minrelaytxfee=0.00001000"], | self.extra_args = [["-minrelaytxfee=0.00001000"], | ||||
["-minrelaytxfee=0.00000500"]] | ["-minrelaytxfee=0.00000500"]] | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | def _test_getnetworkinfo(self): | ||||
connect_nodes(self.nodes[1], self.nodes[0]) | connect_nodes(self.nodes[1], self.nodes[0]) | ||||
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) | assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) | ||||
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) | assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) | ||||
# check the `servicesnames` field | # check the `servicesnames` field | ||||
network_info = [node.getnetworkinfo() for node in self.nodes] | network_info = [node.getnetworkinfo() for node in self.nodes] | ||||
for info in network_info: | for info in network_info: | ||||
assert_net_servicesnames( | assert_net_servicesnames(int(info["localservices"], 0x10), | ||||
int(info["localservices"]), info["localservicesnames"]) | info["localservicesnames"]) | ||||
def _test_getaddednodeinfo(self): | def _test_getaddednodeinfo(self): | ||||
assert_equal(self.nodes[0].getaddednodeinfo(), []) | assert_equal(self.nodes[0].getaddednodeinfo(), []) | ||||
# add a node (node2) to node0 | # add a node (node2) to node0 | ||||
ip_port = "127.0.0.1:{}".format(p2p_port(2)) | ip_port = "127.0.0.1:{}".format(p2p_port(2)) | ||||
self.nodes[0].addnode(node=ip_port, command='add') | self.nodes[0].addnode(node=ip_port, command='add') | ||||
# check that the node has indeed been added | # check that the node has indeed been added | ||||
added_nodes = self.nodes[0].getaddednodeinfo(ip_port) | added_nodes = self.nodes[0].getaddednodeinfo(ip_port) | ||||
Show All 9 Lines | def _test_getpeerinfo(self): | ||||
# the address bound to on one side will be the source address for the | # the address bound to on one side will be the source address for the | ||||
# other node | # other node | ||||
assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr']) | assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr']) | ||||
assert_equal(peer_info[1][0]['addrbind'], peer_info[0][0]['addr']) | assert_equal(peer_info[1][0]['addrbind'], peer_info[0][0]['addr']) | ||||
assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500")) | assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500")) | ||||
assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000")) | assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000")) | ||||
# check the `servicesnames` field | # check the `servicesnames` field | ||||
for info in peer_info: | for info in peer_info: | ||||
assert_net_servicesnames( | assert_net_servicesnames(int(info[0]["services"], 0x10), | ||||
int(info[0]["services"]), info[0]["servicesnames"]) | info[0]["servicesnames"]) | ||||
def _test_getnodeaddresses(self): | def _test_getnodeaddresses(self): | ||||
self.nodes[0].add_p2p_connection(P2PInterface()) | self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
# send some addresses to the node via the p2p message addr | # send some addresses to the node via the p2p message addr | ||||
msg = msg_addr() | msg = msg_addr() | ||||
imported_addrs = [] | imported_addrs = [] | ||||
for i in range(256): | for i in range(256): | ||||
Show All 33 Lines |