5#include <chainparams.h>
19#include <validation.h>
27 const auto mock_time{
ConsumeTime(fuzzed_data_provider, 1296688602)};
33 "-testactivationheight=bip34@2",
34 strprintf(
"-mocktime=%d", mock_time).c_str()
39 test_setup.LoadVerifyActivateChainstate();
40 auto&
node{test_setup.m_node};
41 auto& chainman{*
Assert(test_setup.m_node.chainman)};
43 const auto ActiveHeight = [&]() {
44 LOCK(chainman.GetMutex());
45 return chainman.ActiveHeight();
47 BlockAssembler::Options options;
49 const auto PrepareNextBlock = [&]() {
62 auto current_block = PrepareNextBlock();
64 std::vector<std::pair<COutPoint, CTxOut>> txos;
72 const auto StoreLastTxo = [&]() {
76 const uint32_t i = tx.
vout.size() - 1;
79 if (current_block->vtx.size() == 1 && tx.
vout.at(i).scriptPubKey[0] ==
OP_RETURN) {
81 const uint32_t i = tx.
vout.size() - 2;
87 tx.vin.emplace_back(txo.first);
88 tx.vout.emplace_back(txo.second.nValue, txo.second.scriptPubKey);
90 const auto UpdateUtxoStats = [&]() {
91 LOCK(chainman.GetMutex());
92 chainman.ActiveChainstate().ForceFlushStateToDisk();
93 utxo_stats = std::move(
103 assert(ActiveHeight() == 0);
109 const CScript duplicate_coinbase_script =
CScript() << duplicate_coinbase_height <<
OP_0;
111 current_block = PrepareNextBlock();
117 tx.
vin.at(0).scriptSig = duplicate_coinbase_script;
126 assert(ActiveHeight() == 1);
128 current_block = PrepareNextBlock();
136 fuzzed_data_provider,
156 const auto prev_utxo_stats = utxo_stats;
158 if (duplicate_coinbase_height == ActiveHeight()) {
160 assert(current_block->vtx.at(0)->vin.at(0).scriptSig == duplicate_coinbase_script);
173 current_block = PrepareNextBlock();
int64_t CAmount
Amount in satoshis (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const Txid & GetHash() const LIFETIMEBOUND
T ConsumeIntegralInRange(T min, T max)
Generate a new block, without valid proof-of-work.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
static bool ComputeUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, const std::function< void()> &interruption_point)
Calculate statistics about the unspent transaction output set.
void RegenerateCommitments(CBlock &block, ChainstateManager &chainman)
Update an old GenerateCoinbaseCommitment from CreateNewBlock after the block txs have changed.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Testing setup that performs all steps up until right before ChainstateManager gets initialized.
std::optional< CAmount > total_amount
The total amount, or nullopt if an overflow occurred calculating it.
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const BlockAssembler::Options &assembler_options)
COutPoint MineBlock(const NodeContext &node, const node::BlockAssembler::Options &assembler_options)
Returns the generated coin.
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
FUZZ_TARGET(utxo_total_supply)
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)