Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_net.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2017 The Bitcoin Core developers | # Copyright (c) 2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test RPC calls related to net. | """Test RPC calls related to net. | ||||
Tests correspond to code in rpc/net.cpp. | Tests correspond to code in rpc/net.cpp. | ||||
""" | """ | ||||
import time | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes_bi, | connect_nodes_bi, | ||||
p2p_port, | p2p_port, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def _test_getnettotals(self): | ||||
32, after['bytessent_per_msg']['ping']) | 32, after['bytessent_per_msg']['ping']) | ||||
def _test_getnetworkinginfo(self): | def _test_getnetworkinginfo(self): | ||||
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) | ||||
self.nodes[0].setnetworkactive(False) | self.nodes[0].setnetworkactive(False) | ||||
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False) | assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False) | ||||
timeout = 3 | |||||
while self.nodes[0].getnetworkinfo()['connections'] != 0: | |||||
# Wait a bit for all sockets to close | # Wait a bit for all sockets to close | ||||
assert timeout > 0, 'not all connections closed in time' | wait_until(lambda: self.nodes[0].getnetworkinfo()[ | ||||
timeout -= 0.1 | 'connections'] == 0, timeout=3) | ||||
time.sleep(0.1) | |||||
self.nodes[0].setnetworkactive(True) | self.nodes[0].setnetworkactive(True) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
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) | ||||
def _test_getaddednodeinfo(self): | def _test_getaddednodeinfo(self): | ||||
assert_equal(self.nodes[0].getaddednodeinfo(), []) | assert_equal(self.nodes[0].getaddednodeinfo(), []) | ||||
Show All 21 Lines |