fix/test: Count MN connections properly, add more tests for getnetworkinfo (#4928)

* fix: Count MN connections properly

* tests: check extended connections info returned via getnetworkinfo
This commit is contained in:
UdjinM6 2022-07-26 00:38:07 +03:00 committed by pasta
parent fa12c9685c
commit 8a1a86b063
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
2 changed files with 23 additions and 13 deletions

View File

@ -3366,6 +3366,8 @@ size_t CConnman::GetNodeCount(NumConnections flags)
}
if (flags & (pnode->fInbound ? CONNECTIONS_IN : CONNECTIONS_OUT)) {
nNum++;
} else if (flags == CONNECTIONS_VERIFIED) {
nNum++;
}
}

View File

@ -7,7 +7,7 @@
Tests correspond to code in rpc/net.cpp.
"""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.test_framework import DashTestFramework
from test_framework.util import (
assert_equal,
assert_greater_than_or_equal,
@ -47,15 +47,9 @@ def assert_net_servicesnames(servicesflag, servicenames):
assert "HEADERS_COMPRESSED" in servicenames
class NetTest(BitcoinTestFramework):
class NetTest(DashTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
def setup_network(self):
self.disable_mocktime()
self.setup_nodes()
connect_nodes(self.nodes[0], 1)
self.set_dash_test_params(3, 1, fast_dip3_enforcement=True)
def run_test(self):
# Wait for one ping/pong to finish so that we can be sure that there is no chatter between nodes for some time
@ -76,7 +70,9 @@ class NetTest(BitcoinTestFramework):
def _test_connection_count(self):
# connect_nodes connects each node to the other
assert_equal(self.nodes[0].getconnectioncount(), 2)
# and node0 was also connected to node2 (a masternode)
# during network setup
assert_equal(self.nodes[0].getconnectioncount(), 3)
def _test_getnettotals(self):
# getnettotals totalbytesrecv and totalbytessent should be
@ -87,7 +83,7 @@ class NetTest(BitcoinTestFramework):
net_totals_before = self.nodes[0].getnettotals()
peer_info = self.nodes[0].getpeerinfo()
net_totals_after = self.nodes[0].getnettotals()
assert_equal(len(peer_info), 2)
assert_equal(len(peer_info), 3)
peers_recv = sum([peer['bytesrecv'] for peer in peer_info])
peers_sent = sum([peer['bytessent'] for peer in peer_info])
@ -110,7 +106,7 @@ class NetTest(BitcoinTestFramework):
def _test_getnetworkinfo(self):
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 3)
self.nodes[0].setnetworkactive(state=False)
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False)
@ -131,6 +127,17 @@ class NetTest(BitcoinTestFramework):
for info in network_info:
assert_net_servicesnames(int(info["localservices"], 16), info["localservicesnames"])
self.log.info('Test extended connections info')
connect_nodes(self.nodes[1], 2)
self.nodes[1].ping()
wait_until(lambda: all(['pingtime' in n for n in self.nodes[1].getpeerinfo()]))
assert_equal(self.nodes[1].getnetworkinfo()['connections'], 3)
assert_equal(self.nodes[1].getnetworkinfo()['inboundconnections'], 1)
assert_equal(self.nodes[1].getnetworkinfo()['outboundconnections'], 2)
assert_equal(self.nodes[1].getnetworkinfo()['mnconnections'], 1)
assert_equal(self.nodes[1].getnetworkinfo()['inboundmnconnections'], 0)
assert_equal(self.nodes[1].getnetworkinfo()['outboundmnconnections'], 1)
def _test_getaddednodeinfo(self):
assert_equal(self.nodes[0].getaddednodeinfo(), [])
# add a node (node2) to node0
@ -180,7 +187,8 @@ class NetTest(BitcoinTestFramework):
node_addresses = self.nodes[0].getnodeaddresses(REQUEST_COUNT)
assert_equal(len(node_addresses), REQUEST_COUNT)
for a in node_addresses:
assert_greater_than(a["time"], 1527811200) # 1st June 2018
# see penalty calculations for ADDRs with nTime <= 100000000 in net_processing.cpp
assert_equal(a["time"], self.mocktime - 5 * 24 * 60 * 60 - 2 * 60 * 60)
assert_equal(a["services"], NODE_NETWORK)
assert a["address"] in imported_addrs
assert_equal(a["port"], 8333)