Dash Core  0.12.2.1
P2P Digital Currency
blockchain.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 # Copyright (c) 2014-2015 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 
6 #
7 # Test RPC calls related to blockchain state. Tests correspond to code in
8 # rpc/blockchain.cpp.
9 #
10 
11 from decimal import Decimal
12 
13 from test_framework.test_framework import BitcoinTestFramework
14 from test_framework.authproxy import JSONRPCException
15 from test_framework.util import (
16  initialize_chain,
17  assert_equal,
18  assert_raises,
19  assert_is_hex_string,
20  assert_is_hash_string,
21  start_nodes,
22  connect_nodes_bi,
23 )
24 
25 
27  """
28  Test blockchain-related RPC calls:
29 
30  - gettxoutsetinfo
31  - verifychain
32 
33  """
34 
35  def setup_chain(self):
36  print("Initializing test directory " + self.options.tmpdir)
37  initialize_chain(self.options.tmpdir)
38 
39  def setup_network(self, split=False):
40  self.nodes = start_nodes(2, self.options.tmpdir)
41  connect_nodes_bi(self.nodes, 0, 1)
42  self.is_network_split = False
43  self.sync_all()
44 
45  def run_test(self):
48  self.nodes[0].verifychain(4, 0)
49 
51  node = self.nodes[0]
52  res = node.gettxoutsetinfo()
53 
54  assert_equal(res[u'total_amount'], Decimal('98214.28571450'))
55  assert_equal(res[u'transactions'], 200)
56  assert_equal(res[u'height'], 200)
57  assert_equal(res[u'txouts'], 200)
58  assert_equal(res[u'bytes_serialized'], 14273),
59  assert_equal(len(res[u'bestblock']), 64)
60  assert_equal(len(res[u'hash_serialized']), 64)
61 
63  node = self.nodes[0]
64 
66  JSONRPCException, lambda: node.getblockheader('nonsense'))
67 
68  besthash = node.getbestblockhash()
69  secondbesthash = node.getblockhash(199)
70  header = node.getblockheader(besthash)
71 
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(header['difficulty'], Decimal)
86 
87 if __name__ == '__main__':
def _test_getblockheader(self)
Definition: blockchain.py:62
def initialize_chain(test_dir)
Definition: util.py:184
def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None)
Definition: util.py:305
def assert_raises(exc, fun, args, kwds)
Definition: util.py:469
UniValue verifychain(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:671
def assert_is_hex_string(string)
Definition: util.py:479
def setup_network(self, split=False)
Definition: blockchain.py:39
def _test_gettxoutsetinfo(self)
Definition: blockchain.py:50
def assert_is_hash_string(string, length=64)
Definition: util.py:486
def assert_equal(thing1, thing2)
Definition: util.py:461
def connect_nodes_bi(nodes, a, b)
Definition: util.py:351