0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

test: De-dublicate/optimize assumeutxo test for further extensions

This commit is contained in:
Fabian Jahr 2023-10-17 18:35:10 +02:00
parent 0a576d62fe
commit d3223685b1
No known key found for this signature in database
GPG key ID: F13D1E9D890798CD

View file

@ -92,20 +92,18 @@ class AssumeutxoTest(BitcoinTestFramework):
f.write(valid_snapshot_contents[32 + 8:]) f.write(valid_snapshot_contents[32 + 8:])
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") 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")
self.log.info(" - snapshot file with wrong outpoint hash") self.log.info(" - snapshot file with alternated UTXO data")
with open(bad_snapshot_path, "wb") as f: cases = [
f.write(valid_snapshot_contents[:(32 + 8)]) [b"\xff" * 32, 0, "29926acf3ac81f908cf4f22515713ca541c08bb0f0ef1b2c3443a007134d69b8"], # wrong outpoint hash
f.write(b"\xff" * 32) [(1).to_bytes(4, "little"), 32, "798266c2e1f9a98fe5ce61f5951cbf47130743f3764cf3cbc254be129142cf9d"], # wrong outpoint index
f.write(valid_snapshot_contents[(32 + 8 + 32):]) ]
expected_error(log_msg="[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got 29926acf3ac81f908cf4f22515713ca541c08bb0f0ef1b2c3443a007134d69b8")
self.log.info(" - snapshot file with wrong outpoint index") for content, offset, wrong_hash in cases:
with open(bad_snapshot_path, "wb") as f: with open(bad_snapshot_path, "wb") as f:
f.write(valid_snapshot_contents[:(32 + 8 + 32)]) f.write(valid_snapshot_contents[:(32 + 8 + offset)])
new_index = 1 # The correct index is 0 f.write(content)
f.write(new_index.to_bytes(4, "little")) f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
f.write(valid_snapshot_contents[(32 + 8 + 32 + 4):]) expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got {wrong_hash}")
expected_error(log_msg="[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got 798266c2e1f9a98fe5ce61f5951cbf47130743f3764cf3cbc254be129142cf9d")
def run_test(self): def run_test(self):
""" """