Skip to content

Commit 621db2f

Browse files
committed
test: assumeutxo file with unknown block hash
1 parent 738ef44 commit 621db2f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
- TODO: An invalid hash
2121
- TODO: Valid hash but invalid snapshot file (bad coin height or truncated file or
2222
bad other serialization)
23-
- TODO: Valid snapshot file, but referencing an unknown block
2423
- TODO: Valid snapshot file, but referencing a snapshot block that turns out to be
2524
invalid, or has an invalid parent
2625
- TODO: Valid snapshot file and snapshot block, but the block is not on the
@@ -73,12 +72,14 @@ def test_invalid_snapshot_scenarios(self, valid_snapshot_path):
7372
bad_snapshot_path = valid_snapshot_path + '.mod'
7473

7574
self.log.info(" - snapshot file refering to a block that is not in the assumeutxo parameters")
76-
bad_snapshot_block_hash = self.nodes[0].getblockhash(SNAPSHOT_BASE_HEIGHT - 1)
77-
with open(bad_snapshot_path, 'wb') as f:
78-
# block hash of the snapshot base is stored right at the start (first 32 bytes)
79-
f.write(bytes.fromhex(bad_snapshot_block_hash)[::-1] + valid_snapshot_contents[32:])
80-
error_details = f"assumeutxo block hash in snapshot metadata not recognized ({bad_snapshot_block_hash})"
81-
assert_raises_rpc_error(-32603, f"Unable to load UTXO snapshot, {error_details}", self.nodes[1].loadtxoutset, bad_snapshot_path)
75+
prev_block_hash = self.nodes[0].getblockhash(SNAPSHOT_BASE_HEIGHT - 1)
76+
bogus_block_hash = "0" * 64 # Represents any unknown block hash
77+
for bad_block_hash in [bogus_block_hash, prev_block_hash]:
78+
with open(bad_snapshot_path, 'wb') as f:
79+
# block hash of the snapshot base is stored right at the start (first 32 bytes)
80+
f.write(bytes.fromhex(bad_block_hash)[::-1] + valid_snapshot_contents[32:])
81+
error_details = f"assumeutxo block hash in snapshot metadata not recognized ({bad_block_hash})"
82+
assert_raises_rpc_error(-32603, f"Unable to load UTXO snapshot, {error_details}", self.nodes[1].loadtxoutset, bad_snapshot_path)
8283

8384
self.log.info(" - snapshot file with wrong number of coins")
8485
valid_num_coins = struct.unpack("<I", valid_snapshot_contents[32:32 + 4])[0]

0 commit comments

Comments
 (0)