Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/coins_view.cpp
Show All 21 Lines | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <limits> | #include <limits> | ||||
#include <optional> | #include <optional> | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
namespace { | namespace { | ||||
const TestingSetup *g_setup; | |||||
const Coin EMPTY_COIN{}; | const Coin EMPTY_COIN{}; | ||||
bool operator==(const Coin &a, const Coin &b) { | bool operator==(const Coin &a, const Coin &b) { | ||||
if (a.IsSpent() && b.IsSpent()) { | if (a.IsSpent() && b.IsSpent()) { | ||||
return true; | return true; | ||||
} | } | ||||
return a.IsCoinBase() == b.IsCoinBase() && a.GetHeight() == b.GetHeight() && | return a.IsCoinBase() == b.IsCoinBase() && a.GetHeight() == b.GetHeight() && | ||||
a.GetTxOut() == b.GetTxOut(); | a.GetTxOut() == b.GetTxOut(); | ||||
} | } | ||||
} // namespace | } // namespace | ||||
void initialize() { | void initialize() { | ||||
static const auto testing_setup = MakeFuzzingContext<const TestingSetup>(); | static const auto testing_setup = MakeFuzzingContext<const TestingSetup>(); | ||||
g_setup = testing_setup.get(); | |||||
} | } | ||||
void test_one_input(const std::vector<uint8_t> &buffer) { | void test_one_input(const std::vector<uint8_t> &buffer) { | ||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; | ||||
CCoinsView backend_coins_view; | CCoinsView backend_coins_view; | ||||
CCoinsViewCache coins_view_cache{&backend_coins_view}; | CCoinsViewCache coins_view_cache{&backend_coins_view}; | ||||
COutPoint random_out_point; | COutPoint random_out_point; | ||||
Coin random_coin; | Coin random_coin; | ||||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | if (fuzzed_data_provider.ConsumeBool()) { | ||||
} | } | ||||
case 3: { | case 3: { | ||||
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED}; | CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED}; | ||||
bool expected_code_path = false; | bool expected_code_path = false; | ||||
try { | try { | ||||
(void)GetUTXOStats( | (void)GetUTXOStats( | ||||
&coins_view_cache, | &coins_view_cache, | ||||
WITH_LOCK(::cs_main, | WITH_LOCK(::cs_main, | ||||
return std::ref(g_chainman.m_blockman)), | return std::ref( | ||||
g_setup->m_node.chainman->m_blockman)), | |||||
stats); | stats); | ||||
} catch (const std::logic_error &) { | } catch (const std::logic_error &) { | ||||
expected_code_path = true; | expected_code_path = true; | ||||
} | } | ||||
assert(expected_code_path); | assert(expected_code_path); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |