Skip to content

Commit ace3f4c

Browse files
committed
test: improve assertions in feature_blockfilterindex_prune.py
1 parent 1b1d8bd commit ace3f4c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

test/functional/feature_blockfilterindex_prune.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,48 @@ def set_test_params(self):
1616
self.num_nodes = 2
1717
self.extra_args = [["-fastprune", "-prune=1"], ["-fastprune", "-prune=1", "-blockfilterindex=1"]]
1818

19+
def sync_index(self, height):
20+
expected = {'basic block filter index': {'synced': True, 'best_block_height': height}}
21+
self.wait_until(lambda: self.nodes[1].getindexinfo() == expected)
22+
1923
def run_test(self):
2024
self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned")
21-
self.wait_until(lambda: self.nodes[1].getindexinfo() == {'basic block filter index': {'synced': True, 'best_block_height': 200}})
22-
assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0
25+
self.sync_index(height=200)
26+
assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']), 0)
2327
# Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
2428
self.nodes[1].generate(250)
2529
self.sync_all()
2630
self.nodes[1].generate(250)
2731
self.sync_all()
28-
self.wait_until(lambda: self.nodes[1].getindexinfo() == {'basic block filter index': {'synced': True, 'best_block_height': 700}})
32+
self.sync_index(height=700)
33+
2934
self.log.info("prune some blocks")
3035
pruneheight = self.nodes[1].pruneblockchain(400)
3136
assert_equal(pruneheight, 250)
37+
3238
self.log.info("check if we can access the tips blockfilter when we have pruned some blocks")
33-
assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0
39+
assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']), 0)
40+
3441
self.log.info("check if we can access the blockfilter of a pruned block")
35-
assert len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']) > 0
42+
assert_greater_than(len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']), 0)
43+
3644
self.log.info("start node without blockfilterindex")
3745
self.stop_node(1)
3846
self.start_node(1, extra_args=self.extra_args[0])
47+
3948
self.log.info("make sure accessing the blockfilters throws an error")
4049
assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2))
4150
self.nodes[1].generate(1000)
51+
4252
self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled")
4353
pruneheight_new = self.nodes[1].pruneblockchain(1000)
4454
assert_greater_than(pruneheight_new, pruneheight)
4555
self.stop_node(1)
56+
4657
self.log.info("make sure we get an init error when starting the node again with block filters")
4758
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)"]):
4859
self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1])
60+
4961
self.log.info("make sure the node starts again with the -reindex arg")
5062
reindex_args = self.extra_args[1]
5163
reindex_args.append("-reindex")

0 commit comments

Comments
 (0)