25 void initialize_setup()
27 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
28 g_setup = testing_setup.get();
39 FuzzedWallet(
const std::string&
name)
44 DatabaseOptions options;
45 options.require_create =
true;
47 const std::optional<bool> load_on_start;
52 std::vector<bilingual_str> warnings;
62 std::vector<bilingual_str> warnings;
63 std::optional<bool> load_on_start;
74 op_dest =
wallet->GetNewDestination(type,
"");
76 op_dest =
wallet->GetNewChangeDestination(type);
88 const auto total_amount{
ConsumeMoney(fuzzed_data_provider)};
89 FuzzedWallet a{
"fuzzed_wallet_a"};
90 FuzzedWallet b{
"fuzzed_wallet_b"};
96 using Coins = std::set<std::tuple<CAmount, COutPoint>>;
97 std::vector<std::tuple<Coins, CBlock>> chain;
100 chain.emplace_back();
101 auto& [coins, block]{chain.back()};
107 fuzzed_data_provider,
109 auto& [coins_orig, block]{chain.back()};
111 Coins coins = coins_orig;
112 while (!coins.empty()) {
114 CMutableTransaction tx{};
116 auto num_inputs{fuzzed_data_provider.ConsumeIntegralInRange<int>(1, coins.size())};
118 while (num_inputs-- > 0) {
119 const auto& [coin_amt, coin_outpoint]{*coins.begin()};
121 tx.vin.emplace_back(coin_outpoint);
122 coins.erase(coins.begin());
127 const auto out_value{
ConsumeMoney(fuzzed_data_provider, in)};
130 tx.vout.emplace_back(out_value,
wallet.GetScriptPubKey(fuzzed_data_provider));
134 tx.vout.emplace_back(in,
wallet.GetScriptPubKey(fuzzed_data_provider));
139 const uint256& hash = block.GetHash();
141 info.prev_hash = &block.hashPrevBlock;
142 info.height = chain.
size();
144 a.wallet->blockConnected(info);
145 b.wallet->blockConnected(info);
148 for (
const auto& tx : block.vtx) {
150 for (
const auto& out : tx->vout) {
151 coins_new.emplace(out.nValue,
COutPoint{tx->GetHash(), i++});
154 chain.emplace_back(coins_new,
CBlock{});
157 if (chain.size() <= 1)
return;
158 auto& [coins, block]{chain.back()};
159 if (block.vtx.empty())
return;
161 const uint256& hash = block.GetHash();
163 info.prev_hash = &block.hashPrevBlock;
164 info.height = chain.
size() - 1;
166 a.wallet->blockDisconnected(info);
167 b.wallet->blockDisconnected(info);
170 auto& [coins, first_block]{chain.front()};
171 if (!first_block.vtx.empty()) {
175 assert(total_amount == bal_a + bal_b);
int64_t CAmount
Amount in satoshis (Can be negative)
#define Assert(val)
Identity function.
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])
static constexpr unsigned int size()
#define FUZZ_TARGET_INIT(name, init_fun)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
static path PathFromString(const std::string &string)
Convert byte string to path object.
void UnloadWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly unload and delete the wallet.
Balance GetBalance(const CWallet &wallet, const int min_depth, bool avoid_reuse)
fs::path GetWalletDir()
Get the path of the wallet directory.
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)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::shared_ptr< CWallet > wallet
static constexpr auto OUTPUT_TYPES
static CTransactionRef MakeTransactionRef(Tx &&txIn)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
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.
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)