diff options
Diffstat (limited to 'test/functional/feature_assumeutxo.py')
-rwxr-xr-x | test/functional/feature_assumeutxo.py | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index 2d4e33e5d8..df2fdc9643 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -9,6 +9,7 @@ to a hash that has been compiled into bitcoind. The assumeutxo value generated and used here is committed to in `CRegTestParams::m_assumeutxo_data` in `src/kernel/chainparams.cpp`. """ +import contextlib from shutil import rmtree from dataclasses import dataclass @@ -16,11 +17,16 @@ from test_framework.blocktools import ( create_block, create_coinbase ) +from test_framework.compressor import ( + compress_amount, +) from test_framework.messages import ( CBlockHeader, from_hex, msg_headers, - tx_from_hex + tx_from_hex, + ser_varint, + MAX_MONEY, ) from test_framework.p2p import ( P2PInterface, @@ -139,7 +145,14 @@ class AssumeutxoTest(BitcoinTestFramework): [b"\x81", 34, "3da966ba9826fb6d2604260e01607b55ba44e1a5de298606b08704bc62570ea8", None], # wrong coin code VARINT [b"\x80", 34, "091e893b3ccb4334378709578025356c8bcb0a623f37c7c4e493133c988648e5", None], # another wrong coin code [b"\x84\x58", 34, None, "Bad snapshot data after deserializing 0 coins"], # wrong coin case with height 364 and coinbase 0 - [b"\xCA\xD2\x8F\x5A", 39, None, "Bad snapshot data after deserializing 0 coins - bad tx out value"], # Amount exceeds MAX_MONEY + [ + # compressed txout value + scriptpubkey + ser_varint(compress_amount(MAX_MONEY + 1)) + ser_varint(0), + # txid + coins per txid + vout + coin height + 32 + 1 + 1 + 2, + None, + "Bad snapshot data after deserializing 0 coins - bad tx out value" + ], # Amount exceeds MAX_MONEY ] for content, offset, wrong_hash, custom_message in cases: @@ -297,7 +310,7 @@ class AssumeutxoTest(BitcoinTestFramework): msg = msg_headers() for block_num in range(1, miner.getblockcount()+1): msg.headers.append(from_hex(CBlockHeader(), miner.getblockheader(miner.getblockhash(block_num), verbose=False))) - headers_provider_conn.send_message(msg) + headers_provider_conn.send_without_ping(msg) # Ensure headers arrived default_value = {'status': ''} # No status @@ -337,6 +350,22 @@ class AssumeutxoTest(BitcoinTestFramework): assert 'NETWORK' not in node_services assert 'NETWORK_LIMITED' in node_services + @contextlib.contextmanager + def assert_disk_cleanup(self, node, assumeutxo_used): + """ + Ensure an assumeutxo node is cleaning up the background chainstate + """ + msg = [] + if assumeutxo_used: + # Check that the snapshot actually existed before restart + assert (node.datadir_path / node.chain / "chainstate_snapshot").exists() + msg = ["cleaning up unneeded background chainstate"] + + with node.assert_debug_log(msg): + yield + + assert not (node.datadir_path / node.chain / "chainstate_snapshot").exists() + def run_test(self): """ Bring up two (disconnected) nodes, mine some new blocks on the first, @@ -644,7 +673,8 @@ class AssumeutxoTest(BitcoinTestFramework): for i in (0, 1): n = self.nodes[i] self.log.info(f"Restarting node {i} to ensure (Check|Load)BlockIndex passes") - self.restart_node(i, extra_args=self.extra_args[i]) + with self.assert_disk_cleanup(n, i == 1): + self.restart_node(i, extra_args=self.extra_args[i]) assert_equal(n.getblockchaininfo()["blocks"], FINAL_HEIGHT) @@ -721,7 +751,8 @@ class AssumeutxoTest(BitcoinTestFramework): for i in (0, 2): n = self.nodes[i] self.log.info(f"Restarting node {i} to ensure (Check|Load)BlockIndex passes") - self.restart_node(i, extra_args=self.extra_args[i]) + with self.assert_disk_cleanup(n, i == 2): + self.restart_node(i, extra_args=self.extra_args[i]) assert_equal(n.getblockchaininfo()["blocks"], FINAL_HEIGHT) |