You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.7 KiB
84 lines
2.7 KiB
9 years ago
|
#!/usr/bin/env python3
|
||
|
# Copyright (c) 2014-2016 The Bitcoin Core developers
|
||
9 years ago
|
# Distributed under the MIT software license, see the accompanying
|
||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
8 years ago
|
"""Test RPCs related to blockchainstate.
|
||
9 years ago
|
|
||
8 years ago
|
Test the following RPCs:
|
||
|
- gettxoutsetinfo
|
||
|
- verifychain
|
||
|
|
||
|
Tests correspond to code in rpc/blockchain.cpp.
|
||
|
"""
|
||
9 years ago
|
|
||
9 years ago
|
from decimal import Decimal
|
||
9 years ago
|
|
||
|
from test_framework.test_framework import BitcoinTestFramework
|
||
|
from test_framework.util import (
|
||
|
assert_equal,
|
||
8 years ago
|
assert_raises_jsonrpc,
|
||
9 years ago
|
assert_is_hex_string,
|
||
|
assert_is_hash_string,
|
||
9 years ago
|
start_nodes,
|
||
|
connect_nodes_bi,
|
||
|
)
|
||
|
|
||
9 years ago
|
|
||
9 years ago
|
class BlockchainTest(BitcoinTestFramework):
|
||
|
|
||
9 years ago
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.setup_clean_chain = False
|
||
|
self.num_nodes = 2
|
||
9 years ago
|
|
||
|
def setup_network(self, split=False):
|
||
9 years ago
|
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
|
||
9 years ago
|
connect_nodes_bi(self.nodes, 0, 1)
|
||
|
self.is_network_split = False
|
||
|
self.sync_all()
|
||
|
|
||
|
def run_test(self):
|
||
9 years ago
|
self._test_gettxoutsetinfo()
|
||
|
self._test_getblockheader()
|
||
9 years ago
|
self.nodes[0].verifychain(4, 0)
|
||
9 years ago
|
|
||
|
def _test_gettxoutsetinfo(self):
|
||
9 years ago
|
node = self.nodes[0]
|
||
|
res = node.gettxoutsetinfo()
|
||
|
|
||
9 years ago
|
assert_equal(res['total_amount'], Decimal('8725.00000000'))
|
||
|
assert_equal(res['transactions'], 200)
|
||
|
assert_equal(res['height'], 200)
|
||
|
assert_equal(res['txouts'], 200)
|
||
|
assert_equal(res['bytes_serialized'], 13924),
|
||
|
assert_equal(len(res['bestblock']), 64)
|
||
|
assert_equal(len(res['hash_serialized']), 64)
|
||
9 years ago
|
|
||
9 years ago
|
def _test_getblockheader(self):
|
||
|
node = self.nodes[0]
|
||
|
|
||
8 years ago
|
assert_raises_jsonrpc(-5, "Block not found", node.getblockheader, "nonsense")
|
||
9 years ago
|
|
||
|
besthash = node.getbestblockhash()
|
||
|
secondbesthash = node.getblockhash(199)
|
||
|
header = node.getblockheader(besthash)
|
||
|
|
||
|
assert_equal(header['hash'], besthash)
|
||
|
assert_equal(header['height'], 200)
|
||
|
assert_equal(header['confirmations'], 1)
|
||
|
assert_equal(header['previousblockhash'], secondbesthash)
|
||
|
assert_is_hex_string(header['chainwork'])
|
||
|
assert_is_hash_string(header['hash'])
|
||
|
assert_is_hash_string(header['previousblockhash'])
|
||
|
assert_is_hash_string(header['merkleroot'])
|
||
|
assert_is_hash_string(header['bits'], length=None)
|
||
|
assert isinstance(header['time'], int)
|
||
|
assert isinstance(header['mediantime'], int)
|
||
|
assert isinstance(header['nonce'], int)
|
||
|
assert isinstance(header['version'], int)
|
||
9 years ago
|
assert isinstance(int(header['versionHex'], 16), int)
|
||
9 years ago
|
assert isinstance(header['difficulty'], Decimal)
|
||
9 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
BlockchainTest().main()
|