Skip to content

Commit

Permalink
test: Fix compilation errors in fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lateminer committed Nov 26, 2023
1 parent 834cdb1 commit febda8a
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 27 deletions.
2 changes: 0 additions & 2 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/parse_script.cpp \
test/fuzz/parse_univalue.cpp \
test/fuzz/partially_downloaded_block.cpp \
test/fuzz/policy_estimator.cpp \
test/fuzz/policy_estimator_io.cpp \
test/fuzz/pow.cpp \
test/fuzz/prevector.cpp \
test/fuzz/primitives_transaction.cpp \
Expand Down
4 changes: 4 additions & 0 deletions src/test/fuzz/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <cassert>
#include <string>

namespace {
const BasicTestingSetup* g_setup;
} // namespace

void initialize_block()
{
SelectParams(CBaseChainParams::REGTEST);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/coins_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
const CTransaction transaction{random_mutable_transaction};
bool is_spent = false;
for (const CTxOut& tx_out : transaction.vout) {
if (Coin{tx_out, 0, transaction.IsCoinBase()}.IsSpent()) {
if (Coin{tx_out, 0, transaction.IsCoinBase(), transaction.IsCoinStake(), 0}.IsSpent()) {
is_spent = true;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/test/fuzz/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <util/fees.h>

#include <cstdint>
#include <string>
Expand Down
2 changes: 0 additions & 2 deletions src/test/fuzz/kitchen_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ FUZZ_TARGET(kitchen_sink)
(void)RPCErrorFromTransactionError(transaction_error);
(void)TransactionErrorString(transaction_error);

(void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));

const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
const std::string& output_type_string = FormatOutputType(output_type);
const std::optional<OutputType> parsed = ParseOutputType(output_type_string);
Expand Down
5 changes: 3 additions & 2 deletions src/test/fuzz/partially_downloaded_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void initialize_pdb()

PartiallyDownloadedBlock::CheckBlockFn FuzzedCheckBlock(std::optional<BlockValidationResult> result)
{
return [result](const CBlock&, BlockValidationState& state, const Consensus::Params&, bool, bool) {
return [result](const CBlock&, BlockValidationState& state, const Consensus::Params&, Chainstate& chainstate, bool, bool, bool) {
if (result) {
return state.Invalid(*result);
}
Expand All @@ -53,7 +53,8 @@ FUZZ_TARGET_INIT(partially_downloaded_block, initialize_pdb)
CBlockHeaderAndShortTxIDs cmpctblock{*block};

CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};
PartiallyDownloadedBlock pdb{&pool};
ChainstateManager& chainman = *g_setup->m_node.chainman;
PartiallyDownloadedBlock pdb{&pool, &chainman};

// Set of available transactions (mempool or extra_txn)
std::set<uint16_t> available;
Expand Down
6 changes: 3 additions & 3 deletions src/test/fuzz/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ FUZZ_TARGET_INIT(pow, initialize_pow)
}
{
(void)GetBlockProof(current_block);
(void)CalculateNextWorkRequired(&current_block, fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(0, std::numeric_limits<int64_t>::max()), consensus_params);
(void)CalculateNextTargetRequired(&current_block, fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(0, std::numeric_limits<int64_t>::max()), consensus_params, false);
if (current_block.nHeight != std::numeric_limits<int>::max() && current_block.nHeight - (consensus_params.DifficultyAdjustmentInterval() - 1) >= 0) {
(void)GetNextWorkRequired(&current_block, &(*block_header), consensus_params);
(void)GetNextTargetRequired(&current_block, consensus_params, false);
}
}
{
Expand Down Expand Up @@ -118,6 +118,6 @@ FUZZ_TARGET_INIT(pow_transition, initialize_pow)
blocks.emplace_back(std::move(current_block));
}
auto last_block{blocks.back().get()};
unsigned int new_nbits{GetNextWorkRequired(last_block, nullptr, consensus_params)};
unsigned int new_nbits{GetNextTargetRequired(last_block, consensus_params, false)};
Assert(PermittedDifficultyTransition(consensus_params, last_block->nHeight + 1, last_block->nBits, new_nbits));
}
2 changes: 1 addition & 1 deletion src/test/fuzz/process_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void initialize_process_message()
/*chain_name=*/CBaseChainParams::REGTEST,
/*extra_args=*/{"-txreconciliation"});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
for (int i = 0; i < 2 * Params().GetConsensus().nCoinbaseMaturity; i++) {
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
}
SyncWithValidationInterfaceQueue();
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/process_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void initialize_process_messages()
/*chain_name=*/CBaseChainParams::REGTEST,
/*extra_args=*/{"-txreconciliation"});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
for (int i = 0; i < 2 * Params().GetConsensus().nCoinbaseMaturity; i++) {
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
}
SyncWithValidationInterfaceQueue();
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ std::string ConsumeScalarRPCArgument(FuzzedDataProvider& fuzzed_data_provider)
if (!opt_block_header) {
return;
}
DataStream data_stream{};
CDataStream data_stream{SER_NETWORK, PROTOCOL_VERSION};
data_stream << *opt_block_header;
r = HexStr(data_stream);
},
Expand Down
5 changes: 0 additions & 5 deletions src/test/fuzz/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <util/error.h>
#include <util/fees.h>
#include <util/settings.h>
#include <util/strencodings.h>
#include <util/string.h>
Expand All @@ -34,8 +33,6 @@
#include <string>
#include <vector>

