mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
test: Add tests with maleated snapshot data
This commit is contained in:
parent
4d8de04f32
commit
769a1ef9fd
1 changed files with 29 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue