Bitcoin Core  25.99.0
P2P Digital Currency
Classes | Namespaces | Enumerations | Functions | Variables
setup_common.h File Reference
#include <common/args.h>
#include <key.h>
#include <node/caches.h>
#include <node/context.h>
#include <primitives/transaction.h>
#include <pubkey.h>
#include <random.h>
#include <stdexcept>
#include <util/chaintype.h>
#include <util/check.h>
#include <util/fs.h>
#include <util/string.h>
#include <util/vector.h>
#include <functional>
#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...
 
class  HasReason
 BOOST_CHECK_EXCEPTION predicates to check the specific validation error. More...
 

Namespaces

 std
 

Enumerations

enum class  SeedRand { ZEROS , SEED }
 

Functions

template<typename T >
std::ostream & std::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)
 
template<class T = const BasicTestingSetup>
std::unique_ptr< T > MakeNoLogFileContext (const ChainType chain_type=ChainType::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...
 
const std::function< std::vector< const char * >)> G_TEST_COMMAND_LINE_ARGUMENTS
 Retrieve the command line arguments. 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 58 of file setup_common.h.

Function Documentation

◆ getBlock13b8a()

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

Definition at line 479 of file setup_common.cpp.

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 ChainType  chain_type = ChainType::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 209 of file setup_common.h.

Here is the caller graph for this function:

◆ operator<<()

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

Definition at line 99 of file setup_common.cpp.

Here is the call graph for this function:

◆ Seed()

void Seed ( FastRandomContext ctx)

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

Definition at line 88 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 66 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 75 of file setup_common.h.

◆ g_insecure_rand_ctx

FastRandomContext g_insecure_rand_ctx
extern

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 76 of file setup_common.cpp.

◆ g_mock_deterministic_tests

bool g_mock_deterministic_tests
extern

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

Definition at line 563 of file random.cpp.

◆ G_TEST_COMMAND_LINE_ARGUMENTS

const std::function<std::vector<const char*>)> G_TEST_COMMAND_LINE_ARGUMENTS
extern

Retrieve the command line arguments.

Retrieve the command line arguments.

Allows usage like: test_bitcoin --run_test="net_tests/cnode_listen_port" -- -checkaddrman=1 -printtoconsole=1 which would return ["-checkaddrman=1", "-printtoconsole=1"].

Definition at line 24 of file bench.cpp.

◆ G_TEST_LOG_FUN

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

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 22 of file bench.cpp.