LCOV - code coverage report
Current view: top level - src/test/fuzz - psbt.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 4 58 6.9 %
Date: 2023-09-26 12:08:55 Functions: 5 6 83.3 %

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

Generated by: LCOV version 1.14