LCOV - code coverage report
Current view: top level - src/test/fuzz - rbf.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 4 34 11.8 %
Date: 2023-09-26 12:08:55 Functions: 5 7 71.4 %

          Line data    Source code
       1             : // Copyright (c) 2020-2022 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <node/mempool_args.h>
       6             : #include <policy/rbf.h>
       7             : #include <primitives/transaction.h>
       8             : #include <sync.h>
       9             : #include <test/fuzz/FuzzedDataProvider.h>
      10             : #include <test/fuzz/fuzz.h>
      11             : #include <test/fuzz/util.h>
      12             : #include <test/fuzz/util/mempool.h>
      13             : #include <test/util/setup_common.h>
      14             : #include <test/util/txmempool.h>
      15             : #include <txmempool.h>
      16             : 
      17           2 : #include <cstdint>
      18           2 : #include <optional>
      19             : #include <string>
      20             : #include <vector>
      21             : 
      22             : namespace {
      23             : const BasicTestingSetup* g_setup;
      24             : } // namespace
      25             : 
      26           0 : void initialize_rbf()
      27             : {
      28           0 :     static const auto testing_setup = MakeNoLogFileContext<>();
      29           0 :     g_setup = testing_setup.get();
      30           0 : }
      31             : 
      32           4 : FUZZ_TARGET(rbf, .init = initialize_rbf)
      33             : {
      34           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      35           0 :     SetMockTime(ConsumeTime(fuzzed_data_provider));
      36           0 :     std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
      37           0 :     if (!mtx) {
      38           0 :         return;
      39             :     }
      40             : 
      41           0 :     CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};
      42             : 
      43           0 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
      44             :     {
      45           0 :         const std::optional<CMutableTransaction> another_mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
      46           0 :         if (!another_mtx) {
      47           0 :             break;
      48             :         }
      49           0 :         const CTransaction another_tx{*another_mtx};
      50           0 :         if (fuzzed_data_provider.ConsumeBool() && !mtx->vin.empty()) {
      51           0 :             mtx->vin[0].prevout = COutPoint{another_tx.GetHash(), 0};
      52           0 :         }
      53           0 :         LOCK2(cs_main, pool.cs);
      54           0 :         pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, another_tx));
      55           0 :     }
      56           0 :     const CTransaction tx{*mtx};
      57           0 :     if (fuzzed_data_provider.ConsumeBool()) {
      58           0 :         LOCK2(cs_main, pool.cs);
      59           0 :         pool.addUnchecked(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
      60           0 :     }
      61             :     {
      62           0 :         LOCK(pool.cs);
      63           0 :         (void)IsRBFOptIn(tx, pool);
      64           0 :     }
      65           0 : }

Generated by: LCOV version 1.14