LCOV - code coverage report
Current view: top level - src/test/fuzz - block.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 44 44
Test Date: 2024-12-04 04:00:22 Functions: 100.0 % 3 3
Branches: 54.8 % 84 46

             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                 :             : 
      17                 :             : #include <cassert>
      18                 :             : #include <string>
      19                 :             : 
      20                 :           1 : void initialize_block()
      21                 :             : {
      22                 :           1 :     SelectParams(ChainType::REGTEST);
      23                 :           1 : }
      24                 :             : 
      25         [ +  - ]:         973 : FUZZ_TARGET(block, .init = initialize_block)
      26                 :             : {
      27                 :         561 :     DataStream ds{buffer};
      28                 :         561 :     CBlock block;
      29                 :         561 :     try {
      30         [ +  + ]:         561 :         ds >> TX_WITH_WITNESS(block);
      31         [ -  + ]:          74 :     } catch (const std::ios_base::failure&) {
      32                 :          74 :         return;
      33                 :          74 :     }
      34   [ +  -  +  - ]:         487 :     const Consensus::Params& consensus_params = Params().GetConsensus();
      35         [ +  - ]:         487 :     BlockValidationState validation_state_pow_and_merkle;
      36         [ +  - ]:         487 :     const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true);
      37   [ +  +  -  +  :         487 :     assert(validation_state_pow_and_merkle.IsValid() || validation_state_pow_and_merkle.IsInvalid() || validation_state_pow_and_merkle.IsError());
                   -  - ]
      38         [ +  - ]:         974 :     (void)validation_state_pow_and_merkle.Error("");
      39         [ +  - ]:         487 :     BlockValidationState validation_state_pow;
      40         [ +  - ]:         487 :     const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false);
      41   [ +  +  -  +  :         487 :     assert(validation_state_pow.IsValid() || validation_state_pow.IsInvalid() || validation_state_pow.IsError());
                   -  - ]
      42         [ +  - ]:         487 :     BlockValidationState validation_state_merkle;
      43         [ +  - ]:         487 :     const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true);
      44   [ +  +  -  +  :         487 :     assert(validation_state_merkle.IsValid() || validation_state_merkle.IsInvalid() || validation_state_merkle.IsError());
                   -  - ]
      45         [ +  - ]:         487 :     BlockValidationState validation_state_none;
      46         [ +  - ]:         487 :     const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false);
      47   [ +  +  -  +  :         487 :     assert(validation_state_none.IsValid() || validation_state_none.IsInvalid() || validation_state_none.IsError());
                   -  - ]
      48         [ +  + ]:         487 :     if (valid_incl_pow_and_merkle) {
      49   [ +  -  -  + ]:          13 :         assert(valid_incl_pow && valid_incl_merkle && valid_incl_none);
      50         [ +  + ]:         474 :     } else if (valid_incl_merkle || valid_incl_pow) {
      51         [ -  + ]:          52 :         assert(valid_incl_none);
      52                 :             :     }
      53         [ +  - ]:         487 :     (void)block.GetHash();
      54         [ +  - ]:         487 :     (void)block.ToString();
      55         [ +  - ]:         487 :     (void)BlockMerkleRoot(block);
      56         [ +  + ]:         487 :     if (!block.vtx.empty()) {
      57         [ +  - ]:         478 :         (void)BlockWitnessMerkleRoot(block);
      58                 :             :     }
      59                 :         487 :     (void)GetBlockWeight(block);
      60                 :         487 :     (void)GetWitnessCommitmentIndex(block);
      61                 :         487 :     const size_t raw_memory_size = RecursiveDynamicUsage(block);
      62   [ +  -  +  - ]:         487 :     const size_t raw_memory_size_as_shared_ptr = RecursiveDynamicUsage(std::make_shared<CBlock>(block));
      63         [ -  + ]:         487 :     assert(raw_memory_size_as_shared_ptr > raw_memory_size);
      64         [ +  - ]:         487 :     CBlock block_copy = block;
      65                 :         487 :     block_copy.SetNull();
      66         [ -  + ]:         487 :     const bool is_null = block_copy.IsNull();
      67         [ -  + ]:         487 :     assert(is_null);
      68                 :        2996 : }
        

Generated by: LCOV version 2.0-1