Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
coins_tests.cpp File Reference
#include <addresstype.h>
#include <clientversion.h>
#include <coins.h>
#include <streams.h>
#include <test/util/common.h>
#include <test/util/poolresourcetester.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <txdb.h>
#include <uint256.h>
#include <undo.h>
#include <util/strencodings.h>
#include <map>
#include <string>
#include <variant>
#include <vector>
#include <boost/test/unit_test.hpp>
Include dependency graph for coins_tests.cpp:

Go to the source code of this file.

Classes

struct  CacheTest
struct  UpdateTest
struct  CoinEntry
class  SingleEntryCacheTest
struct  FlushTest

Typedefs

using MaybeCoin = std::optional<CoinEntry>
using CoinOrError = std::variant<MaybeCoin, std::string>

Functions

int ApplyTxInUndo (Coin &&undo, CCoinsViewCache &view, const COutPoint &out)
 Restore the UTXO in a Coin at a given COutPoint.
void UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
 BOOST_FIXTURE_TEST_CASE (coins_cache_base_simulation_test, CacheTest)
 BOOST_FIXTURE_TEST_CASE (coins_cache_dbbase_simulation_test, CacheTest)
 BOOST_FIXTURE_TEST_CASE (updatecoins_simulation_test, UpdateTest)
 BOOST_AUTO_TEST_CASE (ccoins_serialization)
static void SetCoinsValue (const CAmount value, Coin &coin)
static size_t InsertCoinsMapEntry (CCoinsMap &map, CoinsCachePair &sentinel, const CoinEntry &cache_coin)
static MaybeCoin GetCoinsMapEntry (const CCoinsMap &map, const COutPoint &outp=OUTPOINT)
static void WriteCoinsViewEntry (CCoinsView &view, const MaybeCoin &cache_coin)
static void CheckAccessCoin (const CAmount base_value, const MaybeCoin &cache_coin, const MaybeCoin &expected)
 BOOST_AUTO_TEST_CASE (ccoins_access)
static void CheckSpendCoins (const CAmount base_value, const MaybeCoin &cache_coin, const MaybeCoin &expected)
 BOOST_AUTO_TEST_CASE (ccoins_spend)
static void CheckAddCoin (const CAmount base_value, const MaybeCoin &cache_coin, const CAmount modify_value, const CoinOrError &expected, const bool coinbase)
 BOOST_AUTO_TEST_CASE (ccoins_add)
static void CheckWriteCoins (const MaybeCoin &parent, const MaybeCoin &child, const CoinOrError &expected)
 BOOST_AUTO_TEST_CASE (ccoins_write)
 BOOST_FIXTURE_TEST_CASE (ccoins_flush_behavior, FlushTest)
 BOOST_AUTO_TEST_CASE (coins_resource_is_used)
 BOOST_AUTO_TEST_CASE (ccoins_addcoin_exception_keeps_usage_balanced)
 BOOST_AUTO_TEST_CASE (ccoins_emplace_duplicate_keeps_usage_balanced)
 BOOST_AUTO_TEST_CASE (ccoins_reset_guard)
 BOOST_AUTO_TEST_CASE (ccoins_peekcoin)

Variables

static const unsigned int NUM_SIMULATION_ITERATIONS = 40000
static const COutPoint OUTPOINT
constexpr CAmount SPENT {-1}
constexpr CAmount ABSENT {-2}
constexpr CAmount VALUE1 {100}
constexpr CAmount VALUE2 {200}
constexpr CAmount VALUE3 {300}
constexpr MaybeCoin MISSING {std::nullopt}
constexpr MaybeCoin SPENT_DIRTY {{SPENT, CoinEntry::State::DIRTY}}
constexpr MaybeCoin SPENT_DIRTY_FRESH {{SPENT, CoinEntry::State::DIRTY_FRESH}}
constexpr MaybeCoin SPENT_FRESH {{SPENT, CoinEntry::State::FRESH}}
constexpr MaybeCoin SPENT_CLEAN {{SPENT, CoinEntry::State::CLEAN}}
constexpr MaybeCoin VALUE1_DIRTY {{VALUE1, CoinEntry::State::DIRTY}}
constexpr MaybeCoin VALUE1_DIRTY_FRESH {{VALUE1, CoinEntry::State::DIRTY_FRESH}}
constexpr MaybeCoin VALUE1_FRESH {{VALUE1, CoinEntry::State::FRESH}}
constexpr MaybeCoin VALUE1_CLEAN {{VALUE1, CoinEntry::State::CLEAN}}
constexpr MaybeCoin VALUE2_DIRTY {{VALUE2, CoinEntry::State::DIRTY}}
constexpr MaybeCoin VALUE2_DIRTY_FRESH {{VALUE2, CoinEntry::State::DIRTY_FRESH}}
constexpr MaybeCoin VALUE2_FRESH {{VALUE2, CoinEntry::State::FRESH}}
constexpr MaybeCoin VALUE2_CLEAN {{VALUE2, CoinEntry::State::CLEAN}}
constexpr MaybeCoin VALUE3_DIRTY {{VALUE3, CoinEntry::State::DIRTY}}
constexpr MaybeCoin VALUE3_DIRTY_FRESH {{VALUE3, CoinEntry::State::DIRTY_FRESH}}
constexpr auto EX_OVERWRITE_UNSPENT {"Attempted to overwrite an unspent coin (when possible_overwrite is false)"}
constexpr auto EX_FRESH_MISAPPLIED {"FRESH flag misapplied to coin that exists in parent cache"}

