Bitcoin Core  27.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 <vector>
#include <boost/test/unit_test.hpp>
Include dependency graph for coins_tests.cpp:

Go to the source code of this file.

Classes

class  SingleEntryCacheTest
 

Typedefs

typedef std::map< COutPoint, std::tuple< CTransaction, CTxUndo, Coin > > UtxoData
 

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)
 
void SimulationTest (CCoinsView *base, bool fake_best_block)
 
 BOOST_AUTO_TEST_CASE (coins_cache_simulation_test)
 
UtxoData::iterator FindRandomFrom (const std::set< COutPoint > &utxoSet)
 
 BOOST_AUTO_TEST_CASE (updatecoins_simulation_test)
 
 BOOST_AUTO_TEST_CASE (ccoins_serialization)
 
static void SetCoinsValue (CAmount value, Coin &coin)
 
static size_t InsertCoinsMapEntry (CCoinsMap &map, CAmount value, char flags)
 
void GetCoinsMapEntry (const CCoinsMap &map, CAmount &value, char &flags, const COutPoint &outp=OUTPOINT)
 
void WriteCoinsViewEntry (CCoinsView &view, CAmount value, char flags)
 
static void CheckAccessCoin (CAmount base_value, CAmount cache_value, CAmount expected_value, char cache_flags, char expected_flags)
 
 BOOST_AUTO_TEST_CASE (ccoins_access)
 
static void CheckSpendCoins (CAmount base_value, CAmount cache_value, CAmount expected_value, char cache_flags, char expected_flags)
 
 BOOST_AUTO_TEST_CASE (ccoins_spend)
 
static void CheckAddCoinBase (CAmount base_value, CAmount cache_value, CAmount modify_value, CAmount expected_value, char cache_flags, char expected_flags, bool coinbase)
 
template<typename... Args>
static void CheckAddCoin (Args &&... args)
 
 BOOST_AUTO_TEST_CASE (ccoins_add)
 
void CheckWriteCoins (CAmount parent_value, CAmount child_value, CAmount expected_value, char parent_flags, char child_flags, char expected_flags)
 
 BOOST_AUTO_TEST_CASE (ccoins_write)
 
Coin MakeCoin ()
 
void TestFlushBehavior (CCoinsViewCacheTest *view, CCoinsViewDB &base, std::vector< std::unique_ptr< CCoinsViewCacheTest >> &all_caches, bool do_erasing_flush)
 For CCoinsViewCache instances backed by either another cache instance or leveldb, test cache behavior and flag state (DIRTY/FRESH) by. More...
 
 BOOST_AUTO_TEST_CASE (ccoins_flush_behavior)
 
 BOOST_AUTO_TEST_CASE (coins_resource_is_used)
 

Variables

static const unsigned int NUM_SIMULATION_ITERATIONS = 40000
 
UtxoData utxoData
 
static const COutPoint OUTPOINT
 
static const CAmount SPENT = -1
 
static const CAmount ABSENT = -2
 
static const CAmount FAIL = -3
 
static const CAmount VALUE1 = 100
 
static const CAmount VALUE2 = 200
 
static const CAmount VALUE3 = 300
 
static const char DIRTY = CCoinsCacheEntry::DIRTY
 
static const char FRESH = CCoinsCacheEntry::FRESH
 
static const char NO_ENTRY = -1
 
static const auto FLAGS = {char(0), FRESH, DIRTY, char(DIRTY | FRESH)}
 
static const auto CLEAN_FLAGS = {char(0), FRESH}
 
static const auto ABSENT_FLAGS = {NO_ENTRY}
 

Typedef Documentation

◆ UtxoData

typedef std::map<COutPoint, std::tuple<CTransaction,CTxUndo,Coin> > UtxoData

Definition at line 288 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 2069 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/9]

BOOST_AUTO_TEST_CASE ( ccoins_access  )

Definition at line 649 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/9]

BOOST_AUTO_TEST_CASE ( ccoins_add  )

Definition at line 771 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/9]

BOOST_AUTO_TEST_CASE ( ccoins_flush_behavior  )

Definition at line 1073 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/9]

BOOST_AUTO_TEST_CASE ( ccoins_serialization  )

Definition at line 503 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/9]

BOOST_AUTO_TEST_CASE ( ccoins_spend  )

Definition at line 700 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/9]

BOOST_AUTO_TEST_CASE ( ccoins_write  )

Definition at line 820 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/9]

BOOST_AUTO_TEST_CASE ( coins_cache_simulation_test  )

Definition at line 278 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/9]

BOOST_AUTO_TEST_CASE ( coins_resource_is_used  )

Definition at line 1087 of file coins_tests.cpp.

Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/9]

BOOST_AUTO_TEST_CASE ( updatecoins_simulation_test  )

Definition at line 308 of file coins_tests.cpp.

Here is the call graph for this function:

◆ CheckAccessCoin()

