Skip to content

Commit d322368

Browse files
committed
test: De-dublicate/optimize assumeutxo test for further extensions
1 parent 0a576d6 commit d322368

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,18 @@ def expected_error(log_msg="", rpc_details=""):
9292
f.write(valid_snapshot_contents[32 + 8:])
9393
expected_error(log_msg=f"bad snapshot - coins left over after deserializing 298 coins" if off == -1 else f"bad snapshot format or truncated snapshot after deserializing 299 coins")
9494

95-
self.log.info(" - snapshot file with wrong outpoint hash")
96-
with open(bad_snapshot_path, "wb") as f:
97-
f.write(valid_snapshot_contents[:(32 + 8)])
98-
f.write(b"\xff" * 32)
99-
f.write(valid_snapshot_contents[(32 + 8 + 32):])
100-
expected_error(log_msg="[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got 29926acf3ac81f908cf4f22515713ca541c08bb0f0ef1b2c3443a007134d69b8")
101-
102-
self.log.info(" - snapshot file with wrong outpoint index")
103-
with open(bad_snapshot_path, "wb") as f:
104-
f.write(valid_snapshot_contents[:(32 + 8 + 32)])
105-
new_index = 1 # The correct index is 0
106-
f.write(new_index.to_bytes(4, "little"))
107-
f.write(valid_snapshot_contents[(32 + 8 + 32 + 4):])
108-
expected_error(log_msg="[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got 798266c2e1f9a98fe5ce61f5951cbf47130743f3764cf3cbc254be129142cf9d")
95+
self.log.info(" - snapshot file with alternated UTXO data")
96+
cases = [
97+
[b"\xff" * 32, 0, "29926acf3ac81f908cf4f22515713ca541c08bb0f0ef1b2c3443a007134d69b8"], # wrong outpoint hash
98+
[(1).to_bytes(4, "little"), 32, "798266c2e1f9a98fe5ce61f5951cbf47130743f3764cf3cbc254be129142cf9d"], # wrong outpoint index
99+
]
100+
101+
for content, offset, wrong_hash in cases:
102+
with open(bad_snapshot_path, "wb") as f:
103+
f.write(valid_snapshot_contents[:(32 + 8 + offset)])
104+
f.write(content)
105+
f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
106+
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got {wrong_hash}")
109107

110108
def run_test(self):
111109
"""

0 commit comments

Comments
 (0)