Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Public Attributes | List of all members
TestChain100Setup Struct Reference

Testing fixture that pre-creates a 100-block REGTEST-mode block chain. More...

#include <setup_common.h>

Inheritance diagram for TestChain100Setup:
[legend]
Collaboration diagram for TestChain100Setup:
[legend]

Public Member Functions

 TestChain100Setup (const ChainType chain_type=ChainType::REGTEST, const std::vector< const char * > &extra_args={}, const bool coins_db_in_memory=true, const bool block_tree_db_in_memory=true)
 
CBlock CreateAndProcessBlock (const std::vector< CMutableTransaction > &txns, const CScript &scriptPubKey, Chainstate *chainstate=nullptr)
 Create a new block with just given transactions, coinbase paying to scriptPubKey, and try to add it to the current chain. More...
 
CBlock CreateBlock (const std::vector< CMutableTransaction > &txns, const CScript &scriptPubKey, Chainstate &chainstate)
 Create a new block with just given transactions, coinbase paying to scriptPubKey. More...
 
void mineBlocks (int num_blocks)
 Mine a series of new blocks on the active chain. More...
 
std::pair< CMutableTransaction, CAmountCreateValidTransaction (const std::vector< CTransactionRef > &input_transactions, const std::vector< COutPoint > &inputs, int input_height, const std::vector< CKey > &input_signing_keys, const std::vector< CTxOut > &outputs, const std::optional< CFeeRate > &feerate, const std::optional< uint32_t > &fee_output)
 Create a transaction, optionally setting the fee based on the feerate. More...
 
CMutableTransaction CreateValidMempoolTransaction (const std::vector< CTransactionRef > &input_transactions, const std::vector< COutPoint > &inputs, int input_height, const std::vector< CKey > &input_signing_keys, const std::vector< CTxOut > &outputs, bool submit=true)
 Create a transaction and, optionally, submit to the mempool. More...
 
CMutableTransaction CreateValidMempoolTransaction (CTransactionRef input_transaction, uint32_t input_vout, int input_height, CKey input_signing_key, CScript output_destination, CAmount output_amount=CAmount(1 *COIN), bool submit=true)
 Create a 1-in-1-out transaction and, optionally, submit to the mempool. More...
 
std::vector< CTransactionRefPopulateMempool (FastRandomContext &det_rand, size_t num_transactions, bool submit)
 Create transactions spending from m_coinbase_txns. More...
 
void MockMempoolMinFee (const CFeeRate &target_feerate)
 Mock the mempool minimum feerate by adding a transaction and calling TrimToSize(0), simulating the mempool "reaching capacity" and evicting by descendant feerate. More...
 
- Public Member Functions inherited from TestingSetup
 TestingSetup (const ChainType chainType=ChainType::MAIN, const std::vector< const char * > &extra_args={}, const bool coins_db_in_memory=true, const bool block_tree_db_in_memory=true)
 
- Public Member Functions inherited from ChainTestingSetup
 ChainTestingSetup (const ChainType chainType=ChainType::MAIN, const std::vector< const char * > &extra_args={})
 
 ~ChainTestingSetup ()
 
void LoadVerifyActivateChainstate ()
 
- Public Member Functions inherited from BasicTestingSetup
 BasicTestingSetup (const ChainType chainType=ChainType::MAIN, const std::vector< const char * > &extra_args={})
 
 ~BasicTestingSetup ()
 

Public Attributes

std::vector< CTransactionRefm_coinbase_txns
 
CKey coinbaseKey
 
- Public Attributes inherited from ChainTestingSetup
node::CacheSizes m_cache_sizes {}
 
bool m_coins_db_in_memory {true}
 
bool m_block_tree_db_in_memory {true}
 
- Public Attributes inherited from BasicTestingSetup
util::SignalInterrupt m_interrupt
 
node::NodeContext m_node
 
fs::path m_path_root
 
fs::path m_path_lock
 
bool m_has_custom_datadir {false}
 
ArgsManager m_args
 

Detailed Description

Testing fixture that pre-creates a 100-block REGTEST-mode block chain.

Definition at line 106 of file setup_common.h.

Constructor & Destructor Documentation

◆ TestChain100Setup()

TestChain100Setup::TestChain100Setup ( const ChainType  chain_type = ChainType::REGTEST,
const std::vector< const char * > &  extra_args = {},
const bool  coins_db_in_memory = true,
const bool  block_tree_db_in_memory = true 
)

Definition at line 332 of file setup_common.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ CreateAndProcessBlock()

CBlock TestChain100Setup::CreateAndProcessBlock ( const std::vector< CMutableTransaction > &  txns,
const CScript scriptPubKey,
Chainstate chainstate = nullptr 
)

Create a new block with just given transactions, coinbase paying to scriptPubKey, and try to add it to the current chain.

If no chainstate is specified, default to the active.

Definition at line 384 of file setup_common.cpp.

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

◆ CreateBlock()

CBlock TestChain100Setup::CreateBlock ( const std::vector< CMutableTransaction > &  txns,
const CScript scriptPubKey,
Chainstate chainstate 
)

Create a new block with just given transactions, coinbase paying to scriptPubKey.

Definition at line 366 of file setup_common.cpp.

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

◆ CreateValidMempoolTransaction() [1/2]

CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction ( const std::vector< CTransactionRef > &  input_transactions,
const std::vector< COutPoint > &  inputs,
int  input_height,
const std::vector< CKey > &  input_signing_keys,
const std::vector< CTxOut > &  outputs,
bool  submit = true 
)

Create a transaction and, optionally, submit to the mempool.

Parameters
input_transactionsThe transactions to spend
inputsOutpoints with which to construct transaction vin.
input_heightThe height of the block that included the input transaction(s).
input_signing_keysThe keys to spend inputs.
outputsTransaction vout.
submitWhether or not to submit to mempool

Definition at line 465 of file setup_common.cpp.

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

◆ CreateValidMempoolTransaction() [2/2]

CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction ( CTransactionRef  input_transaction,
uint32_t  input_vout,
int  input_height,
CKey  input_signing_key,
CScript  output_destination,
CAmount  output_amount = CAmount(1 * COIN),
bool  submit = true 
)

Create a 1-in-1-out transaction and, optionally, submit to the mempool.

Parameters
input_transactionThe transaction to spend
input_voutThe vout to spend from the input_transaction
input_heightThe height of the block that included the input_transaction
input_signing_keyThe key to spend the input_transaction
output_destinationWhere to send the output
output_amountHow much to send
submitWhether or not to submit to mempool

Definition at line 482 of file setup_common.cpp.

Here is the call graph for this function:

◆ CreateValidTransaction()

std::pair< CMutableTransaction, CAmount > TestChain100Setup::CreateValidTransaction ( const std::vector< CTransactionRef > &  input_transactions,
const std::vector< COutPoint > &  inputs,
int  input_height,
const std::vector< CKey > &  input_signing_keys,
const std::vector< CTxOut > &  outputs,
const std::optional< CFeeRate > &  feerate,
const std::optional< uint32_t > &  fee_output 
)

Create a transaction, optionally setting the fee based on the feerate.

Note: The feerate may not be met exactly depending on whether the signatures can have different sizes.

Parameters
input_transactionsThe transactions to spend
inputsOutpoints with which to construct transaction vin.
input_heightThe height of the block that included the input transactions.
input_signing_keysThe keys to spend the input transactions.
outputsTransaction vout.
feerateThe feerate the transaction should pay.
fee_outputThe index of the output to take the fee from.
Returns
The transaction and the fee it pays

Definition at line 400 of file setup_common.cpp.

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

◆ mineBlocks()

void TestChain100Setup::mineBlocks ( int  num_blocks)

Mine a series of new blocks on the active chain.

Definition at line 355 of file setup_common.cpp.

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

◆ MockMempoolMinFee()

void TestChain100Setup::MockMempoolMinFee ( const CFeeRate target_feerate)

Mock the mempool minimum feerate by adding a transaction and calling TrimToSize(0), simulating the mempool "reaching capacity" and evicting by descendant feerate.

Note that this clears the mempool, and the new minimum feerate will depend on the maximum feerate of transactions removed, so this must be called while the mempool is empty.

Parameters
target_feerateThe new mempool minimum feerate after this function returns. Must be above max(incremental feerate, min relay feerate), or 1sat/vB with default settings.

Definition at line 548 of file setup_common.cpp.

Here is the call graph for this function:

◆ PopulateMempool()

std::vector< CTransactionRef > TestChain100Setup::PopulateMempool ( FastRandomContext det_rand,
size_t  num_transactions,
bool  submit 
)

Create transactions spending from m_coinbase_txns.

These transactions will only spend coins that exist in the current chain, but may be premature coinbase spends, have missing signatures, or violate some other consensus rules. They should only be used for testing mempool consistency. All transactions will have some random number of inputs and outputs (between 1 and 24). Transactions may or may not be dependent upon each other; if dependencies exit, every parent will always be somewhere in the list before the child so each transaction can be submitted in the same order they appear in the list.

Parameters
[in]submitWhen true, submit transactions to the mempool. When false, return them but don't submit them.
Returns
A vector of transactions that can be submitted to the mempool.

Definition at line 500 of file setup_common.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ coinbaseKey

CKey TestChain100Setup::coinbaseKey

Definition at line 215 of file setup_common.h.

◆ m_coinbase_txns

std::vector<CTransactionRef> TestChain100Setup::m_coinbase_txns

Definition at line 214 of file setup_common.h.


The documentation for this struct was generated from the following files: