[CoinControl] Allow non-wallet owned change addresses
[bitcoinplatinum.git] / qa / rpc-tests / blockchain.py
blob410b85d15e35f04a31834bf3b492f9164dbce67a
1 #!/usr/bin/env python3
2 # Copyright (c) 2014-2016 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.
7 # Test RPC calls related to blockchain state. Tests correspond to code in
8 # rpc/blockchain.cpp.
11 from decimal import Decimal
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 assert_raises,
18 assert_is_hex_string,
19 assert_is_hash_string,
20 start_nodes,
21 connect_nodes_bi,
25 class BlockchainTest(BitcoinTestFramework):
26 """
27 Test blockchain-related RPC calls:
29 - gettxoutsetinfo
30 - verifychain
32 """
34 def __init__(self):
35 super().__init__()
36 self.setup_clean_chain = False
37 self.num_nodes = 2
39 def setup_network(self, split=False):
40 self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
41 connect_nodes_bi(self.nodes, 0, 1)
42 self.is_network_split = False
43 self.sync_all()
45 def run_test(self):
46 self._test_gettxoutsetinfo()
47 self._test_getblockheader()
48 self.nodes[0].verifychain(4, 0)
50 def _test_gettxoutsetinfo(self):
51 node = self.nodes[0]
52 res = node.gettxoutsetinfo()
54 assert_equal(res['total_amount'], Decimal('8725.00000000'))
55 assert_equal(res['transactions'], 200)
56 assert_equal(res['height'], 200)
57 assert_equal(res['txouts'], 200)
58 assert_equal(res['bytes_serialized'], 13924),
59 assert_equal(len(res['bestblock']), 64)
60 assert_equal(len(res['hash_serialized']), 64)
62 def _test_getblockheader(self):
63 node = self.nodes[0]
65 assert_raises(
66 JSONRPCException, lambda: node.getblockheader('nonsense'))
68 besthash = node.getbestblockhash()
69 secondbesthash = node.getblockhash(199)
70 header = node.getblockheader(besthash)
72 assert_equal(header['hash'], besthash)
73 assert_equal(header['height'], 200)
74 assert_equal(header['confirmations'], 1)
75 assert_equal(header['previousblockhash'], secondbesthash)
76 assert_is_hex_string(header['chainwork'])
77 assert_is_hash_string(header['hash'])
78 assert_is_hash_string(header['previousblockhash'])
79 assert_is_hash_string(header['merkleroot'])
80 assert_is_hash_string(header['bits'], length=None)
81 assert isinstance(header['time'], int)
82 assert isinstance(header['mediantime'], int)
83 assert isinstance(header['nonce'], int)
84 assert isinstance(header['version'], int)
85 assert isinstance(int(header['versionHex'], 16), int)
86 assert isinstance(header['difficulty'], Decimal)
88 if __name__ == '__main__':
89 BlockchainTest().main()