17#include <validation.h>
26void initialize_setup()
28 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
29 g_setup = testing_setup.get();
41 FuzzedWallet fuzzed_wallet{
44 "tprv8ZgxMBicQKsPd1QwsGgzfu2pcPYbBosZhJknqreRHgsWx32nNEhMjGQX2cgFL8n6wz9xdDYwLcs78N4nsCo32cxEX8RBtwGsEGgybLiQJfk",
47 CCoinControl coin_control;
48 if (fuzzed_data_provider.ConsumeBool()) coin_control.m_version = fuzzed_data_provider.ConsumeIntegral<
unsigned int>();
49 coin_control.m_avoid_partial_spends = fuzzed_data_provider.ConsumeBool();
50 coin_control.m_include_unsafe_inputs = fuzzed_data_provider.ConsumeBool();
51 if (fuzzed_data_provider.ConsumeBool()) coin_control.m_confirm_target = fuzzed_data_provider.ConsumeIntegralInRange<
unsigned int>(0, 999'000);
52 coin_control.destChange = fuzzed_data_provider.ConsumeBool() ? fuzzed_wallet.GetDestination(fuzzed_data_provider) :
ConsumeTxDestination(fuzzed_data_provider);
53 if (fuzzed_data_provider.ConsumeBool()) coin_control.m_change_type = fuzzed_data_provider.PickValueInArray(
OUTPUT_TYPES);
55 coin_control.m_allow_other_inputs = fuzzed_data_provider.ConsumeBool();
56 coin_control.m_locktime = fuzzed_data_provider.ConsumeIntegral<
unsigned int>();
57 coin_control.fOverrideFeeRate = fuzzed_data_provider.ConsumeBool();
67 all_values += n_value;
69 tx.
vout[0].nValue = n_value;
71 LOCK(fuzzed_wallet.wallet->cs_wallet);
73 auto ret{fuzzed_wallet.wallet->mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(
MakeTransactionRef(std::move(tx)), TxStateConfirmed{chainstate.m_chain.Tip()->GetBlockHash(), chainstate.m_chain.Height(), 0}))};
77 std::vector<CRecipient> recipients;
83 destination = fuzzed_wallet.GetDestination(fuzzed_data_provider);
94 recipients.push_back({destination,
96 fuzzed_data_provider.ConsumeBool()});
99 std::optional<unsigned int> change_pos;
100 if (fuzzed_data_provider.ConsumeBool()) change_pos = fuzzed_data_provider.ConsumeIntegral<
unsigned int>();
101 (void)
CreateTransaction(*fuzzed_wallet.wallet, recipients, change_pos, coin_control);
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Serialized script, used inside transaction inputs and outputs.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
util::Result< CreatedTransactionResult > CreateTransaction(CWallet &wallet, const std::vector< CRecipient > &vecSend, std::optional< unsigned int > change_pos, const CCoinControl &coin_control, bool sign)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
FUZZ_TARGET(coin_grinder)
static constexpr auto OUTPUT_TYPES
static CTransactionRef MakeTransactionRef(Tx &&txIn)
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Testing setup that configures a complete environment.
std::unique_ptr< interfaces::Chain > chain
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
CTxDestination ConsumeTxDestination(FuzzedDataProvider &fuzzed_data_provider) 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.