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.
7 Tests correspond to code in rpc/net.cpp.
12 from test_framework
.test_framework
import BitcoinTestFramework
13 from test_framework
.util
import (
20 class NetTest(BitcoinTestFramework
):
23 self
.setup_clean_chain
= True
26 def setup_network(self
):
27 self
.nodes
= start_nodes(self
.num_nodes
, self
.options
.tmpdir
)
28 connect_nodes_bi(self
.nodes
, 0, 1)
29 self
.is_network_split
= False
33 assert_equal(self
.nodes
[0].getnetworkinfo()['networkactive'], True)
34 assert_equal(self
.nodes
[0].getnetworkinfo()['connections'], 2) # bilateral connection
36 self
.nodes
[0].setnetworkactive(False)
37 assert_equal(self
.nodes
[0].getnetworkinfo()['networkactive'], False)
39 while self
.nodes
[0].getnetworkinfo()['connections'] != 0:
40 # Wait a bit for all sockets to close
41 assert timeout
> 0, 'not all connections closed in time'
45 self
.nodes
[0].setnetworkactive(True)
46 connect_nodes_bi(self
.nodes
, 0, 1)
47 assert_equal(self
.nodes
[0].getnetworkinfo()['networkactive'], True)
48 assert_equal(self
.nodes
[0].getnetworkinfo()['connections'], 2)
51 if __name__
== '__main__':