Skip to content

Commit

Permalink
Merge bitcoin#11370: [test] Add getblockchaininfo functional test
Browse files Browse the repository at this point in the history
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 bitcoin#11366).

Tree-SHA512: 56cdec0921f572874f2fdded0990d1722d1435c3ff9979e6bff1afdccdca6f8b214dbe8d7490cdac07b5758909db085132d14340de2cce943241f7ebde7e5b6c
  • Loading branch information
laanwj authored and Dmitriy Korniychuk committed Feb 8, 2022
1 parent 89b336c commit bb8cb25
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/functional/blockchain.py
Expand Up @@ -34,9 +34,10 @@
class BlockchainTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [['-stopatheight=207']]
self.extra_args = [['-stopatheight=207', '-prune=1']]

def run_test(self):
self._test_getblockchaininfo()
self._test_getchaintxstats()
self._test_gettxoutsetinfo()
self._test_getblockheader()
Expand All @@ -45,6 +46,33 @@ def run_test(self):
self._test_stopatheight()
assert self.nodes[0].verifychain(4, 0)

def _test_getblockchaininfo(self):
self.log.info("Test getblockchaininfo")

keys = [
'bestblockhash',
'bip9_softforks',
'blocks',
'chain',
'chainwork',
'difficulty',
'headers',
'mediantime',
'pruned',
'softforks',
'verificationprogress',
]
res = self.nodes[0].getblockchaininfo()
# result should have pruneheight and default keys if pruning is enabled
assert_equal(sorted(res.keys()), sorted(['pruneheight'] + keys))
# pruneheight should be greater or equal to 0
assert res['pruneheight'] >= 0

self.restart_node(0, ['-stopatheight=207'])
res = self.nodes[0].getblockchaininfo()
# should have exact keys
assert_equal(sorted(res.keys()), keys)

def _test_getchaintxstats(self):
chaintxstats = self.nodes[0].getchaintxstats(1)
# 200 txs plus genesis tx
Expand Down
5 changes: 5 additions & 0 deletions test/functional/test_framework/test_framework.py
Expand Up @@ -296,6 +296,11 @@ def stop_nodes(self, wait=0):
# Wait for nodes to stop
node.wait_until_stopped()

def restart_node(self, i, extra_args=None):
"""Stop and start a test node"""
self.stop_node(i)
self.start_node(i, extra_args)

def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None):
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
try:
Expand Down

0 comments on commit bb8cb25

Please sign in to comment.