Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_coinstatsindex.py
Show All 35 Lines | def set_test_params(self): | ||||
] | ] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
self._test_coin_stats_index() | self._test_coin_stats_index() | ||||
self._test_use_index_option() | self._test_use_index_option() | ||||
self._test_reorg_index() | |||||
def block_sanity_check(self, block_info): | def block_sanity_check(self, block_info): | ||||
block_subsidy = 50_000_000 | block_subsidy = 50_000_000 | ||||
assert_equal( | assert_equal( | ||||
block_info['prevout_spent'] + block_subsidy, | block_info['prevout_spent'] + block_subsidy, | ||||
block_info['new_outputs_ex_coinbase'] + block_info['coinbase'] | block_info['new_outputs_ex_coinbase'] + block_info['coinbase'] | ||||
+ block_info['unspendable'] | + block_info['unspendable'] | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | def _test_use_index_option(self): | ||||
self.connect_nodes(0, 1) | self.connect_nodes(0, 1) | ||||
self.nodes[0].waitforblockheight(110) | self.nodes[0].waitforblockheight(110) | ||||
res = self.nodes[0].gettxoutsetinfo('muhash') | res = self.nodes[0].gettxoutsetinfo('muhash') | ||||
option_res = self.nodes[1].gettxoutsetinfo( | option_res = self.nodes[1].gettxoutsetinfo( | ||||
hash_type='muhash', hash_or_height=None, use_index=False) | hash_type='muhash', hash_or_height=None, use_index=False) | ||||
del res['disk_size'], option_res['disk_size'] | del res['disk_size'], option_res['disk_size'] | ||||
assert_equal(res, option_res) | assert_equal(res, option_res) | ||||
def _test_reorg_index(self): | |||||
self.log.info("Test that index can handle reorgs") | |||||
# Generate two block, let the index catch up, then invalidate the | |||||
# blocks | |||||
index_node = self.nodes[1] | |||||
reorg_blocks = index_node.generatetoaddress( | |||||
2, index_node.getnewaddress()) | |||||
reorg_block = reorg_blocks[1] | |||||
self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", | |||||
index_node.gettxoutsetinfo, 'muhash')) | |||||
res_invalid = index_node.gettxoutsetinfo('muhash') | |||||
index_node.invalidateblock(reorg_blocks[0]) | |||||
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110) | |||||
# Add two new blocks | |||||
block = index_node.generate(2)[1] | |||||
self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", | |||||
index_node.gettxoutsetinfo, 'muhash')) | |||||
res = index_node.gettxoutsetinfo( | |||||
hash_type='muhash', hash_or_height=None, use_index=False) | |||||
# Test that the result of the reorged block is not returned for its old | |||||
# block height | |||||
res2 = index_node.gettxoutsetinfo( | |||||
hash_type='muhash', hash_or_height=112) | |||||
assert_equal(res["bestblock"], block) | |||||
assert_equal(res["muhash"], res2["muhash"]) | |||||
assert(res["muhash"] != res_invalid["muhash"]) | |||||
# Test that requesting reorged out block by hash is still returning | |||||
# correct results | |||||
res_invalid2 = index_node.gettxoutsetinfo( | |||||
hash_type='muhash', hash_or_height=reorg_block) | |||||
assert_equal(res_invalid2["muhash"], res_invalid["muhash"]) | |||||
assert(res["muhash"] != res_invalid2["muhash"]) | |||||
# Add another block, so we don't depend on reconsiderblock remembering | |||||
# which blocks were touched by invalidateblock | |||||
index_node.generate(1) | |||||
# Ensure that removing and re-adding blocks yields consistent results | |||||
block = index_node.getblockhash(99) | |||||
index_node.invalidateblock(block) | |||||
self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", | |||||
index_node.gettxoutsetinfo, 'muhash')) | |||||
index_node.reconsiderblock(block) | |||||
self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", | |||||
index_node.gettxoutsetinfo, 'muhash')) | |||||
res3 = index_node.gettxoutsetinfo( | |||||
hash_type='muhash', hash_or_height=112) | |||||
assert_equal(res2, res3) | |||||
self.log.info( | |||||
"Test that a node aware of stale blocks syncs them as well") | |||||
node = self.nodes[0] | |||||
# Ensure the node is aware of a stale block prior to restart | |||||
node.getblock(reorg_block) | |||||
self.restart_node(0, ["-coinstatsindex"]) | |||||
self.wait_until(lambda: not try_rpc(-32603, "Unable to read UTXO set", | |||||
node.gettxoutsetinfo, 'muhash')) | |||||
assert_raises_rpc_error(-32603, "Unable to read UTXO set", | |||||
node.gettxoutsetinfo, 'muhash', reorg_block) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
CoinStatsIndexTest().main() | CoinStatsIndexTest().main() |