52void initialize_setup()
54 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
55 g_setup = testing_setup.get();
70 "tprv8ZgxMBicQKsPd1QwsGgzfu2pcPYbBosZhJknqreRHgsWx32nNEhMjGQX2cgFL8n6wz9xdDYwLcs78N4nsCo32cxEX8RBtwGsEGgybLiQJfk",
75 "tprv8ZgxMBicQKsPfCunYTF18sEmEyjz8TfhGnZ3BoVAhkqLv7PLkQgmoG2Ecsp4JuqciWnkopuEwShit7st743fdmB9cMD4tznUkcs33vK51K9",
82 using Coins = std::set<std::tuple<CAmount, COutPoint>>;
83 std::vector<std::tuple<Coins, CBlock>> chain;
87 auto& [coins, block]{chain.back()};
95 auto& [coins_orig, block]{chain.back()};
97 Coins coins = coins_orig;
98 while (!coins.empty()) {
100 CMutableTransaction tx{};
102 auto num_inputs{fuzzed_data_provider.ConsumeIntegralInRange<int>(1, coins.size())};
104 while (num_inputs-- > 0) {
105 const auto& [coin_amt, coin_outpoint]{*coins.begin()};
107 tx.vin.emplace_back(coin_outpoint);
108 coins.erase(coins.begin());
111 LIMITED_WHILE(in > 0 && fuzzed_data_provider.ConsumeBool(), 10)
113 const auto out_value{
ConsumeMoney(fuzzed_data_provider, in)};
115 auto&
wallet{fuzzed_data_provider.ConsumeBool() ? a : b};
116 tx.vout.emplace_back(out_value,
wallet.GetScriptPubKey(fuzzed_data_provider));
119 auto&
wallet{fuzzed_data_provider.ConsumeBool() ? a : b};
120 tx.vout.emplace_back(in,
wallet.GetScriptPubKey(fuzzed_data_provider));
124 a.FundTx(fuzzed_data_provider, tx);
125 b.FundTx(fuzzed_data_provider, tx);
128 const uint256& hash = block.GetHash();
130 info.prev_hash = &block.hashPrevBlock;
131 info.height = chain.
size();
136 info.chain_time_max = std::numeric_limits<unsigned int>::max();
141 for (
const auto& tx : block.vtx) {
143 for (
const auto&
out : tx->vout) {
144 coins_new.emplace(
out.nValue,
COutPoint{tx->GetHash(), i++});
147 chain.emplace_back(coins_new,
CBlock{});
150 if (chain.size() <= 1)
return;
151 auto& [coins, block]{chain.back()};
152 if (block.vtx.empty())
return;
154 const uint256& hash = block.GetHash();
156 info.prev_hash = &block.hashPrevBlock;
157 info.height = chain.
size() - 1;
159 a.wallet->blockDisconnected(info);
160 b.wallet->blockDisconnected(info);
163 auto& [coins, first_block]{chain.front()};
164 if (!first_block.vtx.empty()) {
168 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.
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
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.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.