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

             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 <test/fuzz/FuzzedDataProvider.h>
       6                 :             : #include <test/fuzz/fuzz.h>
       7                 :             : 
       8                 :             : #include <node/psbt.h>
       9                 :             : #include <psbt.h>
      10                 :             : #include <pubkey.h>
      11                 :             : #include <script/script.h>
      12                 :             : #include <streams.h>
      13                 :             : #include <util/check.h>
      14                 :             : 
      15                 :             : #include <cstdint>
      16                 :             : #include <optional>
      17                 :             : #include <string>
      18                 :             : #include <vector>
      19                 :             : 
      20                 :             : using node::AnalyzePSBT;
      21                 :             : using node::PSBTAnalysis;
      22                 :             : using node::PSBTInputAnalysis;
      23                 :             : 
      24         [ #  # ]:           0 : FUZZ_TARGET(psbt)
      25                 :             : {
      26                 :           0 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      27                 :           0 :     PartiallySignedTransaction psbt_mut;
      28         [ #  # ]:           0 :     std::string error;
      29         [ #  # ]:           0 :     auto str = fuzzed_data_provider.ConsumeRandomLengthString();
      30   [ #  #  #  # ]:           0 :     if (!DecodeRawPSBT(psbt_mut, MakeByteSpan(str), error)) {
      31                 :           0 :         return;
      32                 :             :     }
      33         [ #  # ]:           0 :     const PartiallySignedTransaction psbt = psbt_mut;
      34                 :             : 
      35   [ #  #  #  # ]:           0 :     const PSBTAnalysis analysis = AnalyzePSBT(psbt);
      36         [ #  # ]:           0 :     (void)PSBTRoleName(analysis.next);
      37         [ #  # ]:           0 :     for (const PSBTInputAnalysis& input_analysis : analysis.inputs) {
      38         [ #  # ]:           0 :         (void)PSBTRoleName(input_analysis.next);
      39                 :             :     }
      40                 :             : 
      41         [ #  # ]:           0 :     (void)psbt.IsNull();
      42                 :             : 
      43         [ #  # ]:           0 :     std::optional<CMutableTransaction> tx = psbt.tx;
      44         [ #  # ]:           0 :     if (tx) {
      45         [ #  # ]:           0 :         const CMutableTransaction& mtx = *tx;
      46         [ #  # ]:           0 :         const PartiallySignedTransaction psbt_from_tx{mtx};
      47                 :           0 :     }
      48                 :             : 
      49         [ #  # ]:           0 :     for (const PSBTInput& input : psbt.inputs) {
      50         [ #  # ]:           0 :         (void)PSBTInputSigned(input);
      51         [ #  # ]:           0 :         (void)input.IsNull();
      52                 :             :     }
      53         [ #  # ]:           0 :     (void)CountPSBTUnsignedInputs(psbt);
      54                 :             : 
      55         [ #  # ]:           0 :     for (const PSBTOutput& output : psbt.outputs) {
      56         [ #  # ]:           0 :         (void)output.IsNull();
      57                 :             :     }
      58                 :             : 
      59         [ #  # ]:           0 :     for (size_t i = 0; i < psbt.tx->vin.size(); ++i) {
      60                 :           0 :         CTxOut tx_out;
      61   [ #  #  #  # ]:           0 :         if (psbt.GetInputUTXO(tx_out, i)) {
      62                 :           0 :             (void)tx_out.IsNull();
      63         [ #  # ]:           0 :             (void)tx_out.ToString();
      64                 :             :         }
      65                 :           0 :     }
      66                 :             : 
      67         [ #  # ]:           0 :     psbt_mut = psbt;
      68         [ #  # ]:           0 :     (void)FinalizePSBT(psbt_mut);
      69                 :             : 
      70         [ #  # ]:           0 :     psbt_mut = psbt;
      71         [ #  # ]:           0 :     CMutableTransaction result;
      72   [ #  #  #  # ]:           0 :     if (FinalizeAndExtractPSBT(psbt_mut, result)) {
      73         [ #  # ]:           0 :         const PartiallySignedTransaction psbt_from_tx{result};
      74                 :           0 :     }
      75                 :             : 
      76                 :           0 :     PartiallySignedTransaction psbt_merge;
      77         [ #  # ]:           0 :     str = fuzzed_data_provider.ConsumeRandomLengthString();
      78   [ #  #  #  # ]:           0 :     if (!DecodeRawPSBT(psbt_merge, MakeByteSpan(str), error)) {
      79         [ #  # ]:           0 :         psbt_merge = psbt;
      80                 :             :     }
      81         [ #  # ]:           0 :     psbt_mut = psbt;
      82         [ #  # ]:           0 :     (void)psbt_mut.Merge(psbt_merge);
      83         [ #  # ]:           0 :     psbt_mut = psbt;
      84   [ #  #  #  #  :           0 :     (void)CombinePSBTs(psbt_mut, {psbt_mut, psbt_merge});
             #  #  #  # ]
      85         [ #  # ]:           0 :     psbt_mut = psbt;
      86         [ #  # ]:           0 :     for (unsigned int i = 0; i < psbt_merge.tx->vin.size(); ++i) {
      87         [ #  # ]:           0 :         (void)psbt_mut.AddInput(psbt_merge.tx->vin[i], psbt_merge.inputs[i]);
      88                 :             :     }
      89         [ #  # ]:           0 :     for (unsigned int i = 0; i < psbt_merge.tx->vout.size(); ++i) {
      90   [ #  #  #  # ]:           0 :         Assert(psbt_mut.AddOutput(psbt_merge.tx->vout[i], psbt_merge.outputs[i]));
      91                 :             :     }
      92         [ #  # ]:           0 :     psbt_mut.unknown.insert(psbt_merge.unknown.begin(), psbt_merge.unknown.end());
      93   [ #  #  #  #  :           0 : }
             #  #  #  # ]
        

Generated by: LCOV version 2.0-1