static void CheckAccessCoin ( CAmount  base_value,
CAmount  cache_value,
CAmount  expected_value,
char  cache_flags,
char  expected_flags 
)
static

Definition at line 636 of file coins_tests.cpp.

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

◆ CheckAddCoin()

template<typename... Args>
static void CheckAddCoin ( Args &&...  args)
static

Definition at line 765 of file coins_tests.cpp.

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

◆ CheckAddCoinBase()

static void CheckAddCoinBase ( CAmount  base_value,
CAmount  cache_value,
CAmount  modify_value,
CAmount  expected_value,
char  cache_flags,
char  expected_flags,
bool  coinbase 
)
static

Definition at line 738 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 ( CAmount  base_value,
CAmount  cache_value,
CAmount  expected_value,
char  cache_flags,
char  expected_flags 
)
static

Definition at line 687 of file coins_tests.cpp.

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

◆ CheckWriteCoins()

void CheckWriteCoins ( CAmount  parent_value,
CAmount  child_value,
CAmount  expected_value,
char  parent_flags,
char  child_flags,
char  expected_flags 
)

Definition at line 801 of file coins_tests.cpp.

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

◆ FindRandomFrom()

UtxoData::iterator FindRandomFrom ( const std::set< COutPoint > &  utxoSet)

Definition at line 291 of file coins_tests.cpp.

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

◆ GetCoinsMapEntry()

void GetCoinsMapEntry ( const CCoinsMap map,
CAmount value,
char &  flags,
const COutPoint outp = OUTPOINT 
)

Definition at line 597 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,
CAmount  value,
char  flags 
)
static

Definition at line 582 of file coins_tests.cpp.

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

◆ MakeCoin()

Coin MakeCoin ( )

Definition at line 887 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 ( CAmount  value,
Coin coin 
)
static

Definition at line 570 of file coins_tests.cpp.

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

◆ SimulationTest()

void SimulationTest ( CCoinsView base,
bool  fake_best_block 
)

Definition at line 118 of file coins_tests.cpp.

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

◆ TestFlushBehavior()

void TestFlushBehavior ( CCoinsViewCacheTest *  view,
CCoinsViewDB base,
std::vector< std::unique_ptr< CCoinsViewCacheTest >> &  all_caches,
bool  do_erasing_flush 
)

For CCoinsViewCache instances backed by either another cache instance or leveldb, test cache behavior and flag state (DIRTY/FRESH) by.

  1. Adding a random coin to the child-most cache,
  2. Flushing all caches (without erasing),
  3. Ensure the entry still exists in the cache and has been written to parent,
  4. (if do_erasing_flush) Flushing the caches again (with erasing),
  5. (if do_erasing_flush) Ensure the entry has been written to the parent and is no longer in the cache,
  6. Spend the coin, ensure it no longer exists in the parent.

Definition at line 907 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 1907 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,
CAmount  value,
char  flags 
)

Definition at line 614 of file coins_tests.cpp.

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

Variable Documentation

◆ ABSENT

const CAmount ABSENT = -2
static

Definition at line 557 of file coins_tests.cpp.

◆ ABSENT_FLAGS

const auto ABSENT_FLAGS = {NO_ENTRY}
static

Definition at line 568 of file coins_tests.cpp.

◆ CLEAN_FLAGS

const auto CLEAN_FLAGS = {char(0), FRESH}
static

Definition at line 567 of file coins_tests.cpp.

◆ DIRTY

const char DIRTY = CCoinsCacheEntry::DIRTY
static

Definition at line 562 of file coins_tests.cpp.

◆ FAIL

const CAmount FAIL = -3
static

Definition at line 558 of file coins_tests.cpp.

◆ FLAGS

const auto FLAGS = {char(0), FRESH, DIRTY, char(DIRTY | FRESH)}
static

Definition at line 566 of file coins_tests.cpp.

◆ FRESH

const char FRESH = CCoinsCacheEntry::FRESH
static

Definition at line 563 of file coins_tests.cpp.

◆ NO_ENTRY

const char NO_ENTRY = -1
static

Definition at line 564 of file coins_tests.cpp.

◆ NUM_SIMULATION_ITERATIONS

const unsigned int NUM_SIMULATION_ITERATIONS = 40000
static

Definition at line 102 of file coins_tests.cpp.

◆ OUTPOINT

const COutPoint OUTPOINT
static

Definition at line 555 of file coins_tests.cpp.

◆ SPENT

const CAmount SPENT = -1
static

Definition at line 556 of file coins_tests.cpp.

◆ utxoData

UtxoData utxoData

Definition at line 289 of file coins_tests.cpp.

◆ VALUE1

const CAmount VALUE1 = 100
static

Definition at line 559 of file coins_tests.cpp.

◆ VALUE2

const CAmount VALUE2 = 200
static

Definition at line 560 of file coins_tests.cpp.

◆ VALUE3

const CAmount VALUE3 = 300
static

Definition at line 561 of file coins_tests.cpp.