mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Merge bitcoin/bitcoin#28647: test: Add assumeutxo test for wrong hash
fa68571566
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: utACKfa68571566
theStack: Code-review re-ACKfa68571566
pablomartin4btc: re ACKfa68571566
ryanofsky: Code review ACKfa68571566
Tree-SHA512: 877653010efe4e20018827e8ec2801d036e1344457401f0c9e5d55907b817724201dd2e3f0f29505bbff619882c0c2cd731ecdcd209258bcefe11b86ff0205dd
This commit is contained in:
commit
ff6be778f9
1 changed files with 14 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/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
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test for assumeutxo, a means of quickly bootstrapping a node using
|
"""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:
|
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
|
||||||
- TODO: Valid hash but invalid snapshot file (bad coin height or truncated file or
|
|
||||||
bad other serialization)
|
bad other serialization)
|
||||||
- TODO: Valid snapshot file, but referencing an unknown block
|
- TODO: Valid snapshot file, but referencing an unknown block
|
||||||
- TODO: Valid snapshot file, but referencing a snapshot block that turns out to be
|
- 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_equal,
|
||||||
assert_raises_rpc_error,
|
assert_raises_rpc_error,
|
||||||
)
|
)
|
||||||
import struct
|
|
||||||
|
|
||||||
START_HEIGHT = 199
|
START_HEIGHT = 199
|
||||||
SNAPSHOT_BASE_HEIGHT = 299
|
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)
|
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")
|
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]:
|
for off in [-1, +1]:
|
||||||
with open(bad_snapshot_path, 'wb') as f:
|
with open(bad_snapshot_path, 'wb') as f:
|
||||||
f.write(valid_snapshot_contents[:32])
|
f.write(valid_snapshot_contents[:32])
|
||||||
f.write(struct.pack("<I", valid_num_coins + off))
|
f.write((valid_num_coins + off).to_bytes(8, "little"))
|
||||||
f.write(valid_snapshot_contents[32 + 4:])
|
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"
|
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]):
|
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)
|
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):
|
def run_test(self):
|
||||||
"""
|
"""
|
||||||
Bring up two (disconnected) nodes, mine some new blocks on the first,
|
Bring up two (disconnected) nodes, mine some new blocks on the first,
|
||||||
|
|
Loading…
Add table
Reference in a new issue