14#include <boost/test/unit_test.hpp>
20BOOST_AUTO_TEST_SUITE(coinsviewoverlay_tests)
24CBlock CreateBlock() noexcept
26 static constexpr auto NUM_TXS{100};
29 coinbase.
vin.emplace_back();
32 for (
const auto i : std::views::iota(1, NUM_TXS)) {
35 tx.
vin.emplace_back(txid, 0);
47 for (
const auto& tx : block.
vtx | std::views::drop(1)) {
48 for (
const auto& in : tx->
vin) {
51 cache.EmplaceCoinInternalDANGER(
COutPoint{in.prevout}, std::move(coin));
62 for (
const auto& tx : block.
vtx) {
63 if (tx->IsCoinBase()) {
66 for (
const auto& in : tx->
vin) {
67 const auto& outpoint{in.prevout};
69 const auto& second{cache.
AccessCoin(outpoint)};
83 const auto block{CreateBlock()};
84 CCoinsViewDB db{{.path =
"", .cache_bytes = 1_MiB, .memory_only =
true}, {}};
85 PopulateView(block, db);
88 const auto& outpoint{block.
vtx[1]->vin[0].prevout};
94 CheckCache(block, view);
96 for (
const auto& tx : block.
vtx) {
97 for (
const auto& in : tx->
vin) {
98 BOOST_CHECK(!main_cache.HaveCoinInCache(in.prevout));
105 BOOST_CHECK(!main_cache.PeekCoin(outpoint).has_value());
110 const auto block{CreateBlock()};
111 CCoinsViewDB db{{.path =
"", .cache_bytes = 1_MiB, .memory_only =
true}, {}};
113 PopulateView(block, main_cache);
115 CheckCache(block, view);
117 const auto& outpoint{block.
vtx[1]->vin[0].prevout};
121 BOOST_CHECK(!main_cache.PeekCoin(outpoint).has_value());
128 const auto block{CreateBlock()};
129 CCoinsViewDB db{{.path =
"", .cache_bytes = 1_MiB, .memory_only =
true}, {}};
130 PopulateView(block, db);
133 PopulateView(block, main_cache,
true);
135 for (
const auto& tx : block.
vtx) {
136 for (
const auto& in : tx->
vin) {
137 const auto& c{view.AccessCoin(in.prevout)};
149 const auto block{CreateBlock()};
150 CCoinsViewDB db{{.path =
"", .cache_bytes = 1_MiB, .memory_only =
true}, {}};
153 for (
const auto& tx : block.
vtx) {
154 for (
const auto& in : tx->
vin) {
155 const auto& c{view.AccessCoin(in.prevout)};
std::vector< CTransactionRef > vtx
CCoinsView that adds a memory cache for transactions to another CCoinsView.
unsigned int GetCacheSize() const
Size of the cache (in number of transaction outputs)
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
CCoinsView backed by the coin database (chainstate/)
Abstract view on the open txout dataset.
virtual std::optional< Coin > GetCoin(const COutPoint &outpoint) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
An outpoint - a combination of a transaction hash and an index n into its vout.
CTxOut out
unspent transaction output
CCoinsViewCache overlay that avoids populating/mutating parent cache layers on cache misses.
static transaction_identifier FromUint256(const uint256 &id)
BOOST_AUTO_TEST_CASE(fetch_inputs_from_db)
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
A mutable version of CTransaction.