24void initialize_setup()
26 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
27 g_setup = testing_setup.get();
37 std::shared_ptr<CWallet>
wallet;
38 FuzzedWallet(
const std::string&
name)
46 const std::optional<bool> load_on_start;
51 std::vector<bilingual_str> warnings;
61 std::vector<bilingual_str> warnings;
62 std::optional<bool> load_on_start;
92 const auto total_amount{
ConsumeMoney(fuzzed_data_provider)};
93 FuzzedWallet a{
"fuzzed_wallet_a"};
94 FuzzedWallet b{
"fuzzed_wallet_b"};
100 using Coins = std::set<std::tuple<CAmount, COutPoint>>;
101 std::vector<std::tuple<Coins, CBlock>> chain;
104 chain.emplace_back();
105 auto& [coins, block]{chain.back()};
111 fuzzed_data_provider,
113 auto& [coins_orig, block]{chain.back()};
115 Coins coins = coins_orig;
116 while (!coins.empty()) {
118 CMutableTransaction tx{};
120 auto num_inputs{fuzzed_data_provider.ConsumeIntegralInRange<int>(1, coins.size())};
122 while (num_inputs-- > 0) {
123 const auto& [coin_amt, coin_outpoint]{*coins.begin()};
125 tx.vin.emplace_back(coin_outpoint);
126 coins.erase(coins.begin());
131 const auto out_value{
ConsumeMoney(fuzzed_data_provider, in)};
134 tx.vout.emplace_back(out_value,
wallet.GetScriptPubKey(fuzzed_data_provider));
138 tx.vout.emplace_back(in,
wallet.GetScriptPubKey(fuzzed_data_provider));
143 a.wallet->blockConnected(block, chain.size());
144 b.wallet->blockConnected(block, chain.size());
147 for (
const auto& tx : block.vtx) {
149 for (
const auto& out : tx->vout) {
150 coins_new.emplace(out.nValue,
COutPoint{tx->GetHash(), i++});
153 chain.emplace_back(coins_new,
CBlock{});
156 if (chain.size() <= 1)
return;
157 auto& [coins, block]{chain.back()};
158 if (block.vtx.empty())
return;
160 a.wallet->blockDisconnected(block, chain.size() - 1);
161 b.wallet->blockDisconnected(block, chain.size() - 1);
164 auto& [coins, first_block]{chain.front()};
165 if (!first_block.vtx.empty()) {
169 assert(total_amount == bal_a + bal_b);
int64_t CAmount
Amount in satoshis (Can be negative)
void ForceSetArg(const std::string &strArg, const std::string &strValue)
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
T PickValueInArray(const T(&array)[size])
#define FUZZ_TARGET_INIT(name, init_fun)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
static constexpr auto OUTPUT_TYPES
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
CAmount m_mine_trusted
Trusted, at depth=GetBalance.min_depth or more.
std::unique_ptr< interfaces::Chain > chain
Testing setup that configures a complete environment.
WalletContext struct containing references to state shared between CWallet instances,...
interfaces::Chain * chain
bool error(const char *fmt, const Args &... args)
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
std::shared_ptr< CWallet > CreateWallet(WalletContext &context, const std::string &name, std::optional< bool > load_on_start, DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error, std::vector< bilingual_str > &warnings)
fs::path GetWalletDir()
Get the path of the wallet directory.
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.