LCOV - code coverage report
Current view: top level - src/test/fuzz - chain.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 3 32 9.4 %
Date: 2023-09-26 12:08:55 Functions: 3 5 60.0 %

          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           4 : FUZZ_TARGET(chain)
      15             : {
      16           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      17           0 :     std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
      18           0 :     if (!disk_block_index) {
      19           0 :         return;
      20             :     }
      21             : 
      22           0 :     const uint256 zero{};
      23           0 :     disk_block_index->phashBlock = &zero;
      24             :     {
      25           2 :         LOCK(::cs_main);
      26           0 :         (void)disk_block_index->ConstructBlockHash();
      27           0 :         (void)disk_block_index->GetBlockPos();
      28           0 :         (void)disk_block_index->GetBlockTime();
      29           0 :         (void)disk_block_index->GetBlockTimeMax();
      30           0 :         (void)disk_block_index->GetMedianTimePast();
      31           0 :         (void)disk_block_index->GetUndoPos();
      32           0 :         (void)disk_block_index->HaveTxsDownloaded();
      33           0 :         (void)disk_block_index->IsValid();
      34           0 :     }
      35             : 
      36           0 :     const CBlockHeader block_header = disk_block_index->GetBlockHeader();
      37           0 :     (void)CDiskBlockIndex{*disk_block_index};
      38           0 :     (void)disk_block_index->BuildSkip();
      39             : 
      40           0 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
      41           0 :         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           0 :         if (block_status & ~BLOCK_VALID_MASK) {
      58           0 :             continue;
      59             :         }
      60           0 :         WITH_LOCK(::cs_main, (void)disk_block_index->RaiseValidity(block_status));
      61           0 :     }
      62             : 
      63           0 :     CBlockIndex block_index{block_header};
      64           0 :     block_index.phashBlock = &zero;
      65           0 :     (void)block_index.GetBlockHash();
      66           0 :     (void)block_index.ToString();
      67           0 : }

Generated by: LCOV version 1.14