diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2020-11-19 09:30:13 -0500 |
---|---|---|
committer | James O'Beirne <james.obeirne@pm.me> | 2021-02-12 07:53:40 -0600 |
commit | 769a1ef9fdc9c372f5bbe91d1961cabd60bc1895 (patch) | |
tree | 324e7d1fa6011b18de611ec05934f14bd8eb4a5c /src/test/validation_chainstatemanager_tests.cpp | |
parent | 4d8de04f32736199e4b41a14a2d29b1a4d0a15d4 (diff) | |
download | bitcoin-769a1ef9fdc9c372f5bbe91d1961cabd60bc1895.tar.xz |
test: Add tests with maleated snapshot data
Diffstat (limited to 'src/test/validation_chainstatemanager_tests.cpp')
-rw-r--r-- | src/test/validation_chainstatemanager_tests.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 96b8e0ca2a..94d4277019 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -169,8 +169,11 @@ BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches) BOOST_CHECK_CLOSE(c2.m_coinsdb_cache_size_bytes, max_cache * 0.95, 1); } +auto NoMalleation = [](CAutoFile& file, SnapshotMetadata& meta){}; + +template<typename F = decltype(NoMalleation)> static bool -CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root) +CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root, F malleation = NoMalleation) { // Write out a snapshot to the test's tempdir. // @@ -191,6 +194,8 @@ CreateAndActivateUTXOSnapshot(NodeContext& node, const fs::path root) SnapshotMetadata metadata; auto_infile >> metadata; + malleation(auto_infile, metadata); + return node.chainman->ActivateSnapshot(auto_infile, metadata, /*in_memory*/ true); } @@ -232,6 +237,29 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Determi initial_size += 10; initial_total_coins += 10; + // Should not load malleated snapshots + BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( + m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + // A UTXO is missing but count is correct + metadata.m_coins_count -= 1; + + COutPoint outpoint; + Coin coin; + + auto_infile >> outpoint; + auto_infile >> coin; + })); + BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( + m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + // Coins count is larger than coins in file + metadata.m_coins_count += 1; + })); + BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( + m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + // Coins count is smaller than coins in file + metadata.m_coins_count -= 1; + })); + BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root)); // Ensure our active chain is the snapshot chainstate. |