11 #include <util/time.h> 17 #include <validation.h> 26 void initialize_setup()
28 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
41 FuzzedWallet fuzzed_wallet{
44 "tprv8ZgxMBicQKsPd1QwsGgzfu2pcPYbBosZhJknqreRHgsWx32nNEhMjGQX2cgFL8n6wz9xdDYwLcs78N4nsCo32cxEX8RBtwGsEGgybLiQJfk",
47 CCoinControl coin_control;
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); 54 if (fuzzed_data_provider.ConsumeBool()) coin_control.m_feerate = CFeeRate(ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)); 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(); 60 CAmount all_values{0}; 61 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) 63 CMutableTransaction tx; 64 tx.nLockTime = next_locktime++; 66 CAmount n_value{ConsumeMoney(fuzzed_data_provider)}; 67 all_values += n_value; 68 if (all_values > MAX_MONEY) return; 69 tx.vout[0].nValue = n_value; 70 tx.vout[0].scriptPubKey = GetScriptForDestination(fuzzed_wallet.GetDestination(fuzzed_data_provider)); 71 LOCK(fuzzed_wallet.wallet->cs_wallet); 72 auto txid{tx.GetHash()}; 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(), /*index=*/0}))}; 77 std::vector<CRecipient> recipients; 78 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100) { 79 CTxDestination destination; 83 destination = fuzzed_wallet.GetDestination(fuzzed_data_provider); 88 destination = CNoDestination{script}; 91 destination = ConsumeTxDestination(fuzzed_data_provider); 94 recipients.push_back({destination, 95 /*nAmount=*/ConsumeMoney(fuzzed_data_provider), 96 /*fSubtractFeeFromAmount=*/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); 104 } // namespace wallet std::unique_ptr< interfaces::Chain > chain
FUZZ_TARGET(coin_grinder)
const TestingSetup * g_setup
void ForceSetArg(const std::string &strArg, const std::string &strValue)
int64_t CAmount
Amount in satoshis (Can be negative)
Chainstate stores and provides an API to update our local knowledge of the current best chain...
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
FuzzedDataProvider & fuzzed_data_provider
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
T ConsumeIntegralInRange(T min, T max)
Seed with a compile time constant of zeros.
Testing setup that configures a complete environment.
std::string ToString(const T &t)
Locale-independent version of std::to_string.