LCOV - code coverage report
Current view: top level - src/test/fuzz - block_header.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 0.0 % 27 0
Test Date: 2024-08-28 04:44:32 Functions: 0.0 % 2 0
Branches: 0.0 % 30 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020 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 <primitives/block.h>
       6                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       7                 :             : #include <test/fuzz/fuzz.h>
       8                 :             : #include <test/fuzz/util.h>
       9                 :             : #include <uint256.h>
      10                 :             : 
      11                 :             : #include <cassert>
      12                 :             : #include <cstdint>
      13                 :             : #include <optional>
      14                 :             : #include <string>
      15                 :             : #include <vector>
      16                 :             : 
      17         [ #  # ]:           0 : FUZZ_TARGET(block_header)
      18                 :             : {
      19                 :           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      20                 :           0 :     const std::optional<CBlockHeader> block_header = ConsumeDeserializable<CBlockHeader>(fuzzed_data_provider);
      21         [ #  # ]:           0 :     if (!block_header) {
      22                 :             :         return;
      23                 :             :     }
      24                 :           0 :     {
      25                 :           0 :         const uint256 hash = block_header->GetHash();
      26                 :           0 :         constexpr uint256 u256_max{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"};
      27         [ #  # ]:           0 :         assert(hash != u256_max);
      28                 :           0 :         assert(block_header->GetBlockTime() == block_header->nTime);
      29                 :           0 :         assert(block_header->IsNull() == (block_header->nBits == 0));
      30                 :             :     }
      31                 :           0 :     {
      32                 :           0 :         CBlockHeader mut_block_header = *block_header;
      33                 :           0 :         mut_block_header.SetNull();
      34         [ #  # ]:           0 :         assert(mut_block_header.IsNull());
      35                 :           0 :         CBlock block{*block_header};
      36   [ #  #  #  #  :           0 :         assert(block.GetBlockHeader().GetHash() == block_header->GetHash());
                   #  # ]
      37         [ #  # ]:           0 :         (void)block.ToString();
      38                 :           0 :         block.SetNull();
      39   [ #  #  #  #  :           0 :         assert(block.GetBlockHeader().GetHash() == mut_block_header.GetHash());
                   #  # ]
      40                 :           0 :     }
      41                 :           0 :     {
      42                 :           0 :         std::optional<CBlockLocator> block_locator = ConsumeDeserializable<CBlockLocator>(fuzzed_data_provider);
      43         [ #  # ]:           0 :         if (block_locator) {
      44         [ #  # ]:           0 :             (void)block_locator->IsNull();
      45         [ #  # ]:           0 :             block_locator->SetNull();
      46         [ #  # ]:           0 :             assert(block_locator->IsNull());
      47                 :             :         }
      48                 :           0 :     }
      49                 :             : }
        

Generated by: LCOV version 2.0-1