Typedef Documentation

◆ CoinOrError

using CoinOrError = std::variant<MaybeCoin, std::string>

Definition at line 600 of file coins_tests.cpp.

◆ MaybeCoin

using MaybeCoin = std::optional<CoinEntry>

Definition at line 599 of file coins_tests.cpp.

Function Documentation

◆ ApplyTxInUndo()

int ApplyTxInUndo ( Coin && undo,
CCoinsViewCache & view,
const COutPoint & out )

Restore the UTXO in a Coin at a given COutPoint.

Parameters
undoThe Coin to be restored.
viewThe coins view to which to apply the changes.
outThe out point that corresponds to the tx input.
Returns
A DisconnectResult as an int

Definition at line 2146 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BOOST_AUTO_TEST_CASE() [1/10]

BOOST_AUTO_TEST_CASE ( ccoins_access )

Definition at line 694 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/10]

BOOST_AUTO_TEST_CASE ( ccoins_add )

Definition at line 760 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/10]

BOOST_AUTO_TEST_CASE ( ccoins_addcoin_exception_keeps_usage_balanced )

Definition at line 1088 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/10]

BOOST_AUTO_TEST_CASE ( ccoins_emplace_duplicate_keeps_usage_balanced )

Definition at line 1106 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/10]

BOOST_AUTO_TEST_CASE ( ccoins_peekcoin )

Definition at line 1175 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/10]

BOOST_AUTO_TEST_CASE ( ccoins_reset_guard )

Definition at line 1124 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/10]

BOOST_AUTO_TEST_CASE ( ccoins_serialization )

Definition at line 522 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/10]

BOOST_AUTO_TEST_CASE ( ccoins_spend )

Definition at line 724 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/10]

BOOST_AUTO_TEST_CASE ( ccoins_write )

Definition at line 805 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/10]

BOOST_AUTO_TEST_CASE ( coins_resource_is_used )

Definition at line 1063 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [1/4]

BOOST_FIXTURE_TEST_CASE ( ccoins_flush_behavior ,
FlushTest  )

Definition at line 1049 of file coins_tests.cpp.

◆ BOOST_FIXTURE_TEST_CASE() [2/4]

BOOST_FIXTURE_TEST_CASE ( coins_cache_base_simulation_test ,
CacheTest  )

Definition at line 287 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [3/4]

BOOST_FIXTURE_TEST_CASE ( coins_cache_dbbase_simulation_test ,
CacheTest  )

Definition at line 297 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [4/4]

BOOST_FIXTURE_TEST_CASE ( updatecoins_simulation_test ,
UpdateTest  )

Definition at line 330 of file coins_tests.cpp.

Here is the call graph for this function:

◆ CheckAccessCoin()

void CheckAccessCoin ( const CAmount base_value,
const MaybeCoin & cache_coin,
const MaybeCoin & expected )
static

Definition at line 685 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckAddCoin()

void CheckAddCoin ( const CAmount base_value,
const MaybeCoin & cache_coin,
const CAmount modify_value,
const CoinOrError & expected,
const bool coinbase )
static

Definition at line 746 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckSpendCoins()

void CheckSpendCoins ( const CAmount base_value,
const MaybeCoin & cache_coin,
const MaybeCoin & expected )
static

Definition at line 716 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckWriteCoins()

void CheckWriteCoins ( const MaybeCoin & parent,
const MaybeCoin & child,
const CoinOrError & expected )
static

Definition at line 792 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCoinsMapEntry()

MaybeCoin GetCoinsMapEntry ( const CCoinsMap & map,
const COutPoint & outp = OUTPOINT )
static

Definition at line 644 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InsertCoinsMapEntry()

size_t InsertCoinsMapEntry ( CCoinsMap & map,
CoinsCachePair & sentinel,
const CoinEntry & cache_coin )
static

Definition at line 633 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCoinsValue()

void SetCoinsValue ( const CAmount value,
Coin & coin )
static

Definition at line 621 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateCoins()

void UpdateCoins ( const CTransaction & tx,
CCoinsViewCache & inputs,
CTxUndo & txundo,
int nHeight )

