Skip to content

Commit f6ffb14

Browse files
committed
[test] Add getblockchaininfo functional test
1 parent fd8f45f commit f6ffb14

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-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

0 commit comments

Comments
 (0)