mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
Merge bitcoin/bitcoin#28666: test: assumeutxo file with unknown block hash
621db2f004
test: assumeutxo file with unknown block hash (Fabian Jahr) Pull request description: Takes care of one of the open Todos in the assumeutxo functional test. Since an unknown block could be any hash, I simply chose one placeholder, it could also be a random string though. ACKs for top commit: maflcko: lgtm ACK621db2f004
pablomartin4btc: cr ACK621db2f004
theStack: ACK621db2f004
ryanofsky: Code review ACK621db2f004
Tree-SHA512: ee0438ce619f7348c6f88e39b0ea7ddddb8832956d9034ecc795c6033d5d905c09d11b7d0d5afc38231b2fd091ea7c1bd0a0be99d9c32c4e6357a25d76294142
This commit is contained in:
commit
655dc716aa
1 changed files with 8 additions and 7 deletions
|
@ -19,7 +19,6 @@ Interesting test cases could be loading an assumeutxo snapshot file with:
|
||||||
|
|
||||||
- TODO: Valid hash but invalid snapshot file (bad coin height or
|
- TODO: Valid hash but invalid snapshot file (bad coin height or
|
||||||
bad other serialization)
|
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
|
- TODO: Valid snapshot file, but referencing a snapshot block that turns out to be
|
||||||
invalid, or has an invalid parent
|
invalid, or has an invalid parent
|
||||||
- TODO: Valid snapshot file and snapshot block, but the block is not on the
|
- TODO: Valid snapshot file and snapshot block, but the block is not on the
|
||||||
|
@ -71,12 +70,14 @@ class AssumeutxoTest(BitcoinTestFramework):
|
||||||
bad_snapshot_path = valid_snapshot_path + '.mod'
|
bad_snapshot_path = valid_snapshot_path + '.mod'
|
||||||
|
|
||||||
self.log.info(" - snapshot file refering to a block that is not in the assumeutxo parameters")
|
self.log.info(" - snapshot file refering to a block that is not in the assumeutxo parameters")
|
||||||
bad_snapshot_block_hash = self.nodes[0].getblockhash(SNAPSHOT_BASE_HEIGHT - 1)
|
prev_block_hash = self.nodes[0].getblockhash(SNAPSHOT_BASE_HEIGHT - 1)
|
||||||
with open(bad_snapshot_path, 'wb') as f:
|
bogus_block_hash = "0" * 64 # Represents any unknown block hash
|
||||||
# block hash of the snapshot base is stored right at the start (first 32 bytes)
|
for bad_block_hash in [bogus_block_hash, prev_block_hash]:
|
||||||
f.write(bytes.fromhex(bad_snapshot_block_hash)[::-1] + valid_snapshot_contents[32:])
|
with open(bad_snapshot_path, 'wb') as f:
|
||||||
error_details = f"assumeutxo block hash in snapshot metadata not recognized ({bad_snapshot_block_hash})"
|
# block hash of the snapshot base is stored right at the start (first 32 bytes)
|
||||||
assert_raises_rpc_error(-32603, f"Unable to load UTXO snapshot, {error_details}", self.nodes[1].loadtxoutset, bad_snapshot_path)
|
f.write(bytes.fromhex(bad_block_hash)[::-1] + valid_snapshot_contents[32:])
|
||||||
|
error_details = f"assumeutxo block hash in snapshot metadata not recognized ({bad_block_hash})"
|
||||||
|
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 = int.from_bytes(valid_snapshot_contents[32:32 + 8], "little")
|
valid_num_coins = int.from_bytes(valid_snapshot_contents[32:32 + 8], "little")
|
||||||
|
|
Loading…
Add table
Reference in a new issue