diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-04-02 15:39:20 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-04-02 15:39:26 +0200 |
commit | ebfd653798113a53a604dcaa98c56b2d6638ad5d (patch) | |
tree | 574abc7a42764578d7ababf6c27d2a265f4bd852 /test | |
parent | 12af74b289f8cdc6caf850dc6c802f9936b1e8b3 (diff) | |
parent | fa697b719286c599103d04c7055b7c666e71f09d (diff) |
Merge #10077: [qa] Add setnetworkactive smoke test
fa697b7 [qa] Add setnetworkactive smoke test (MarcoFalke)
Tree-SHA512: 7205bae16f551e93383987392702e6853cfb06d4448735815fa116385cbf5deb6c4a8f521efdd43cf3cc59fede3b3d1ffe74e662890b74bcc21b5c13ce1f20b7
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/net.py | 54 | ||||
-rwxr-xr-x | test/functional/test_runner.py | 1 |
2 files changed, 55 insertions, 0 deletions
diff --git a/test/functional/net.py b/test/functional/net.py new file mode 100755 index 0000000000..e9463c7dc7 --- /dev/null +++ b/test/functional/net.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# Copyright (c) 2017 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test RPC calls related to net. + +Tests correspond to code in rpc/net.cpp. +""" + +from decimal import Decimal +import time + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.authproxy import JSONRPCException +from test_framework.util import ( + assert_equal, + start_nodes, + connect_nodes_bi, +) + + +class NetTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 2 + + def setup_network(self): + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) + connect_nodes_bi(self.nodes, 0, 1) + self.is_network_split = False + self.sync_all() + + def run_test(self): + assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) + assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) # bilateral connection + + self.nodes[0].setnetworkactive(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 + assert timeout > 0, 'not all connections closed in time' + timeout -= 0.1 + time.sleep(0.1) + + self.nodes[0].setnetworkactive(True) + connect_nodes_bi(self.nodes, 0, 1) + assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True) + assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) + + +if __name__ == '__main__': + NetTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 37a2ab62a4..b1a5d2de94 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -71,6 +71,7 @@ BASE_SCRIPTS= [ 'decodescript.py', 'blockchain.py', 'disablewallet.py', + 'net.py', 'keypool.py', 'p2p-mempool.py', 'prioritise_transaction.py', |