LCOV - code coverage report
Current view: top level - src/test/fuzz - policy_estimator_io.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 27 27
Test Date: 2026-08-29 05:53:03 Functions: 100.0 % 3 3
Branches: 63.0 % 46 29

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-present 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 <policy/fees/block_policy_estimator.h>
       6                 :             : #include <policy/fees/estimator_args.h>
       7                 :             : #include <policy/fees/mempool_estimator.h>
       8                 :             : #include <streams.h>
       9                 :             : #include <test/fuzz/FuzzedDataProvider.h>
      10                 :             : #include <test/fuzz/fuzz.h>
      11                 :             : #include <test/fuzz/util.h>
      12                 :             : #include <test/util/setup_common.h>
      13                 :             : 
      14                 :             : #include <memory>
      15                 :             : 
      16                 :             : namespace {
      17                 :             : const TestingSetup* g_setup;
      18                 :             : } // namespace
      19                 :             : 
      20                 :           1 : void initialize_policy_estimator_io()
      21                 :             : {
      22                 :           1 :     static const auto testing_setup{
      23   [ +  -  +  -  :           3 :         MakeNoLogFileContext<const TestingSetup>(ChainType::REGTEST, TestOpts{.setup_net = false})};
                   +  - ]
      24                 :           1 :     g_setup = testing_setup.get();
      25                 :           1 : }
      26                 :             : 
      27         [ +  - ]:         940 : FUZZ_TARGET(policy_estimator_io, .init = initialize_policy_estimator_io)
      28                 :             : {
      29         [ +  + ]:         464 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      30         [ +  + ]:         464 :     FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
      31                 :             :     // Reuse estimators across runs to avoid costly object creation.
      32                 :         464 :     static CBlockPolicyEstimator block_policy_estimator{
      33   [ +  +  +  -  :         466 :         BlockPolicyFeeEstPath(*g_setup->m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES};
             +  -  +  - ]
      34                 :         464 :     {
      35                 :         928 :         AutoFile fuzzed_auto_file_block_policy{fuzzed_file_provider.open()};
      36   [ +  -  +  + ]:         464 :         if (block_policy_estimator.Read(fuzzed_auto_file_block_policy)) {
      37         [ +  - ]:         110 :             block_policy_estimator.Write(fuzzed_auto_file_block_policy);
      38                 :             :         }
      39         [ +  - ]:         464 :         (void)fuzzed_auto_file_block_policy.fclose();
      40                 :         464 :     }
      41                 :         464 :     static MemPoolFeeRateEstimator mempool_feerate_estimator{
      42         [ +  - ]:           2 :         MempoolPolicyEstimatorPath(*g_setup->m_node.args),
      43         [ +  - ]:           1 :         *g_setup->m_node.mempool,
      44   [ +  +  +  -  :         466 :         *g_setup->m_node.chainman};
                   +  - ]
      45                 :         464 :     {
      46                 :         928 :         AutoFile fuzzed_auto_file_mempool_policy{fuzzed_file_provider.open()};
      47   [ +  -  +  + ]:         464 :         if (mempool_feerate_estimator.Read(fuzzed_auto_file_mempool_policy)) {
      48         [ +  - ]:           8 :             mempool_feerate_estimator.Write(fuzzed_auto_file_mempool_policy);
      49                 :             :         }
      50                 :             :         // Write() does not take ownership; close explicitly because it may
      51                 :             :         // have written to the fuzzed file.
      52         [ +  - ]:         464 :         (void)fuzzed_auto_file_mempool_policy.fclose();
      53                 :         464 :     }
      54                 :         464 : }
        

Generated by: LCOV version 2.5.0-full