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

           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         [ -  + ]:        390 : FUZZ_TARGET(block_header)
      18                 :            : {
      19                 :         44 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      20                 :         44 :     const std::optional<CBlockHeader> block_header = ConsumeDeserializable<CBlockHeader>(fuzzed_data_provider);
      21         [ +  + ]:         44 :     if (!block_header) {
      22                 :         21 :         return;
      23                 :            :     }
      24                 :            :     {
      25         [ +  - ]:        196 :         const uint256 hash = block_header->GetHash();
      26   [ +  +  -  +  :         23 :         static const uint256 u256_max(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
                   -  + ]
      27         [ +  - ]:         23 :         assert(hash != u256_max);
      28         [ +  - ]:         23 :         assert(block_header->GetBlockTime() == block_header->nTime);
      29         [ +  - ]:         23 :         assert(block_header->IsNull() == (block_header->nBits == 0));
      30                 :            :     }
      31                 :            :     {
      32                 :         23 :         CBlockHeader mut_block_header = *block_header;
      33                 :         23 :         mut_block_header.SetNull();
      34         [ +  - ]:         23 :         assert(mut_block_header.IsNull());
      35                 :         23 :         CBlock block{*block_header};
      36   [ +  -  +  -  :         23 :         assert(block.GetBlockHeader().GetHash() == block_header->GetHash());
          +  -  +  -  +  
                -  +  - ]
      37         [ +  - ]:         23 :         (void)block.ToString();
      38         [ +  - ]:         23 :         block.SetNull();
      39   [ +  -  +  -  :         23 :         assert(block.GetBlockHeader().GetHash() == mut_block_header.GetHash());
          +  -  +  -  +  
                      - ]
      40                 :         23 :     }
      41                 :            :     {
      42                 :         23 :         std::optional<CBlockLocator> block_locator = ConsumeDeserializable<CBlockLocator>(fuzzed_data_provider);
      43         [ +  + ]:         23 :         if (block_locator) {
      44   [ +  -  +  - ]:          2 :             (void)block_locator->IsNull();
      45   [ +  -  +  - ]:          2 :             block_locator->SetNull();
      46   [ +  -  +  -  :          2 :             assert(block_locator->IsNull());
                   +  - ]
      47                 :          2 :         }
      48                 :         23 :     }
      49                 :         44 : }

Generated by: LCOV version 1.14