Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_blockchain.py
Show All 19 Lines | |||||
from decimal import Decimal | from decimal import Decimal | ||||
import http.client | import http.client | ||||
import subprocess | import subprocess | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than, | |||||
assert_greater_than_or_equal, | |||||
assert_raises, | assert_raises, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
assert_is_hash_string, | assert_is_hash_string, | ||||
assert_is_hex_string, | assert_is_hex_string, | ||||
) | ) | ||||
class BlockchainTest(BitcoinTestFramework): | class BlockchainTest(BitcoinTestFramework): | ||||
Show All 20 Lines | def _test_getblockchaininfo(self): | ||||
'bestblockhash', | 'bestblockhash', | ||||
'blocks', | 'blocks', | ||||
'chain', | 'chain', | ||||
'chainwork', | 'chainwork', | ||||
'difficulty', | 'difficulty', | ||||
'headers', | 'headers', | ||||
'mediantime', | 'mediantime', | ||||
'pruned', | 'pruned', | ||||
'size_on_disk', | |||||
'softforks', | 'softforks', | ||||
'verificationprogress', | 'verificationprogress', | ||||
'warnings', | 'warnings', | ||||
] | ] | ||||
res = self.nodes[0].getblockchaininfo() | res = self.nodes[0].getblockchaininfo() | ||||
# result should have pruneheight and default keys if pruning is enabled | |||||
assert_equal(sorted(res.keys()), sorted(['pruneheight'] + keys)) | # result should have these additional pruning keys if manual pruning is | ||||
# enabled | |||||
assert_equal(sorted(res.keys()), sorted( | |||||
['pruneheight', 'automatic_pruning'] + keys)) | |||||
# size_on_disk should be > 0 | |||||
assert_greater_than(res['size_on_disk'], 0) | |||||
# pruneheight should be greater or equal to 0 | # pruneheight should be greater or equal to 0 | ||||
assert res['pruneheight'] >= 0 | assert_greater_than_or_equal(res['pruneheight'], 0) | ||||
# check other pruning fields given that prune=1 | |||||
assert res['pruned'] | |||||
assert not res['automatic_pruning'] | |||||
self.restart_node(0, ['-stopatheight=207']) | self.restart_node(0, ['-stopatheight=207']) | ||||
res = self.nodes[0].getblockchaininfo() | res = self.nodes[0].getblockchaininfo() | ||||
# should have exact keys | # should have exact keys | ||||
assert_equal(sorted(res.keys()), keys) | assert_equal(sorted(res.keys()), keys) | ||||
self.restart_node(0, ['-stopatheight=207', '-prune=550']) | |||||
res = self.nodes[0].getblockchaininfo() | |||||
# result should have these additional pruning keys if prune=550 | |||||
assert_equal(sorted(res.keys()), sorted( | |||||
['pruneheight', 'automatic_pruning', 'prune_target_size'] + keys)) | |||||
# check related fields | |||||
assert res['pruned'] | |||||
assert_equal(res['pruneheight'], 0) | |||||
assert res['automatic_pruning'] | |||||
assert_equal(res['prune_target_size'], 576716800) | |||||
assert_greater_than(res['size_on_disk'], 0) | |||||
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 159 Lines • Show Last 20 Lines |