LCOV - code coverage report
Current view: top level - src/test/fuzz - chain.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 32 32 100.0 %
Date: 2023-10-05 15:40:34 Functions: 5 5 100.0 %
Branches: 27 46 58.7 %

           Branch data     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 <chain.h>
       6                 :            : #include <test/fuzz/FuzzedDataProvider.h>
       7                 :            : #include <test/fuzz/fuzz.h>
       8                 :            : #include <test/fuzz/util.h>
       9                 :            : 
      10                 :            : #include <cstdint>
      11                 :            : #include <optional>
      12                 :            : #include <vector>
      13                 :            : 
      14         [ -  + ]:        394 : FUZZ_TARGET(chain)
      15                 :            : {
      16                 :         48 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      17                 :         48 :     std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
      18         [ +  + ]:         48 :     if (!disk_block_index) {
      19                 :         21 :         return;
      20                 :            :     }
      21                 :            : 
      22                 :         27 :     const uint256 zero{};
      23                 :         27 :     disk_block_index->phashBlock = &zero;
      24                 :            :     {
      25         [ +  - ]:        200 :         LOCK(::cs_main);
      26   [ +  -  +  - ]:         27 :         (void)disk_block_index->ConstructBlockHash();
      27   [ +  -  +  - ]:         27 :         (void)disk_block_index->GetBlockPos();
      28   [ +  -  +  - ]:         27 :         (void)disk_block_index->GetBlockTime();
      29   [ +  -  +  - ]:         27 :         (void)disk_block_index->GetBlockTimeMax();
      30   [ +  -  +  - ]:         27 :         (void)disk_block_index->GetMedianTimePast();
      31   [ +  -  +  - ]:         27 :         (void)disk_block_index->GetUndoPos();
      32   [ +  -  +  - ]:         27 :         (void)disk_block_index->HaveTxsDownloaded();
      33   [ +  -  +  - ]:         27 :         (void)disk_block_index->IsValid();
      34                 :         27 :     }
      35                 :            : 
      36                 :         27 :     const CBlockHeader block_header = disk_block_index->GetBlockHeader();
      37                 :         27 :     (void)CDiskBlockIndex{*disk_block_index};
      38                 :         27 :     (void)disk_block_index->BuildSkip();
      39                 :            : 
      40   [ +  +  +  + ]:        611 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
      41                 :        584 :         const BlockStatus block_status = fuzzed_data_provider.PickValueInArray({
      42                 :            :             BlockStatus::BLOCK_VALID_UNKNOWN,
      43                 :            :             BlockStatus::BLOCK_VALID_RESERVED,
      44                 :            :             BlockStatus::BLOCK_VALID_TREE,
      45                 :            :             BlockStatus::BLOCK_VALID_TRANSACTIONS,
      46                 :            :             BlockStatus::BLOCK_VALID_CHAIN,
      47                 :            :             BlockStatus::BLOCK_VALID_SCRIPTS,
      48                 :            :             BlockStatus::BLOCK_VALID_MASK,
      49                 :            :             BlockStatus::BLOCK_HAVE_DATA,
      50                 :            :             BlockStatus::BLOCK_HAVE_UNDO,
      51                 :            :             BlockStatus::BLOCK_HAVE_MASK,
      52                 :            :             BlockStatus::BLOCK_FAILED_VALID,
      53                 :            :             BlockStatus::BLOCK_FAILED_CHILD,
      54                 :            :             BlockStatus::BLOCK_FAILED_MASK,
      55                 :            :             BlockStatus::BLOCK_OPT_WITNESS,
      56                 :            :         });
      57         [ +  + ]:        584 :         if (block_status & ~BLOCK_VALID_MASK) {
      58                 :        207 :             continue;
      59                 :            :         }
      60         [ +  - ]:        754 :         WITH_LOCK(::cs_main, (void)disk_block_index->RaiseValidity(block_status));
      61                 :        377 :     }
      62                 :            : 
      63                 :         27 :     CBlockIndex block_index{block_header};
      64                 :         27 :     block_index.phashBlock = &zero;
      65                 :         27 :     (void)block_index.GetBlockHash();
      66                 :         27 :     (void)block_index.ToString();
      67                 :         48 : }

Generated by: LCOV version 1.14