51void initialize_setup()
53 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
54 g_setup = testing_setup.get();
68 "tprv8ZgxMBicQKsPd1QwsGgzfu2pcPYbBosZhJknqreRHgsWx32nNEhMjGQX2cgFL8n6wz9xdDYwLcs78N4nsCo32cxEX8RBtwGsEGgybLiQJfk",
73 "tprv8ZgxMBicQKsPfCunYTF18sEmEyjz8TfhGnZ3BoVAhkqLv7PLkQgmoG2Ecsp4JuqciWnkopuEwShit7st743fdmB9cMD4tznUkcs33vK51K9",
80 using Coins = std::set<std::tuple<CAmount, COutPoint>>;
81 std::vector<std::tuple<Coins, CBlock>> chain;
85 auto& [coins, block]{chain.back()};
93 auto& [coins_orig, block]{chain.back()};
95 Coins coins = coins_orig;
96 while (!coins.empty()) {
98 CMutableTransaction tx{};
100 auto num_inputs{fuzzed_data_provider.ConsumeIntegralInRange<int>(1, coins.size())};
102 while (num_inputs-- > 0) {
103 const auto& [coin_amt, coin_outpoint]{*coins.begin()};
105 tx.vin.emplace_back(coin_outpoint);
106 coins.erase(coins.begin());
109 LIMITED_WHILE(in > 0 && fuzzed_data_provider.ConsumeBool(), 10)
111 const auto out_value{
ConsumeMoney(fuzzed_data_provider, in)};
113 auto&
wallet{fuzzed_data_provider.ConsumeBool() ? a : b};
114 tx.vout.emplace_back(out_value,
wallet.GetScriptPubKey(fuzzed_data_provider));
117 auto&
wallet{fuzzed_data_provider.ConsumeBool() ? a : b};
118 tx.vout.emplace_back(in,
wallet.GetScriptPubKey(fuzzed_data_provider));
122 a.FundTx(fuzzed_data_provider, tx);
123 b.FundTx(fuzzed_data_provider, tx);
126 const uint256& hash = block.GetHash();
128 info.prev_hash = &block.hashPrevBlock;
129 info.height = chain.
size();
134 info.chain_time_max = std::numeric_limits<unsigned int>::max();
139 for (
const auto& tx : block.vtx) {
141 for (
const auto&
out : tx->vout) {
142 coins_new.emplace(
out.nValue,
COutPoint{tx->GetHash(), i++});
145 chain.emplace_back(coins_new,
CBlock{});
148 if (chain.size() <= 1)
return;
149 auto& [coins, block]{chain.back()};
150 if (block.vtx.empty())
return;
152 const uint256& hash = block.GetHash();
154 info.prev_hash = &block.hashPrevBlock;
155 info.height = chain.
size() - 1;
157 a.wallet->blockDisconnected(info);
158 b.wallet->blockDisconnected(info);
161 auto& [coins, first_block]{chain.front()};
162 if (!first_block.vtx.empty()) {
166 assert(total_amount == bal_a + bal_b);
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
int64_t CAmount
Amount in satoshis (Can be negative)
An outpoint - a combination of a transaction hash and an index n into its vout.
static constexpr unsigned int size()
static transaction_identifier FromUint256(const uint256 &id)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
FUZZ_TARGET(coin_grinder)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Testing setup that configures a complete environment.
Block data sent with blockConnected, blockDisconnected notifications.
std::unique_ptr< interfaces::Chain > chain
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
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.