Skip to content

Commit ebfd653

Browse files
committed
Merge #10077: [qa] Add setnetworkactive smoke test
fa697b7 [qa] Add setnetworkactive smoke test (MarcoFalke) Tree-SHA512: 7205bae16f551e93383987392702e6853cfb06d4448735815fa116385cbf5deb6c4a8f521efdd43cf3cc59fede3b3d1ffe74e662890b74bcc21b5c13ce1f20b7
2 parents 12af74b + fa697b7 commit ebfd653

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

test/functional/net.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2017 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test RPC calls related to net.
6+
7+
Tests correspond to code in rpc/net.cpp.
8+
"""
9+
10+
from decimal import Decimal
11+
import time
12+
13+
from test_framework.test_framework import BitcoinTestFramework
14+
from test_framework.authproxy import JSONRPCException
15+
from test_framework.util import (
16+
assert_equal,
17+
start_nodes,
18+
connect_nodes_bi,
19+
)
20+
21+
22+
class NetTest(BitcoinTestFramework):
23+
def __init__(self):
24+
super().__init__()
25+
self.setup_clean_chain = True
26+
self.num_nodes = 2
27+
28+
def setup_network(self):
29+
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
30+
connect_nodes_bi(self.nodes, 0, 1)
31+
self.is_network_split = False
32+
self.sync_all()
33+
34+
def run_test(self):
35+
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
36+
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) # bilateral connection
37+
38+
self.nodes[0].setnetworkactive(False)
39+
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False)
40+
timeout = 3
41+
while self.nodes[0].getnetworkinfo()['connections'] != 0:
42+
# Wait a bit for all sockets to close
43+
assert timeout > 0, 'not all connections closed in time'
44+
timeout -= 0.1
45+
time.sleep(0.1)
46+
47+
self.nodes[0].setnetworkactive(True)
48+
connect_nodes_bi(self.nodes, 0, 1)
49+
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
50+
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
51+
52+
53+
if __name__ == '__main__':
54+
NetTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
'decodescript.py',
7272
'blockchain.py',
7373
'disablewallet.py',
74+
'net.py',
7475
'keypool.py',
7576
'p2p-mempool.py',
7677
'prioritise_transaction.py',

0 commit comments

Comments
 (0)