Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Typedefs | Functions | Variables
coins_tests.cpp File Reference
#include <addresstype.h>
#include <clientversion.h>
#include <coins.h>
#include <streams.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. More...
 
void UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
 
 BOOST_FIXTURE_TEST_CASE (coins_cache_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)
 

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 594 of file coins_tests.cpp.

◆ MaybeCoin

using MaybeCoin = std::optional<CoinEntry>

Definition at line 593 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 2266 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/6]

BOOST_AUTO_TEST_CASE ( ccoins_access  )

Definition at line 683 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( ccoins_add  )

Definition at line 749 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( ccoins_serialization  )

Definition at line 511 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( ccoins_spend  )

Definition at line 713 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( ccoins_write  )

Definition at line 794 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( coins_resource_is_used  )

Definition at line 1052 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [1/3]

BOOST_FIXTURE_TEST_CASE ( ccoins_flush_behavior  ,
FlushTest   
)

Definition at line 1038 of file coins_tests.cpp.

◆ BOOST_FIXTURE_TEST_CASE() [2/3]

BOOST_FIXTURE_TEST_CASE ( coins_cache_simulation_test  ,
CacheTest   
)

Definition at line 287 of file coins_tests.cpp.

◆ BOOST_FIXTURE_TEST_CASE() [3/3]

BOOST_FIXTURE_TEST_CASE ( updatecoins_simulation_test  ,
UpdateTest   
)

Definition at line 319 of file coins_tests.cpp.

Here is the call graph for this function:

◆ CheckAccessCoin()

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

Definition at line 674 of file coins_tests.cpp.

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

◆ CheckAddCoin()

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

Definition at line 735 of file coins_tests.cpp.

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

◆ CheckSpendCoins()

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

Definition at line 705 of file coins_tests.cpp.

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

◆ CheckWriteCoins()

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

Definition at line 781 of file coins_tests.cpp.

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

◆ GetCoinsMapEntry()

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

Definition at line 638 of file coins_tests.cpp.

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

◆ InsertCoinsMapEntry()

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

Definition at line 627 of file coins_tests.cpp.

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

◆ SetCoinsValue()

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

Definition at line 615 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 2099 of file validation.cpp.

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

◆ WriteCoinsViewEntry()

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

Definition at line 648 of file coins_tests.cpp.

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

Variable Documentation

◆ ABSENT

constexpr CAmount ABSENT {-2}
constexpr

Definition at line 565 of file coins_tests.cpp.

◆ EX_FRESH_MISAPPLIED

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

Definition at line 613 of file coins_tests.cpp.

◆ EX_OVERWRITE_UNSPENT

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

Definition at line 612 of file coins_tests.cpp.

◆ MISSING

constexpr MaybeCoin MISSING {std::nullopt}
constexpr

Definition at line 596 of file coins_tests.cpp.

◆ NUM_SIMULATION_ITERATIONS

const unsigned int NUM_SIMULATION_ITERATIONS = 40000
static

Definition at line 109 of file coins_tests.cpp.

◆ OUTPOINT

const COutPoint OUTPOINT
static

Definition at line 563 of file coins_tests.cpp.

◆ SPENT

constexpr CAmount SPENT {-1}
constexpr

Definition at line 564 of file coins_tests.cpp.

◆ SPENT_CLEAN

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

Definition at line 600 of file coins_tests.cpp.

◆ SPENT_DIRTY

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

Definition at line 597 of file coins_tests.cpp.

◆ SPENT_DIRTY_FRESH

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

Definition at line 598 of file coins_tests.cpp.

◆ SPENT_FRESH

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

Definition at line 599 of file coins_tests.cpp.

◆ VALUE1

constexpr CAmount VALUE1 {100}
constexpr

Definition at line 566 of file coins_tests.cpp.

◆ VALUE1_CLEAN

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

Definition at line 604 of file coins_tests.cpp.

◆ VALUE1_DIRTY

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

Definition at line 601 of file coins_tests.cpp.

◆ VALUE1_DIRTY_FRESH

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

Definition at line 602 of file coins_tests.cpp.

◆ VALUE1_FRESH

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

Definition at line 603 of file coins_tests.cpp.

◆ VALUE2

constexpr CAmount VALUE2 {200}
constexpr

Definition at line 567 of file coins_tests.cpp.

◆ VALUE2_CLEAN

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

Definition at line 608 of file coins_tests.cpp.

◆ VALUE2_DIRTY

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

Definition at line 605 of file coins_tests.cpp.

◆ VALUE2_DIRTY_FRESH

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

Definition at line 606 of file coins_tests.cpp.

◆ VALUE2_FRESH

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

Definition at line 607 of file coins_tests.cpp.

◆ VALUE3

constexpr CAmount VALUE3 {300}
constexpr

Definition at line 568 of file coins_tests.cpp.

◆ VALUE3_DIRTY

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

Definition at line 609 of file coins_tests.cpp.

◆ VALUE3_DIRTY_FRESH

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

Definition at line 610 of file coins_tests.cpp.