35 const Coin EMPTY_COIN{};
46 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
47 g_setup = testing_setup.get();
65 Coin coin = random_coin;
66 bool expected_code_path =
false;
67 const bool possible_overwrite = fuzzed_data_provider.ConsumeBool();
69 coins_view_cache.AddCoin(random_out_point, std::move(coin), possible_overwrite);
70 expected_code_path = true;
71 } catch (
const std::logic_error& e) {
72 if (e.what() == std::string{
"Attempted to overwrite an unspent coin (when possible_overwrite is false)"}) {
73 assert(!possible_overwrite);
74 expected_code_path = true;
77 assert(expected_code_path);
80 (void)coins_view_cache.Flush();
83 coins_view_cache.SetBestBlock(
ConsumeUInt256(fuzzed_data_provider));
87 (void)coins_view_cache.SpendCoin(random_out_point, fuzzed_data_provider.ConsumeBool() ? &move_to :
nullptr);
90 coins_view_cache.Uncache(random_out_point);
93 if (fuzzed_data_provider.ConsumeBool()) {
96 coins_view_cache.SetBackend(backend_coins_view);
99 const std::optional<COutPoint> opt_out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);
100 if (!opt_out_point) {
103 random_out_point = *opt_out_point;
106 const std::optional<Coin> opt_coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
110 random_coin = *opt_coin;
113 const std::optional<CMutableTransaction> opt_mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
114 if (!opt_mutable_transaction) {
117 random_mutable_transaction = *opt_mutable_transaction;
123 coins_cache_entry.
flags = fuzzed_data_provider.ConsumeIntegral<
unsigned char>();
124 if (fuzzed_data_provider.ConsumeBool()) {
125 coins_cache_entry.
coin = random_coin;
127 const std::optional<Coin> opt_coin = ConsumeDeserializable<Coin>(fuzzed_data_provider);
131 coins_cache_entry.
coin = *opt_coin;
133 coins_map.emplace(random_out_point, std::move(coins_cache_entry));
135 bool expected_code_path =
false;
137 coins_view_cache.BatchWrite(coins_map, fuzzed_data_provider.ConsumeBool() ?
ConsumeUInt256(fuzzed_data_provider) : coins_view_cache.GetBestBlock());
138 expected_code_path =
true;
139 }
catch (
const std::logic_error& e) {
140 if (e.what() == std::string{
"FRESH flag misapplied to coin that exists in parent cache"}) {
141 expected_code_path =
true;
144 assert(expected_code_path);
149 const Coin& coin_using_access_coin = coins_view_cache.AccessCoin(random_out_point);
150 const bool exists_using_access_coin = !(coin_using_access_coin == EMPTY_COIN);
151 const bool exists_using_have_coin = coins_view_cache.HaveCoin(random_out_point);
152 const bool exists_using_have_coin_in_cache = coins_view_cache.HaveCoinInCache(random_out_point);
153 Coin coin_using_get_coin;
154 const bool exists_using_get_coin = coins_view_cache.GetCoin(random_out_point, coin_using_get_coin);
155 if (exists_using_get_coin) {
156 assert(coin_using_get_coin == coin_using_access_coin);
158 assert((exists_using_access_coin && exists_using_have_coin_in_cache && exists_using_have_coin && exists_using_get_coin) ||
159 (!exists_using_access_coin && !exists_using_have_coin_in_cache && !exists_using_have_coin && !exists_using_get_coin));
160 const bool exists_using_have_coin_in_backend = backend_coins_view.
HaveCoin(random_out_point);
161 if (exists_using_have_coin_in_backend) {
162 assert(exists_using_have_coin);
164 Coin coin_using_backend_get_coin;
165 if (backend_coins_view.
GetCoin(random_out_point, coin_using_backend_get_coin)) {
166 assert(exists_using_have_coin_in_backend);
167 assert(coin_using_get_coin == coin_using_backend_get_coin);
169 assert(!exists_using_have_coin_in_backend);
174 bool expected_code_path =
false;
176 (void)coins_view_cache.Cursor();
177 }
catch (
const std::logic_error&) {
178 expected_code_path =
true;
180 assert(expected_code_path);
181 (void)coins_view_cache.DynamicMemoryUsage();
182 (void)coins_view_cache.EstimateSize();
183 (void)coins_view_cache.GetBestBlock();
184 (void)coins_view_cache.GetCacheSize();
185 (void)coins_view_cache.GetHeadBlocks();
186 (void)coins_view_cache.HaveInputs(
CTransaction{random_mutable_transaction});
190 std::unique_ptr<CCoinsViewCursor> coins_view_cursor = backend_coins_view.Cursor();
191 assert(!coins_view_cursor);
192 (void)backend_coins_view.EstimateSize();
193 (void)backend_coins_view.GetBestBlock();
194 (void)backend_coins_view.GetHeadBlocks();
197 if (fuzzed_data_provider.ConsumeBool()) {
199 fuzzed_data_provider,
201 const CTransaction transaction{random_mutable_transaction};
202 bool is_spent =
false;
203 for (
const CTxOut& tx_out : transaction.vout) {
204 if (Coin{tx_out, 0, transaction.IsCoinBase()}.IsSpent()) {
213 bool expected_code_path =
false;
214 const int height{int(fuzzed_data_provider.ConsumeIntegral<uint32_t>() >> 1)};
215 const bool possible_overwrite = fuzzed_data_provider.ConsumeBool();
217 AddCoins(coins_view_cache, transaction, height, possible_overwrite);
218 expected_code_path =
true;
219 }
catch (
const std::logic_error& e) {
220 if (e.what() == std::string{
"Attempted to overwrite an unspent coin (when possible_overwrite is false)"}) {
221 assert(!possible_overwrite);
222 expected_code_path =
true;
225 assert(expected_code_path);
233 const CTransaction transaction{random_mutable_transaction};
244 if (
Consensus::CheckTxInputs(transaction, state, coins_view_cache, fuzzed_data_provider.ConsumeIntegralInRange<
int>(0, std::numeric_limits<int>::max()), tx_fee_out)) {
249 const CTransaction transaction{random_mutable_transaction};
258 const CTransaction transaction{random_mutable_transaction};
264 const auto flags{fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
273 CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
274 bool expected_code_path =
false;
277 }
catch (
const std::logic_error&) {
278 expected_code_path =
true;
280 assert(expected_code_path);