Skip to content

Commit 2d85899

Browse files
committed
Merge #11370: [test] Add getblockchaininfo functional test
f6ffb14 [test] Add getblockchaininfo functional test (João Barbosa) fd8f45f [test] Add restart_node to BitcoinTestFramework (João Barbosa) Pull request description: Adds functional test for `getblockchaininfo`. Also deals with the fact that `pruneheight` is only in the response when pruning is enabled (related to #11366). Tree-SHA512: 56cdec0921f572874f2fdded0990d1722d1435c3ff9979e6bff1afdccdca6f8b214dbe8d7490cdac07b5758909db085132d14340de2cce943241f7ebde7e5b6c
2 parents a3b4c59 + f6ffb14 commit 2d85899

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

test/functional/blockchain.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
class BlockchainTest(BitcoinTestFramework):
3434
def set_test_params(self):
3535
self.num_nodes = 1
36-
self.extra_args = [['-stopatheight=207']]
36+
self.extra_args = [['-stopatheight=207', '-prune=1']]
3737

3838
def run_test(self):
39+
self._test_getblockchaininfo()
3940
self._test_getchaintxstats()
4041
self._test_gettxoutsetinfo()
4142
self._test_getblockheader()
@@ -44,6 +45,33 @@ def run_test(self):
4445
self._test_stopatheight()
4546
assert self.nodes[0].verifychain(4, 0)
4647

48+
def _test_getblockchaininfo(self):
49+
self.log.info("Test getblockchaininfo")
50+
51+
keys = [
52+
'bestblockhash',
53+
'bip9_softforks',
54+
'blocks',
55+
'chain',
56+
'chainwork',
57+
'difficulty',
58+
'headers',
59+
'mediantime',
60+
'pruned',
61+
'softforks',
62+
'verificationprogress',
63+
]
64+
res = self.nodes[0].getblockchaininfo()
65+
# result should have pruneheight and default keys if pruning is enabled
66+
assert_equal(sorted(res.keys()), sorted(['pruneheight'] + keys))
67+
# pruneheight should be greater or equal to 0
68+
assert res['pruneheight'] >= 0
69+
70+
self.restart_node(0, ['-stopatheight=207'])
71+
res = self.nodes[0].getblockchaininfo()
72+
# should have exact keys
73+
assert_equal(sorted(res.keys()), keys)
74+
4775
def _test_getchaintxstats(self):
4876
chaintxstats = self.nodes[0].getchaintxstats(1)
4977
# 200 txs plus genesis tx

test/functional/test_framework/test_framework.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ def stop_nodes(self):
273273
# Wait for nodes to stop
274274
node.wait_until_stopped()
275275

276+
def restart_node(self, i, extra_args=None):
277+
"""Stop and start a test node"""
278+
self.stop_node(i)
279+
self.start_node(i, extra_args)
280+
276281
def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None):
277282
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
278283
try:

0 commit comments

Comments
 (0)