Skip to content

Commit 0c7ab1f

Browse files
committed
Merge #365: QA: Reactivate and improve rpc_blockchain tests
7b6a393 QA: Reactivate and improve rpc_blockchain tests (Jorge Timón)
2 parents 5ad7e17 + 7b6a393 commit 0c7ab1f

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
'signrawtransactions.py',
143143
'nodehandling.py',
144144
'decodescript.py',
145-
#'blockchain.py',
145+
'blockchain.py',
146146
#'disablewallet.py',
147147
'keypool.py',
148148
'p2p-mempool.py',

qa/rpc-tests/blockchain.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
assert_is_hash_string,
2020
start_nodes,
2121
connect_nodes_bi,
22+
assert_raises_message,
2223
)
2324

2425

@@ -45,45 +46,67 @@ def setup_network(self, split=False):
4546
def run_test(self):
4647
self._test_gettxoutsetinfo()
4748
self._test_getblockheader()
49+
self._test_getblockheader(getblock=True)
50+
self._test_getblockchaininfo()
4851
self.nodes[0].verifychain(4, 0)
4952

5053
def _test_gettxoutsetinfo(self):
5154
node = self.nodes[0]
5255
res = node.gettxoutsetinfo()
5356

54-
assert_equal(res['total_amount'], Decimal('8725.00000000'))
55-
assert_equal(res['transactions'], 200)
57+
assert 'total_amount' not in res
58+
assert_equal(res['transactions'], 1)
5659
assert_equal(res['height'], 200)
57-
assert_equal(res['txouts'], 200)
58-
assert_equal(res['bytes_serialized'], 13924),
60+
assert_equal(res['txouts'], 100)
61+
assert_equal(res['bytes_serialized'], 3948),
5962
assert_equal(len(res['bestblock']), 64)
6063
assert_equal(len(res['hash_serialized']), 64)
6164

62-
def _test_getblockheader(self):
65+
def _test_getblockheader(self, getblock=False):
6366
node = self.nodes[0]
6467

6568
assert_raises(
6669
JSONRPCException, lambda: node.getblockheader('nonsense'))
6770

6871
besthash = node.getbestblockhash()
6972
secondbesthash = node.getblockhash(199)
70-
header = node.getblockheader(besthash)
73+
if getblock:
74+
header = node.getblock(besthash)
75+
else:
76+
header = node.getblockheader(besthash)
7177

7278
assert_equal(header['hash'], besthash)
7379
assert_equal(header['height'], 200)
7480
assert_equal(header['confirmations'], 1)
7581
assert_equal(header['previousblockhash'], secondbesthash)
76-
assert_is_hex_string(header['chainwork'])
7782
assert_is_hash_string(header['hash'])
7883
assert_is_hash_string(header['previousblockhash'])
7984
assert_is_hash_string(header['merkleroot'])
80-
assert_is_hash_string(header['bits'], length=None)
8185
assert isinstance(header['time'], int)
8286
assert isinstance(header['mediantime'], int)
83-
assert isinstance(header['nonce'], int)
8487
assert isinstance(header['version'], int)
8588
assert isinstance(int(header['versionHex'], 16), int)
86-
assert isinstance(header['difficulty'], int)#always 1
89+
assert 'nonce' in header
90+
assert 'bits' in header
91+
assert 'difficulty' in header
92+
assert 'chainwork' in header
93+
94+
def _test_getblockchaininfo(self):
95+
besthash = self.nodes[0].getbestblockhash()
96+
res = self.nodes[0].getblockchaininfo()
97+
98+
assert_equal(res['chain'], 'elementsregtest')
99+
assert 'difficulty' in res
100+
assert 'chainwork' in res
101+
assert_equal(res['blocks'], 200)
102+
assert_equal(res['headers'], 200)
103+
assert_equal(res['bestblockhash'], besthash)
104+
assert isinstance(res['mediantime'], int)
105+
assert_equal(res['verificationprogress'], 1)
106+
assert_equal(res['pruned'], False)
107+
assert 'pruneheight' not in res
108+
assert 'softforks' not in res
109+
assert 'bip9_softforks' in res
87110

88111
if __name__ == '__main__':
89112
BlockchainTest().main()

0 commit comments

Comments
 (0)