Skip to content

Commit

Permalink
Fix wallet_pruning.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil committed Oct 31, 2024
1 parent 7169737 commit f358cb8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions test/functional/wallet_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def mine_large_blocks(self, node, n):
height = int(best_block["height"]) + 1
self.nTime = max(self.nTime, int(best_block["time"])) + 1
previousblockhash = int(best_block["hash"], 16)
big_script = CScript([OP_RETURN] + [OP_TRUE] * 950000)
big_script = CScript([OP_RETURN] + [OP_TRUE] * 480000)
# Set mocktime to accept all future blocks
for i in self.nodes:
if i.running:
i.setmocktime(self.nTime + 600 * n)
for _ in range(n):
i.setmocktime(self.nTime + 32 * n)
for i in range(n):
block = create_block(hashprev=previousblockhash, ntime=self.nTime, coinbase=create_coinbase(height, script_pubkey=big_script))
block.solve()

Expand All @@ -59,7 +59,11 @@ def mine_large_blocks(self, node, n):

# Simulate 10 minutes of work time per block
# Important for matching a timestamp with a block +- some window
self.nTime += 600
self.nTime += 32

if i%100 == 0:
self.sync_all()

self.sync_all()

def test_wallet_import_pruned(self, wallet_name):
Expand Down Expand Up @@ -92,7 +96,7 @@ def test_wallet_import_pruned_with_missing_blocks(self, wallet_name):
# Make sure wallet cannot be imported because of missing blocks
# This will try to rescan blocks `TIMESTAMP_WINDOW` (2h) before the wallet birthheight.
# There are 6 blocks an hour, so 11 blocks (excluding birthheight).
assert_raises_rpc_error(-4, f"Pruned blocks from height {wallet_birthheight - 11} required to import keys. Use RPC call getblockchaininfo to determine your pruned height.", self.nodes[1].importwallet, self.nodes[0].datadir_path / wallet_file)
assert_raises_rpc_error(-4, f"Pruned blocks from height {wallet_birthheight - 224} required to import keys. Use RPC call getblockchaininfo to determine your pruned height.", self.nodes[1].importwallet, self.nodes[0].datadir_path / wallet_file)
self.log.info("- Done")

def get_birthheight(self, wallet_file):
Expand Down Expand Up @@ -122,18 +126,18 @@ def run_test(self):

# A blk*.dat file is 128MB
# Generate 250 light blocks
self.generate(self.nodes[0], 250)
self.generate(self.nodes[0], 2250)
# Generate 50MB worth of large blocks in the blk00000.dat file
self.mine_large_blocks(self.nodes[0], 50)
self.mine_large_blocks(self.nodes[0], 550)

# Create a wallet which birth's block is in the blk00000.dat file
wallet_birthheight_1 = "wallet_birthheight_1"
assert_equal(self.has_block(1), False)
assert_equal(self.has_block(2), False)
self.create_wallet(wallet_birthheight_1, unload=True)

# Generate enough large blocks to reach pruning disk limit
# Not pruning yet because we are still below PruneAfterHeight
self.mine_large_blocks(self.nodes[0], 600)
self.mine_large_blocks(self.nodes[0], 1200)
self.log.info("- Long chain created")

# Create a wallet with birth height > wallet_birthheight_1
Expand All @@ -149,7 +153,7 @@ def run_test(self):
self.mine_large_blocks(self.nodes[0], 5)

# blk00000.dat file is now pruned from node1
assert_equal(self.has_block(0), False)
assert_equal(self.has_block(7), False)

self.test_wallet_import_pruned(wallet_birthheight_2)
self.test_wallet_import_pruned_with_missing_blocks(wallet_birthheight_1)
Expand Down

0 comments on commit f358cb8

Please sign in to comment.