Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_chainstate_tests.cpp
Show All 13 Lines | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, TestingSetup) | BOOST_FIXTURE_TEST_SUITE(validation_chainstate_tests, TestingSetup) | ||||
//! Test resizing coins-related CChainState caches during runtime. | //! Test resizing coins-related CChainState caches during runtime. | ||||
//! | //! | ||||
BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches) { | BOOST_AUTO_TEST_CASE(validation_chainstate_resize_caches) { | ||||
ChainstateManager manager; | ChainstateManager manager; | ||||
CTxMemPool mempool; | |||||
//! Create and add a Coin with DynamicMemoryUsage of 80 bytes to the given | //! Create and add a Coin with DynamicMemoryUsage of 80 bytes to the given | ||||
//! view. | //! view. | ||||
auto add_coin = [](CCoinsViewCache &coins_view) -> COutPoint { | auto add_coin = [](CCoinsViewCache &coins_view) -> COutPoint { | ||||
TxId txid{InsecureRand256()}; | TxId txid{InsecureRand256()}; | ||||
COutPoint outp{txid, 0}; | COutPoint outp{txid, 0}; | ||||
Amount nValue = static_cast<int64_t>(InsecureRand32()) * SATOSHI; | Amount nValue = static_cast<int64_t>(InsecureRand32()) * SATOSHI; | ||||
CScript scriptPubKey; | CScript scriptPubKey; | ||||
scriptPubKey.assign((uint32_t)56, 1); | scriptPubKey.assign((uint32_t)56, 1); | ||||
Coin newcoin(CTxOut(nValue, std::move(scriptPubKey)), 1, false); | Coin newcoin(CTxOut(nValue, std::move(scriptPubKey)), 1, false); | ||||
coins_view.AddCoin(outp, std::move(newcoin), false); | coins_view.AddCoin(outp, std::move(newcoin), false); | ||||
return outp; | return outp; | ||||
}; | }; | ||||
CChainState &c1 = | CChainState &c1 = | ||||
*WITH_LOCK(cs_main, return &manager.InitializeChainstate()); | *WITH_LOCK(cs_main, return &manager.InitializeChainstate(mempool)); | ||||
c1.InitCoinsDB( | c1.InitCoinsDB( | ||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, | /* cache_size_bytes */ 1 << 23, /* in_memory */ true, | ||||
/* should_wipe */ false); | /* should_wipe */ false); | ||||
WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23)); | WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23)); | ||||
// Add a coin to the in-memory cache, upsize once, then downsize. | // Add a coin to the in-memory cache, upsize once, then downsize. | ||||
{ | { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
Show All 28 Lines |