enum class FeeEstimateMode;

FUZZ_TARGET(string)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
Expand All @@ -49,8 +46,6 @@ FUZZ_TARGET(string)
(void)BlockFilterTypeByName(random_string_1, block_filter_type);
(void)Capitalize(random_string_1);
(void)CopyrightHolders(random_string_1);
FeeEstimateMode fee_estimate_mode;
(void)FeeModeFromString(random_string_1, fee_estimate_mode);
const auto width{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 1000)};
(void)FormatParagraph(random_string_1, width, fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, width));
(void)FormatSubVersion(random_string_1, fuzzed_data_provider.ConsumeIntegral<int>(), random_string_vector);
Expand Down
1 change: 0 additions & 1 deletion src/test/fuzz/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
(void)GetVirtualTransactionSize(tx);
(void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024);
(void)RecursiveDynamicUsage(tx);
(void)SignalsOptInRBF(tx);

CCoinsView coins_view;
const CCoinsViewCache coins_view_cache(&coins_view);
Expand Down
7 changes: 3 additions & 4 deletions src/test/fuzz/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void initialize_tx_pool()
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
g_setup = testing_setup.get();

for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
for (int i = 0; i < 2 * Params().GetConsensus().nCoinbaseMaturity; ++i) {
CTxIn in = MineBlock(g_setup->m_node, P2WSH_OP_TRUE);
// Remember the txids to avoid expensive disk access later on
auto& outpoints = i < COINBASE_MATURITY ?
auto& outpoints = i < Params().GetConsensus().nCoinbaseMaturity ?
g_outpoints_coinbase_init_mature :
g_outpoints_coinbase_init_immature;
outpoints.push_back(in.prevout);
Expand Down Expand Up @@ -122,7 +122,6 @@ CTxMemPool MakeMempool(FuzzedDataProvider& fuzzed_data_provider, const NodeConte
CTxMemPool::Options mempool_opts{MemPoolOptionsForTest(node)};

// ...override specific options for this specific fuzz suite
mempool_opts.estimator = nullptr;
mempool_opts.check_ratio = 1;
mempool_opts.require_standard = fuzzed_data_provider.ConsumeBool();

Expand All @@ -148,7 +147,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
outpoints_rbf = outpoints_supply;

// The sum of the values of all spendable outpoints
constexpr CAmount SUPPLY_TOTAL{COINBASE_MATURITY * 50 * COIN};
const CAmount SUPPLY_TOTAL{Params().GetConsensus().nCoinbaseMaturity * 50 * COIN};

SetMempoolConstraints(*node.args, fuzzed_data_provider);
CTxMemPool tx_pool_{MakeMempool(fuzzed_data_provider, node)};
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/utxo_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const std::vector<std::shared_ptr<CBlock>>* g_chain;
void initialize_chain()
{
const auto params{CreateChainParams(ArgsManager{}, CBaseChainParams::REGTEST)};
static const auto chain{CreateBlockChain(2 * COINBASE_MATURITY, *params)};
static const auto chain{CreateBlockChain(2 * Params().GetConsensus().nCoinbaseMaturity, *params)};
g_chain = &chain;
}

Expand Down Expand Up @@ -58,7 +58,7 @@ FUZZ_TARGET_INIT(utxo_snapshot, initialize_chain)
if (fuzzed_data_provider.ConsumeBool()) {
for (const auto& block : *g_chain) {
BlockValidationState dummy;
bool processed{chainman.ProcessNewBlockHeaders({*block}, true, dummy)};
bool processed{chainman.ProcessNewBlockHeaders({*block}, true, dummy, false)};
Assert(processed);
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
Assert(index);
Expand Down
1 change: 0 additions & 1 deletion src/wallet/test/fuzz/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ FUZZ_TARGET(coinselection)
FastRandomContext fast_random_context{ConsumeUInt256(fuzzed_data_provider)};
CoinSelectionParams coin_params{fast_random_context};
coin_params.m_subtract_fee_outputs = subtract_fee_outputs;
coin_params.m_long_term_feerate = long_term_fee_rate;
coin_params.m_effective_feerate = effective_fee_rate;
coin_params.change_output_size = fuzzed_data_provider.ConsumeIntegralInRange<int>(10, 1000);
coin_params.m_change_fee = effective_fee_rate.GetFee(coin_params.change_output_size);
Expand Down

0 comments on commit febda8a

Please sign in to comment.