From ace3f4cbdf476ea8b954d98dfaa931076f87a080 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 24 Feb 2021 22:56:37 +0100 Subject: test: improve assertions in feature_blockfilterindex_prune.py --- test/functional/feature_blockfilterindex_prune.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'test/functional') diff --git a/test/functional/feature_blockfilterindex_prune.py b/test/functional/feature_blockfilterindex_prune.py index 6648e8ecd9..449ae9fbef 100755 --- a/test/functional/feature_blockfilterindex_prune.py +++ b/test/functional/feature_blockfilterindex_prune.py @@ -16,36 +16,48 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework): self.num_nodes = 2 self.extra_args = [["-fastprune", "-prune=1"], ["-fastprune", "-prune=1", "-blockfilterindex=1"]] + def sync_index(self, height): + expected = {'basic block filter index': {'synced': True, 'best_block_height': height}} + self.wait_until(lambda: self.nodes[1].getindexinfo() == expected) + def run_test(self): self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned") - self.wait_until(lambda: self.nodes[1].getindexinfo() == {'basic block filter index': {'synced': True, 'best_block_height': 200}}) - assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0 + self.sync_index(height=200) + assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']), 0) # Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection self.nodes[1].generate(250) self.sync_all() self.nodes[1].generate(250) self.sync_all() - self.wait_until(lambda: self.nodes[1].getindexinfo() == {'basic block filter index': {'synced': True, 'best_block_height': 700}}) + self.sync_index(height=700) + self.log.info("prune some blocks") pruneheight = self.nodes[1].pruneblockchain(400) assert_equal(pruneheight, 250) + self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") - assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0 + assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']), 0) + self.log.info("check if we can access the blockfilter of a pruned block") - assert len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']) > 0 + assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']), 0) + self.log.info("start node without blockfilterindex") self.stop_node(1) self.start_node(1, extra_args=self.extra_args[0]) + self.log.info("make sure accessing the blockfilters throws an error") assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2)) self.nodes[1].generate(1000) + self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") pruneheight_new = self.nodes[1].pruneblockchain(1000) assert_greater_than(pruneheight_new, pruneheight) self.stop_node(1) + self.log.info("make sure we get an init error when starting the node again with block filters") with self.nodes[1].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"]): self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1]) + self.log.info("make sure the node starts again with the -reindex arg") reindex_args = self.extra_args[1] reindex_args.append("-reindex") -- cgit v1.2.3 From 88c4b9b761964d0b3011126796f272cfca2a9fa2 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 25 Feb 2021 15:00:37 +0100 Subject: test: remove unneeded node from feature_blockfilterindex_prune.py --- test/functional/feature_blockfilterindex_prune.py | 37 +++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'test/functional') diff --git a/test/functional/feature_blockfilterindex_prune.py b/test/functional/feature_blockfilterindex_prune.py index 449ae9fbef..d13d191b20 100755 --- a/test/functional/feature_blockfilterindex_prune.py +++ b/test/functional/feature_blockfilterindex_prune.py @@ -13,55 +13,52 @@ from test_framework.util import ( class FeatureBlockfilterindexPruneTest(BitcoinTestFramework): def set_test_params(self): - self.num_nodes = 2 - self.extra_args = [["-fastprune", "-prune=1"], ["-fastprune", "-prune=1", "-blockfilterindex=1"]] + self.num_nodes = 1 + self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1"]] def sync_index(self, height): expected = {'basic block filter index': {'synced': True, 'best_block_height': height}} - self.wait_until(lambda: self.nodes[1].getindexinfo() == expected) + self.wait_until(lambda: self.nodes[0].getindexinfo() == expected) def run_test(self): self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned") self.sync_index(height=200) - assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']), 0) + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) # Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection - self.nodes[1].generate(250) + self.nodes[0].generate(250) self.sync_all() - self.nodes[1].generate(250) + self.nodes[0].generate(250) self.sync_all() self.sync_index(height=700) self.log.info("prune some blocks") - pruneheight = self.nodes[1].pruneblockchain(400) + pruneheight = self.nodes[0].pruneblockchain(400) assert_equal(pruneheight, 250) self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") - assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']), 0) + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) self.log.info("check if we can access the blockfilter of a pruned block") - assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']), 0) + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0) self.log.info("start node without blockfilterindex") - self.stop_node(1) - self.start_node(1, extra_args=self.extra_args[0]) + self.restart_node(0, extra_args=["-fastprune", "-prune=1"]) self.log.info("make sure accessing the blockfilters throws an error") - assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2)) - self.nodes[1].generate(1000) + assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2)) + self.nodes[0].generate(1000) self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") - pruneheight_new = self.nodes[1].pruneblockchain(1000) + pruneheight_new = self.nodes[0].pruneblockchain(1000) assert_greater_than(pruneheight_new, pruneheight) - self.stop_node(1) + self.stop_node(0) self.log.info("make sure we get an init error when starting the node again with block filters") - with self.nodes[1].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"]): - self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1]) + with self.nodes[0].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"]): + self.nodes[0].assert_start_raises_init_error(extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"]) self.log.info("make sure the node starts again with the -reindex arg") - reindex_args = self.extra_args[1] - reindex_args.append("-reindex") - self.start_node(1, extra_args=reindex_args) + self.start_node(0, extra_args = ["-fastprune", "-prune=1", "-blockfilterindex", "-reindex"]) if __name__ == '__main__': -- cgit v1.2.3