aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_coinstatsindex.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/feature_coinstatsindex.py')
-rwxr-xr-xtest/functional/feature_coinstatsindex.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/test/functional/feature_coinstatsindex.py b/test/functional/feature_coinstatsindex.py
index 4f8541a5d7..2ffb182946 100755
--- a/test/functional/feature_coinstatsindex.py
+++ b/test/functional/feature_coinstatsindex.py
@@ -52,6 +52,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
self._test_use_index_option()
self._test_reorg_index()
self._test_index_rejects_hash_serialized()
+ self._test_init_index_after_reorg()
def block_sanity_check(self, block_info):
block_subsidy = 50
@@ -60,6 +61,9 @@ class CoinStatsIndexTest(BitcoinTestFramework):
block_info['new_outputs_ex_coinbase'] + block_info['coinbase'] + block_info['unspendable']
)
+ def sync_index_node(self):
+ self.wait_until(lambda: self.nodes[1].getindexinfo()['coinstatsindex']['synced'] is True)
+
def _test_coin_stats_index(self):
node = self.nodes[0]
index_node = self.nodes[1]
@@ -145,14 +149,14 @@ class CoinStatsIndexTest(BitcoinTestFramework):
self.block_sanity_check(res5['block_info'])
# Generate and send a normal tx with two outputs
- tx1_txid, tx1_vout = self.wallet.send_to(
+ tx1 = self.wallet.send_to(
from_node=node,
scriptPubKey=self.wallet.get_scriptPubKey(),
amount=21 * COIN,
)
# Find the right position of the 21 BTC output
- tx1_out_21 = self.wallet.get_utxo(txid=tx1_txid, vout=tx1_vout)
+ tx1_out_21 = self.wallet.get_utxo(txid=tx1["txid"], vout=tx1["sent_vout"])
# Generate and send another tx with an OP_RETURN output (which is unspendable)
tx2 = self.wallet.create_self_transfer(utxo_to_spend=tx1_out_21)['tx']
@@ -227,18 +231,16 @@ class CoinStatsIndexTest(BitcoinTestFramework):
self.log.info("Test that the index works with -reindex")
self.restart_node(1, extra_args=["-coinstatsindex", "-reindex"])
+ self.sync_index_node()
res11 = index_node.gettxoutsetinfo('muhash')
assert_equal(res11, res10)
- self.log.info("Test that -reindex-chainstate is disallowed with coinstatsindex")
+ self.log.info("Test that the index works with -reindex-chainstate")
- self.stop_node(1)
- self.nodes[1].assert_start_raises_init_error(
- expected_msg='Error: -reindex-chainstate option is not compatible with -coinstatsindex. '
- 'Please temporarily disable coinstatsindex while using -reindex-chainstate, or replace -reindex-chainstate with -reindex to fully rebuild all indexes.',
- extra_args=['-coinstatsindex', '-reindex-chainstate'],
- )
- self.restart_node(1, extra_args=["-coinstatsindex"])
+ self.restart_node(1, extra_args=["-coinstatsindex", "-reindex-chainstate"])
+ self.sync_index_node()
+ res12 = index_node.gettxoutsetinfo('muhash')
+ assert_equal(res12, res10)
def _test_use_index_option(self):
self.log.info("Test use_index option for nodes running the index")
@@ -257,6 +259,7 @@ class CoinStatsIndexTest(BitcoinTestFramework):
index_node = self.nodes[1]
reorg_blocks = self.generatetoaddress(index_node, 2, getnewdestination()[2])
reorg_block = reorg_blocks[1]
+ self.sync_index_node()
res_invalid = index_node.gettxoutsetinfo('muhash')
index_node.invalidateblock(reorg_blocks[0])
assert_equal(index_node.gettxoutsetinfo('muhash')['height'], 110)
@@ -296,6 +299,26 @@ class CoinStatsIndexTest(BitcoinTestFramework):
for use_index in {True, False, None}:
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_2', hash_or_height=111, use_index=use_index)
+ def _test_init_index_after_reorg(self):
+ self.log.info("Test a reorg while the index is deactivated")
+ index_node = self.nodes[1]
+ block = self.nodes[0].getbestblockhash()
+ self.generate(index_node, 2, sync_fun=self.no_op)
+ self.sync_index_node()
+
+ # Restart without index
+ self.restart_node(1, extra_args=[])
+ self.connect_nodes(0, 1)
+ index_node.invalidateblock(block)
+ self.generatetoaddress(index_node, 5, getnewdestination()[2])
+ res = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=False)
+
+ # Restart with index that still has its best block on the old chain
+ self.restart_node(1, extra_args=self.extra_args[1])
+ self.sync_index_node()
+ res1 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=None, use_index=True)
+ assert_equal(res["muhash"], res1["muhash"])
+
if __name__ == '__main__':
CoinStatsIndexTest().main()