LCOV - code coverage report
Current view: top level - src/test/fuzz - block.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 49 49 100.0 %
Date: 2023-10-05 15:40:34 Functions: 7 7 100.0 %
Branches: 71 130 54.6 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2019-2021 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 <chainparams.h>
       6                 :            : #include <consensus/merkle.h>
       7                 :            : #include <consensus/validation.h>
       8                 :            : #include <core_io.h>
       9                 :            : #include <core_memusage.h>
      10                 :            : #include <primitives/block.h>
      11                 :            : #include <pubkey.h>
      12                 :            : #include <streams.h>
      13                 :            : #include <test/fuzz/fuzz.h>
      14                 :            : #include <util/chaintype.h>
      15                 :            : #include <validation.h>
      16                 :            : #include <version.h>
      17         [ +  - ]:        173 : 
      18         [ +  - ]:        173 : #include <cassert>
      19                 :            : #include <string>
      20                 :            : 
      21                 :          1 : void initialize_block()
      22                 :            : {
      23                 :          1 :     SelectParams(ChainType::REGTEST);
      24                 :          1 : }
      25                 :            : 
      26   [ +  -  -  + ]:        662 : FUZZ_TARGET(block, .init = initialize_block)
      27                 :            : {
      28                 :        316 :     CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
      29         [ +  - ]:        316 :     CBlock block;
      30                 :            :     try {
      31                 :            :         int nVersion;
      32         [ +  + ]:        316 :         ds >> nVersion;
      33         [ +  - ]:        315 :         ds.SetVersion(nVersion);
      34         [ +  + ]:        315 :         ds >> block;
      35         [ +  - ]:        316 :     } catch (const std::ios_base::failure&) {
      36                 :            :         return;
      37         [ +  - ]:         46 :     }
      38   [ +  -  +  - ]:        270 :     const Consensus::Params& consensus_params = Params().GetConsensus();
      39                 :        270 :     BlockValidationState validation_state_pow_and_merkle;
      40         [ +  - ]:        270 :     const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true);
      41   [ +  -  +  +  :        270 :     assert(validation_state_pow_and_merkle.IsValid() || validation_state_pow_and_merkle.IsInvalid() || validation_state_pow_and_merkle.IsError());
          +  -  -  +  #  
                #  +  - ]
      42   [ +  -  +  - ]:        270 :     (void)validation_state_pow_and_merkle.Error("");
      43                 :        270 :     BlockValidationState validation_state_pow;
      44         [ +  - ]:        270 :     const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false);
      45   [ +  -  +  +  :        270 :     assert(validation_state_pow.IsValid() || validation_state_pow.IsInvalid() || validation_state_pow.IsError());
          +  -  -  +  #  
                #  +  - ]
      46                 :        270 :     BlockValidationState validation_state_merkle;
      47         [ +  - ]:        270 :     const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true);
      48   [ +  -  +  +  :        270 :     assert(validation_state_merkle.IsValid() || validation_state_merkle.IsInvalid() || validation_state_merkle.IsError());
          +  -  -  +  #  
                #  +  - ]
      49                 :        270 :     BlockValidationState validation_state_none;
      50         [ +  - ]:        270 :     const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false);
      51   [ +  -  +  +  :        270 :     assert(validation_state_none.IsValid() || validation_state_none.IsInvalid() || validation_state_none.IsError());
          +  -  -  +  #  
                #  +  - ]
      52         [ +  + ]:        270 :     if (valid_incl_pow_and_merkle) {
      53   [ +  -  -  +  :         27 :         assert(valid_incl_pow && valid_incl_merkle && valid_incl_none);
                   +  - ]
      54   [ +  +  +  + ]:        270 :     } else if (valid_incl_merkle || valid_incl_pow) {
      55         [ +  - ]:         35 :         assert(valid_incl_none);
      56                 :         35 :     }
      57         [ +  - ]:        270 :     (void)block.GetHash();
      58         [ +  - ]:        270 :     (void)block.ToString();
      59         [ +  - ]:        270 :     (void)BlockMerkleRoot(block);
      60         [ +  + ]:        270 :     if (!block.vtx.empty()) {
      61         [ +  - ]:        266 :         (void)BlockWitnessMerkleRoot(block);
      62                 :        266 :     }
      63         [ +  - ]:        270 :     (void)GetBlockWeight(block);
      64         [ +  - ]:        270 :     (void)GetWitnessCommitmentIndex(block);
      65         [ +  - ]:        270 :     const size_t raw_memory_size = RecursiveDynamicUsage(block);
      66   [ +  -  +  - ]:        270 :     const size_t raw_memory_size_as_shared_ptr = RecursiveDynamicUsage(std::make_shared<CBlock>(block));
      67         [ +  - ]:        270 :     assert(raw_memory_size_as_shared_ptr > raw_memory_size);
      68         [ +  - ]:        270 :     CBlock block_copy = block;
      69         [ +  - ]:        270 :     block_copy.SetNull();
      70         [ +  - ]:        270 :     const bool is_null = block_copy.IsNull();
      71         [ +  - ]:        270 :     assert(is_null);
      72         [ -  + ]:        362 : }

Generated by: LCOV version 1.14