diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2023-10-17 11:38:11 -0400 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2023-10-17 12:05:42 -0400 |
commit | ff6be778f94b65c6bf9748bdb1adce006d04d5dd (patch) | |
tree | 94f6c4e9166029398a01f6929d35734e9d269799 | |
parent | 738ef44abb6895dad016d8f32f7d7fa1c251b354 (diff) | |
parent | fa685715663117955e9bb795cbf79ddbd3dfed19 (diff) |
Merge bitcoin/bitcoin#28647: test: Add assumeutxo test for wrong hash
fa685715663117955e9bb795cbf79ddbd3dfed19 test: Add assumeutxo test for wrong hash (MarcoFalke)
Pull request description:
Also:
* Update test TODOs
* Fix off-by-4 typo in test, remove `struct` import
ACKs for top commit:
fjahr:
utACK fa685715663117955e9bb795cbf79ddbd3dfed19
theStack:
Code-review re-ACK fa685715663117955e9bb795cbf79ddbd3dfed19
pablomartin4btc:
re ACK fa685715663117955e9bb795cbf79ddbd3dfed19
ryanofsky:
Code review ACK fa685715663117955e9bb795cbf79ddbd3dfed19
Tree-SHA512: 877653010efe4e20018827e8ec2801d036e1344457401f0c9e5d55907b817724201dd2e3f0f29505bbff619882c0c2cd731ecdcd209258bcefe11b86ff0205dd
-rwxr-xr-x | test/functional/feature_assumeutxo.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index 376e35da3b..fef2e9d02c 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (c) 2021 The Bitcoin Core developers +# Copyright (c) 2021-present The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test for assumeutxo, a means of quickly bootstrapping a node using @@ -17,8 +17,7 @@ The assumeutxo value generated and used here is committed to in Interesting test cases could be loading an assumeutxo snapshot file with: -- TODO: An invalid hash -- TODO: Valid hash but invalid snapshot file (bad coin height or truncated file or +- TODO: Valid hash but invalid snapshot file (bad coin height or bad other serialization) - TODO: Valid snapshot file, but referencing an unknown block - TODO: Valid snapshot file, but referencing a snapshot block that turns out to be @@ -40,7 +39,6 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, ) -import struct START_HEIGHT = 199 SNAPSHOT_BASE_HEIGHT = 299 @@ -81,17 +79,25 @@ class AssumeutxoTest(BitcoinTestFramework): assert_raises_rpc_error(-32603, f"Unable to load UTXO snapshot, {error_details}", self.nodes[1].loadtxoutset, bad_snapshot_path) self.log.info(" - snapshot file with wrong number of coins") - valid_num_coins = struct.unpack("<I", valid_snapshot_contents[32:32 + 4])[0] + valid_num_coins = int.from_bytes(valid_snapshot_contents[32:32 + 8], "little") for off in [-1, +1]: with open(bad_snapshot_path, 'wb') as f: f.write(valid_snapshot_contents[:32]) - f.write(struct.pack("<I", valid_num_coins + off)) - f.write(valid_snapshot_contents[32 + 4:]) - + f.write((valid_num_coins + off).to_bytes(8, "little")) + f.write(valid_snapshot_contents[32 + 8:]) expected_log = 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" with self.nodes[1].assert_debug_log([expected_log]): assert_raises_rpc_error(-32603, "Unable to load UTXO snapshot", self.nodes[1].loadtxoutset, bad_snapshot_path) + self.log.info(" - snapshot file with wrong outpoint hash") + with open(bad_snapshot_path, "wb") as f: + f.write(valid_snapshot_contents[:(32 + 8)]) + f.write(b"\xff" * 32) + f.write(valid_snapshot_contents[(32 + 8 + 32):]) + expected_log = "[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got 29926acf3ac81f908cf4f22515713ca541c08bb0f0ef1b2c3443a007134d69b8" + with self.nodes[1].assert_debug_log([expected_log]): + assert_raises_rpc_error(-32603, "Unable to load UTXO snapshot", self.nodes[1].loadtxoutset, bad_snapshot_path) + def run_test(self): """ Bring up two (disconnected) nodes, mine some new blocks on the first, |