Skip to content

Commit

Permalink
test: Add coverage for failing dumptxoutset behavior
Browse files Browse the repository at this point in the history
In case of a failure to create the dump, the node should not be left in an inconsistent state like deactivated network activity or an invalidated blockchain.
  • Loading branch information
fjahr committed Sep 4, 2024
1 parent b8d2f58 commit 25358d2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/functional/rpc_dumptxoutset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""Test the generation of UTXO snapshots using `dumptxoutset`.
"""

import os

from test_framework.blocktools import COINBASE_MATURITY
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
Expand All @@ -28,7 +30,7 @@ def run_test(self):

FILENAME = 'txoutset.dat'
out = node.dumptxoutset(FILENAME, "latest")
expected_path = node.datadir_path / self.chain / FILENAME
expected_path = node.chain_path / FILENAME

assert expected_path.is_file()

Expand Down Expand Up @@ -60,6 +62,16 @@ def run_test(self):
assert_raises_rpc_error(
-8, 'Invalid snapshot type "bogus" specified. Please specify "rollback" or "latest"', node.dumptxoutset, 'utxos.dat', "bogus")

self.log.info(f"Test that dumptxoutset failure does not leave the network activity suspended")
rev_file = node.chain_path / "blocks" / "rev00000.dat"
bogus_file = node.chain_path / "blocks" / "bogus.dat"
os.rename(rev_file, bogus_file)
assert_raises_rpc_error(
-1, 'Could not roll back to requested height.', node.dumptxoutset, 'utxos.dat', rollback=99)
assert_equal(node.getnetworkinfo()['networkactive'], True)

# Cleanup
os.rename(bogus_file, rev_file)

if __name__ == '__main__':
DumptxoutsetTest(__file__).main()

0 comments on commit 25358d2

Please sign in to comment.