Skip to content

Commit

Permalink
test: Add test for loadtxoutset when headers are not synced
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr committed Feb 26, 2024
1 parent 2bc1ecf commit 08c972d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ class AssumeutxoTest(BitcoinTestFramework):

def set_test_params(self):
"""Use the pregenerated, deterministic chain up to height 199."""
self.num_nodes = 3
self.num_nodes = 4
self.rpc_timeout = 120
self.extra_args = [
[],
["-fastprune", "-prune=1", "-blockfilterindex=1", "-coinstatsindex=1"],
["-persistmempool=0","-txindex=1", "-blockfilterindex=1", "-coinstatsindex=1"],
[],
]

def setup_network(self):
"""Start with the nodes disconnected so that one can generate a snapshot
including blocks the other hasn't yet seen."""
self.add_nodes(3)
self.add_nodes(4)
self.start_nodes(extra_args=self.extra_args)

def test_invalid_snapshot_scenarios(self, valid_snapshot_path):
Expand Down Expand Up @@ -113,6 +114,12 @@ def expected_error(log_msg="", rpc_details=""):
f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27, got {wrong_hash}")

def test_headers_not_synced(self, valid_snapshot_path):
self.log.info("Test loading snapshot when headers are not synced")
assert_raises_rpc_error(-32603, "The base block header (3bb7ce5eba0be48939b7a521ac1ba9316afee2c7bada3a0cca24188e6d7d96c0) must appear in the headers chain. Make sure all headers are syncing, and call this RPC again.",
self.nodes[3].loadtxoutset,
valid_snapshot_path)

def test_invalid_chainstate_scenarios(self):
self.log.info("Test different scenarios of invalid snapshot chainstate in datadir")

Expand Down Expand Up @@ -181,8 +188,8 @@ def run_test(self):
n1.submitheader(newblock)
n2.submitheader(newblock)

# Ensure everyone is seeing the same headers.
for n in self.nodes:
# Ensure everyone is seeing the same headers except for the last node
for n in self.nodes[:2]:
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)

self.log.info("-- Testing assumeutxo + some indexes + pruning")
Expand Down Expand Up @@ -210,6 +217,7 @@ def run_test(self):

self.test_invalid_mempool_state(dump_output['path'])
self.test_invalid_snapshot_scenarios(dump_output['path'])
self.test_headers_not_synced(dump_output['path'])
self.test_invalid_chainstate_scenarios()

self.log.info(f"Loading snapshot into second node from {dump_output['path']}")
Expand Down Expand Up @@ -317,7 +325,7 @@ def run_test(self):

self.connect_nodes(0, 2)
self.wait_until(lambda: n2.getchainstates()['chainstates'][-1]['blocks'] == FINAL_HEIGHT)
self.sync_blocks()
self.sync_blocks(nodes=self.nodes[:2])

self.log.info("Ensuring background validation completes")
self.wait_until(lambda: len(n2.getchainstates()['chainstates']) == 1)
Expand Down

0 comments on commit 08c972d

Please sign in to comment.