LCOV - code coverage report
Current view: top level - src/test/fuzz - transaction.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 95.3 % 64 61
Test Date: 2024-09-01 05:20:30 Functions: 75.0 % 4 3
Branches: 54.9 % 102 56

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2019-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 <chainparams.h>
       6                 :             : #include <coins.h>
       7                 :             : #include <consensus/tx_check.h>
       8                 :             : #include <consensus/tx_verify.h>
       9                 :             : #include <consensus/validation.h>
      10                 :             : #include <core_io.h>
      11                 :             : #include <core_memusage.h>
      12                 :             : #include <policy/policy.h>
      13                 :             : #include <policy/settings.h>
      14                 :             : #include <primitives/transaction.h>
      15                 :             : #include <streams.h>
      16                 :             : #include <test/fuzz/fuzz.h>
      17                 :             : #include <univalue.h>
      18                 :             : #include <util/chaintype.h>
      19                 :             : #include <util/rbf.h>
      20                 :             : #include <validation.h>
      21                 :             : 
      22                 :             : #include <cassert>
      23                 :             : 
      24                 :           0 : void initialize_transaction()
      25                 :             : {
      26                 :           0 :     SelectParams(ChainType::REGTEST);
      27                 :           0 : }
      28                 :             : 
      29         [ +  - ]:        1630 : FUZZ_TARGET(transaction, .init = initialize_transaction)
      30                 :             : {
      31                 :        1628 :     DataStream ds{buffer};
      32                 :        1628 :     bool valid_tx = true;
      33         [ +  - ]:        3256 :     const CTransaction tx = [&] {
      34                 :             :         try {
      35         [ +  + ]:        1628 :             return CTransaction(deserialize, TX_WITH_WITNESS, ds);
      36         [ -  + ]:         103 :         } catch (const std::ios_base::failure&) {
      37                 :         103 :             valid_tx = false;
      38   [ +  -  +  - ]:         103 :             return CTransaction{CMutableTransaction{}};
      39         [ #  # ]:         103 :         }
      40                 :        1731 :     }();
      41                 :        1628 :     bool valid_mutable_tx = true;
      42   [ +  -  +  - ]:        1628 :     DataStream ds_mtx{buffer};
      43         [ +  - ]:        1628 :     CMutableTransaction mutable_tx;
      44                 :             :     try {
      45   [ +  -  +  + ]:        1628 :         ds_mtx >> TX_WITH_WITNESS(mutable_tx);
      46         [ -  + ]:        1628 :     } catch (const std::ios_base::failure&) {
      47                 :         103 :         valid_mutable_tx = false;
      48         [ +  - ]:         103 :     }
      49         [ +  - ]:        1628 :     assert(valid_tx == valid_mutable_tx);
      50         [ +  + ]:        1628 :     if (!valid_tx) {
      51                 :         103 :         return;
      52                 :             :     }
      53                 :             : 
      54                 :             :     {
      55                 :        1525 :         TxValidationState state_with_dupe_check;
      56         [ +  - ]:        1525 :         const bool res{CheckTransaction(tx, state_with_dupe_check)};
      57   [ +  -  +  - ]:        1525 :         Assert(res == state_with_dupe_check.IsValid());
      58                 :        1525 :     }
      59                 :             : 
      60         [ +  - ]:        1525 :     const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE};
      61                 :        1525 :     std::string reason;
      62         [ +  - ]:        1525 :     const bool is_standard_with_permit_bare_multisig = IsStandardTx(tx, std::nullopt, /* permit_bare_multisig= */ true, dust_relay_fee, reason);
      63         [ +  - ]:        1525 :     const bool is_standard_without_permit_bare_multisig = IsStandardTx(tx, std::nullopt, /* permit_bare_multisig= */ false, dust_relay_fee, reason);
      64         [ +  + ]:        1525 :     if (is_standard_without_permit_bare_multisig) {
      65         [ +  - ]:          37 :         assert(is_standard_with_permit_bare_multisig);
      66                 :          37 :     }
      67                 :             : 
      68         [ +  - ]:        1525 :     (void)tx.GetHash();
      69         [ +  - ]:        1525 :     (void)tx.GetTotalSize();
      70                 :             :     try {
      71         [ +  + ]:        1525 :         (void)tx.GetValueOut();
      72         [ -  + ]:        1525 :     } catch (const std::runtime_error&) {
      73         [ +  - ]:        1068 :     }
      74         [ +  - ]:        1525 :     (void)tx.GetWitnessHash();
      75         [ +  - ]:        1525 :     (void)tx.HasWitness();
      76         [ +  - ]:        1525 :     (void)tx.IsCoinBase();
      77         [ +  - ]:        1525 :     (void)tx.IsNull();
      78         [ +  - ]:        1525 :     (void)tx.ToString();
      79                 :             : 
      80         [ +  - ]:        1525 :     (void)EncodeHexTx(tx);
      81         [ +  - ]:        1525 :     (void)GetLegacySigOpCount(tx);
      82         [ +  - ]:        1525 :     (void)GetTransactionWeight(tx);
      83         [ +  - ]:        1525 :     (void)GetVirtualTransactionSize(tx);
      84         [ +  - ]:        1525 :     (void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024);
      85         [ +  - ]:        1525 :     (void)RecursiveDynamicUsage(tx);
      86         [ +  - ]:        1525 :     (void)SignalsOptInRBF(tx);
      87                 :             : 
      88                 :        1525 :     CCoinsView coins_view;
      89         [ +  - ]:        1525 :     const CCoinsViewCache coins_view_cache(&coins_view);
      90         [ +  - ]:        1525 :     (void)AreInputsStandard(tx, coins_view_cache);
      91         [ +  - ]:        1525 :     (void)IsWitnessStandard(tx, coins_view_cache);
      92                 :             : 
      93   [ +  -  +  + ]:        1525 :     if (tx.GetTotalSize() < 250'000) { // Avoid high memory usage (with msan) due to json encoding
      94                 :             :         {
      95         [ +  - ]:        1457 :             UniValue u{UniValue::VOBJ};
      96         [ +  - ]:        1457 :             TxToUniv(tx, /*block_hash=*/uint256::ZERO, /*entry=*/u);
      97                 :        1457 :         }
      98                 :             :         {
      99         [ +  - ]:        1457 :             UniValue u{UniValue::VOBJ};
     100         [ +  - ]:        1457 :             TxToUniv(tx, /*block_hash=*/uint256::ONE, /*entry=*/u);
     101                 :        1457 :         }
     102                 :        1457 :     }
     103         [ -  + ]:        2799 : }
        

Generated by: LCOV version 2.0-1