Changeset View
Changeset View
Standalone View
Standalone View
test/functional/blockchain.py
Show All 29 Lines | from test_framework.util import ( | ||||
assert_is_hex_string, | assert_is_hex_string, | ||||
assert_is_hash_string, | assert_is_hash_string, | ||||
) | ) | ||||
class BlockchainTest(BitcoinTestFramework): | class BlockchainTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [['-stopatheight=207']] | self.extra_args = [['-stopatheight=207', '-prune=1']] | ||||
def run_test(self): | def run_test(self): | ||||
self._test_getblockchaininfo() | |||||
self._test_getchaintxstats() | self._test_getchaintxstats() | ||||
self._test_gettxoutsetinfo() | self._test_gettxoutsetinfo() | ||||
self._test_getblockheader() | self._test_getblockheader() | ||||
self._test_getdifficulty() | self._test_getdifficulty() | ||||
self._test_getnetworkhashps() | self._test_getnetworkhashps() | ||||
self._test_stopatheight() | self._test_stopatheight() | ||||
assert self.nodes[0].verifychain(4, 0) | assert self.nodes[0].verifychain(4, 0) | ||||
def _test_getblockchaininfo(self): | |||||
self.log.info("Test getblockchaininfo") | |||||
keys = [ | |||||
'bestblockhash', | |||||
'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): | def _test_getchaintxstats(self): | ||||
chaintxstats = self.nodes[0].getchaintxstats(1) | chaintxstats = self.nodes[0].getchaintxstats(1) | ||||
# 200 txs plus genesis tx | # 200 txs plus genesis tx | ||||
assert_equal(chaintxstats['txcount'], 201) | assert_equal(chaintxstats['txcount'], 201) | ||||
# tx rate should be 1 per 10 minutes, or 1/600 | # tx rate should be 1 per 10 minutes, or 1/600 | ||||
# we have to round because of binary math | # we have to round because of binary math | ||||
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |