5 #include <chainparams.h> 18 #include <util/time.h> 19 #include <validation.h> 33 "-testactivationheight=bip34@2",
38 test_setup.LoadVerifyActivateChainstate();
39 auto&
node{test_setup.m_node};
40 auto& chainman{*
Assert(test_setup.m_node.chainman)};
42 const auto ActiveHeight = [&]() {
43 LOCK(chainman.GetMutex());
44 return chainman.ActiveHeight();
46 BlockAssembler::Options options;
48 options.include_dummy_extranonce =
true;
49 const auto PrepareNextBlock = [&]() {
63 auto current_block = PrepareNextBlock();
65 std::vector<std::pair<COutPoint, CTxOut>> txos;
73 const auto StoreLastTxo = [&]() {
77 const uint32_t i = tx.
vout.size() - 1;
80 if (current_block->vtx.size() == 1 && tx.
vout.at(i).scriptPubKey[0] ==
OP_RETURN) {
82 const uint32_t i = tx.
vout.size() - 2;
88 tx.vin.emplace_back(txo.first);
89 tx.vout.emplace_back(txo.second.nValue, txo.second.scriptPubKey);
91 const auto UpdateUtxoStats = [&](
bool wipe_cache) {
92 LOCK(chainman.GetMutex());
93 chainman.ActiveChainstate().ForceFlushStateToDisk(wipe_cache);
94 utxo_stats = std::move(
104 assert(ActiveHeight() == 0);
110 const CScript duplicate_coinbase_script =
CScript() << duplicate_coinbase_height <<
OP_0;
112 current_block = PrepareNextBlock();
118 tx.
vin.at(0).scriptSig = duplicate_coinbase_script;
127 assert(ActiveHeight() == 1);
129 current_block = PrepareNextBlock();
137 fuzzed_data_provider, 139 // Append an input-output pair to the last tx in the current block 140 CMutableTransaction tx{*current_block->vtx.back()}; 142 current_block->vtx.back() = MakeTransactionRef(tx); 146 // Append a tx to the list of txs in the current block 147 CMutableTransaction tx{}; 149 current_block->vtx.push_back(MakeTransactionRef(tx)); 153 // Append the current block to the active chain 154 node::RegenerateCommitments(*current_block, chainman); 155 const bool was_valid = !MineBlock(node, current_block).IsNull(); 157 const uint256 prev_hash_serialized{utxo_stats.hashSerialized}; 159 if (duplicate_coinbase_height == ActiveHeight()) { 160 // we mined the duplicate coinbase 161 assert(current_block->vtx.at(0)->vin.at(0).scriptSig == duplicate_coinbase_script); 164 circulation += GetBlockSubsidy(ActiveHeight(), Params().GetConsensus()); 167 UpdateUtxoStats(/*wipe_cache=*/fuzzed_data_provider.ConsumeBool()); 170 // utxo stats must not change 171 assert(prev_hash_serialized == utxo_stats.hashSerialized); 174 current_block = PrepareNextBlock(); Testing setup that performs all steps up until right before ChainstateManager gets initialized...
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const BlockAssembler::Options &assembler_options)
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Generate a new block, without valid proof-of-work.
std::optional< CAmount > total_amount
The total amount, or nullopt if an overflow occurred calculating it.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
int64_t CAmount
Amount in satoshis (Can be negative)
COutPoint MineBlock(const NodeContext &node, const node::BlockAssembler::Options &assembler_options)
Returns the generated coin.
const std::vector< CTxOut > vout
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
An outpoint - a combination of a transaction hash and an index n into its vout.
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
static CTransactionRef MakeTransactionRef(Tx &&txIn)
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
const CChainParams & Params()
Return the currently selected parameters.
Serialized script, used inside transaction inputs and outputs.
static bool ComputeUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, const std::function< void()> &interruption_point, std::unique_ptr< CCoinsViewCursor > pcursor)
Calculate statistics about the unspent transaction output set.
FuzzedDataProvider & fuzzed_data_provider
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
A mutable version of CTransaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
T ConsumeIntegralInRange(T min, T max)
Seed with a compile time constant of zeros.
FUZZ_TARGET(utxo_total_supply)
#define Assert(val)
Identity function.
const Txid & GetHash() const LIFETIMEBOUND