Ensure snapshot loading fails for coins exceeding base height
Objective: This test verifies that snapshot loading is correctly rejected for coins with a height greater than the base height.
Update:
- Added
test_invalid_snapshot_wrong_coin_code
tofeature_assumeutxo.py
. - The test artificially sets a coin’s height above 299 in a snapshot and checks for load failure.
- Edit: Added a test case for outputs whose amounts surpass the MAX_MONEY supply limit.
This implementation addresses the request for enhancing assumeutxo
testing as outlined in issue #28648
Edit: This is an explanation on how I arrive at content values: b"\x84\x58" and b"\xCA\xD2\x8F\x5A"
You can use this tool to decode the utxo snapshot https://github.com/jrakibi/utxo-live Hereโs an overview of how itโs done: The serialization format for a UTXO in the snapshot is as follows:
- Transaction ID (txid) - 32 bytes
- Output Index (outnum)- 4 bytes
- VARINT (code) - A varible-length integer encoding the height and whether the transaction is a coinbase. The format of this VARINT is (height « 1) | coinbase_flag.
- VARINT (amount_v) - A variable-length integer that represents a compressed format of the output amount (in satoshis).
For the test cases mentioned:
b"\x84\x58"
- This value corresponds to a VARINT representing the height and coinbase flag. Once we decode this code, we can extract the height and coinbase usingheight = code_decoded >> 1
andcoinbase = code_decoded & 0x01
. In our case, with code_decoded = 728, it results inheight = 364
andcoinbase = 0
.b"\xCA\xD2\x8F\x5A"
- This byte sequence represents a compressed amount value. The decompression function takes this value and translates it into a full amount in satoshis. In our case, the decompression of this amount translates to a number larger than the maximum allowed value of coins (21 million BTC)