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
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 (
19 assert_is_hash_string
,
25 class BlockchainTest(BitcoinTestFramework
):
27 Test blockchain-related RPC calls:
36 self
.setup_clean_chain
= False
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
46 self
._test
_gettxoutsetinfo
()
47 self
._test
_getblockheader
()
48 self
.nodes
[0].verifychain(4, 0)
50 def _test_gettxoutsetinfo(self
):
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
):
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()