Definition at line 1996 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteCoinsViewEntry()

void WriteCoinsViewEntry ( CCoinsView & view,
const MaybeCoin & cache_coin )
static

Definition at line 654 of file coins_tests.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ABSENT

CAmount ABSENT {-2}
constexpr

Definition at line 571 of file coins_tests.cpp.

◆ EX_FRESH_MISAPPLIED

auto EX_FRESH_MISAPPLIED {"FRESH flag misapplied to coin that exists in parent cache"}
constexpr

Definition at line 619 of file coins_tests.cpp.

◆ EX_OVERWRITE_UNSPENT

auto EX_OVERWRITE_UNSPENT {"Attempted to overwrite an unspent coin (when possible_overwrite is false)"}
constexpr

Definition at line 618 of file coins_tests.cpp.

◆ MISSING

MaybeCoin MISSING {std::nullopt}
constexpr

Definition at line 602 of file coins_tests.cpp.

◆ NUM_SIMULATION_ITERATIONS

const unsigned int NUM_SIMULATION_ITERATIONS = 40000
static

Definition at line 104 of file coins_tests.cpp.

◆ OUTPOINT

const COutPoint OUTPOINT
static

Definition at line 569 of file coins_tests.cpp.

◆ SPENT

CAmount SPENT {-1}
constexpr

Definition at line 570 of file coins_tests.cpp.

◆ SPENT_CLEAN

MaybeCoin SPENT_CLEAN {{SPENT, CoinEntry::State::CLEAN}}
constexpr

Definition at line 606 of file coins_tests.cpp.

◆ SPENT_DIRTY

MaybeCoin SPENT_DIRTY {{SPENT, CoinEntry::State::DIRTY}}
constexpr

Definition at line 603 of file coins_tests.cpp.

◆ SPENT_DIRTY_FRESH

MaybeCoin SPENT_DIRTY_FRESH {{SPENT, CoinEntry::State::DIRTY_FRESH}}
constexpr

Definition at line 604 of file coins_tests.cpp.

◆ SPENT_FRESH

MaybeCoin SPENT_FRESH {{SPENT, CoinEntry::State::FRESH}}
constexpr

Definition at line 605 of file coins_tests.cpp.

◆ VALUE1

CAmount VALUE1 {100}
constexpr

Definition at line 572 of file coins_tests.cpp.

◆ VALUE1_CLEAN

MaybeCoin VALUE1_CLEAN {{VALUE1, CoinEntry::State::CLEAN}}
constexpr

Definition at line 610 of file coins_tests.cpp.

◆ VALUE1_DIRTY

MaybeCoin VALUE1_DIRTY {{VALUE1, CoinEntry::State::DIRTY}}
constexpr

Definition at line 607 of file coins_tests.cpp.

◆ VALUE1_DIRTY_FRESH

MaybeCoin VALUE1_DIRTY_FRESH {{VALUE1, CoinEntry::State::DIRTY_FRESH}}
constexpr

Definition at line 608 of file coins_tests.cpp.

◆ VALUE1_FRESH

MaybeCoin VALUE1_FRESH {{VALUE1, CoinEntry::State::FRESH}}
constexpr

Definition at line 609 of file coins_tests.cpp.

◆ VALUE2

CAmount VALUE2 {200}
constexpr

Definition at line 573 of file coins_tests.cpp.

◆ VALUE2_CLEAN

MaybeCoin VALUE2_CLEAN {{VALUE2, CoinEntry::State::CLEAN}}
constexpr

Definition at line 614 of file coins_tests.cpp.

◆ VALUE2_DIRTY

MaybeCoin VALUE2_DIRTY {{VALUE2, CoinEntry::State::DIRTY}}
constexpr

Definition at line 611 of file coins_tests.cpp.

◆ VALUE2_DIRTY_FRESH

MaybeCoin VALUE2_DIRTY_FRESH {{VALUE2, CoinEntry::State::DIRTY_FRESH}}
constexpr

Definition at line 612 of file coins_tests.cpp.

◆ VALUE2_FRESH

MaybeCoin VALUE2_FRESH {{VALUE2, CoinEntry::State::FRESH}}
constexpr

Definition at line 613 of file coins_tests.cpp.

◆ VALUE3

CAmount VALUE3 {300}
constexpr

Definition at line 574 of file coins_tests.cpp.

◆ VALUE3_DIRTY

MaybeCoin VALUE3_DIRTY {{VALUE3, CoinEntry::State::DIRTY}}
constexpr

Definition at line 615 of file coins_tests.cpp.

◆ VALUE3_DIRTY_FRESH

MaybeCoin VALUE3_DIRTY_FRESH {{VALUE3, CoinEntry::State::DIRTY_FRESH}}
constexpr

Definition at line 616 of file coins_tests.cpp.