Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Enumerations | Functions | Variables
setup_common.h File Reference
#include <chainparamsbase.h>
#include <fs.h>
#include <key.h>
#include <util/system.h>
#include <node/context.h>
#include <pubkey.h>
#include <random.h>
#include <stdexcept>
#include <txmempool.h>
#include <util/check.h>
#include <util/string.h>
#include <util/vector.h>
#include <type_traits>
#include <vector>
Include dependency graph for setup_common.h:

Go to the source code of this file.

Classes

struct  BasicTestingSetup
 Basic testing setup. More...
 
struct  ChainTestingSetup
 Testing setup that performs all steps up until right before ChainstateManager gets initialized. More...
 
struct  TestingSetup
 Testing setup that configures a complete environment. More...
 
struct  RegTestingSetup
 Identical to TestingSetup, but chain set to regtest. More...
 
struct  TestChain100Setup
 Testing fixture that pre-creates a 100-block REGTEST-mode block chain. More...
 
struct  TestMemPoolEntryHelper
 
class  HasReason
 BOOST_CHECK_EXCEPTION predicates to check the specific validation error. More...
 

Enumerations

enum  SeedRand { SeedRand::ZEROS, SeedRand::SEED }
 

Functions

template<typename T >
std::ostream & operator<< (typename std::enable_if< std::is_enum< T >::value, std::ostream >::type &stream, const T &e)
 
void Seed (FastRandomContext &ctx)
 Seed the given random ctx or use the seed passed in via an environment var. More...
 
static void SeedInsecureRand (SeedRand seed=SeedRand::SEED)
 
static uint32_t InsecureRand32 ()
 
static uint256 InsecureRand256 ()
 
static uint64_t InsecureRandBits (int bits)
 
static uint64_t InsecureRandRange (uint64_t range)
 
static bool InsecureRandBool ()
 
template<class T = const BasicTestingSetup>
std::unique_ptr< TMakeNoLogFileContext (const std::string &chain_name=CBaseChainParams::REGTEST, const std::vector< const char * > &extra_args={})
 Make a test setup that has disk access to the debug.log file disabled. More...
 
CBlock getBlock13b8a ()
 
std::ostream & operator<< (std::ostream &os, const uint256 &num)
 

Variables

const std::function< void(const std::string &)> G_TEST_LOG_FUN
 This is connected to the logger. More...
 
FastRandomContext g_insecure_rand_ctx
 This global and the helpers that use it are not thread-safe. More...
 
bool g_mock_deterministic_tests
 Flag to make GetRand in random.h return the same number. More...
 
static constexpr CAmount CENT {1000000}
 

Enumeration Type Documentation

◆ SeedRand

enum SeedRand
strong
Enumerator
ZEROS 

Seed with a compile time constant of zeros.

SEED 

Call the Seed() helper.

Definition at line 48 of file setup_common.h.

Function Documentation

◆ getBlock13b8a()

CBlock getBlock13b8a ( )
Returns
a real block (0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af) with 9 txs.

Definition at line 327 of file setup_common.cpp.

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

◆ InsecureRand256()

static uint256 InsecureRand256 ( )
inlinestatic

Definition at line 66 of file setup_common.h.

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

◆ InsecureRand32()

static uint32_t InsecureRand32 ( )
inlinestatic

Definition at line 65 of file setup_common.h.

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

◆ InsecureRandBits()

static uint64_t InsecureRandBits ( int  bits)
inlinestatic

Definition at line 67 of file setup_common.h.

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

◆ InsecureRandBool()

static bool InsecureRandBool ( )
inlinestatic

Definition at line 69 of file setup_common.h.

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

◆ InsecureRandRange()

static uint64_t InsecureRandRange ( uint64_t  range)
inlinestatic

Definition at line 68 of file setup_common.h.

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

◆ MakeNoLogFileContext()

template<class T = const BasicTestingSetup>
std::unique_ptr<T> MakeNoLogFileContext ( const std::string &  chain_name = CBaseChainParams::REGTEST,
const std::vector< const char * > &  extra_args = {} 
)

Make a test setup that has disk access to the debug.log file disabled.

Can be used in "hot loops", for example fuzzing or benchmarking.

Definition at line 159 of file setup_common.h.

◆ operator<<() [1/2]

std::ostream& operator<< ( std::ostream &  os,
const uint256 num 
)

Definition at line 69 of file setup_common.cpp.

Here is the call graph for this function:

◆ operator<<() [2/2]

template<typename T >
std::ostream& operator<< ( typename std::enable_if< std::is_enum< T >::value, std::ostream >::type &  stream,
const T e 
)

Definition at line 29 of file setup_common.h.

◆ Seed()

void Seed ( FastRandomContext ctx)

Seed the given random ctx or use the seed passed in via an environment var.

Definition at line 58 of file setup_common.cpp.

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

◆ SeedInsecureRand()

static void SeedInsecureRand ( SeedRand  seed = SeedRand::SEED)
inlinestatic

Definition at line 56 of file setup_common.h.

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

Variable Documentation

◆ CENT

constexpr CAmount CENT {1000000}
staticconstexpr

Definition at line 71 of file setup_common.h.

◆ g_insecure_rand_ctx

FastRandomContext g_insecure_rand_ctx

This global and the helpers that use it are not thread-safe.

If thread-safety is needed, the global could be made thread_local (given that thread_local is supported on all architectures we support) or a per-thread instance could be used in the multi-threaded test.

Definition at line 46 of file setup_common.cpp.

◆ g_mock_deterministic_tests

bool g_mock_deterministic_tests

Flag to make GetRand in random.h return the same number.

Definition at line 589 of file random.cpp.

◆ G_TEST_LOG_FUN

const std::function<void(const std::string&)> G_TEST_LOG_FUN

This is connected to the logger.

Can be used to redirect logs to any other log

This is connected to the logger.

Definition at line 13 of file bench.cpp.