From fafde92f84fb7c245bc3c1cd946a32c891861e5e Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 12 Oct 2023 11:21:08 +0200 Subject: test: Check snapshot file with wrong number of coins Also, fix a bug in an assert_debug_log call. --- test/functional/feature_assumeutxo.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index ea93b7ab88..c900736ae9 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -40,7 +40,7 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, ) - +import struct START_HEIGHT = 199 SNAPSHOT_BASE_HEIGHT = 299 @@ -68,23 +68,35 @@ class AssumeutxoTest(BitcoinTestFramework): def test_invalid_snapshot_scenarios(self, valid_snapshot_path): self.log.info("Test different scenarios of loading invalid snapshot files") - self.log.info(" - snapshot file refering to a block that is not in the assumeutxo parameters") with open(valid_snapshot_path, 'rb') as f: valid_snapshot_contents = f.read() + bad_snapshot_path = valid_snapshot_path + '.mod' + self.log.info(" - snapshot file refering to a block that is not in the assumeutxo parameters") # we can only test this with a block that is already known, as otherwise the `loadtxoutset` RPC # would time out (waiting to see the hash in the headers chain), rather than error immediately bad_snapshot_height = SNAPSHOT_BASE_HEIGHT - 1 - bad_snapshot_path = valid_snapshot_path + '.mod' with open(bad_snapshot_path, 'wb') as f: bad_snapshot_block_hash = self.nodes[0].getblockhash(bad_snapshot_height) # block hash of the snapshot base is stored right at the start (first 32 bytes) f.write(bytes.fromhex(bad_snapshot_block_hash)[::-1] + valid_snapshot_contents[32:]) expected_log = f"assumeutxo height in snapshot metadata not recognized ({bad_snapshot_height}) - refusing to load snapshot" - 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) + self.log.info(" - snapshot file with wrong number of coins") + valid_num_coins = struct.unpack("