LCOV - code coverage report
Current view: top level - src/test/util - transaction_utils.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 0 50 0.0 %
Date: 2023-11-10 23:46:46 Functions: 0 3 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2019-2020 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 <coins.h>
       6                 :            : #include <script/signingprovider.h>
       7                 :            : #include <test/util/transaction_utils.h>
       8                 :            : 
       9                 :          0 : CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue)
      10                 :            : {
      11                 :          0 :     CMutableTransaction txCredit;
      12                 :          0 :     txCredit.nVersion = 1;
      13                 :          0 :     txCredit.nLockTime = 0;
      14                 :          0 :     txCredit.vin.resize(1);
      15                 :          0 :     txCredit.vout.resize(1);
      16                 :          0 :     txCredit.vin[0].prevout.SetNull();
      17                 :          0 :     txCredit.vin[0].scriptSig = CScript() << CScriptNum(0) << CScriptNum(0);
      18                 :          0 :     txCredit.vin[0].nSequence = CTxIn::SEQUENCE_FINAL;
      19                 :          0 :     txCredit.vout[0].scriptPubKey = scriptPubKey;
      20                 :          0 :     txCredit.vout[0].nValue = nValue;
      21                 :            : 
      22                 :          0 :     return txCredit;
      23                 :          0 : }
      24                 :            : 
      25                 :          0 : CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit)
      26                 :            : {
      27                 :          0 :     CMutableTransaction txSpend;
      28                 :          0 :     txSpend.nVersion = 1;
      29                 :          0 :     txSpend.nLockTime = 0;
      30                 :          0 :     txSpend.vin.resize(1);
      31                 :          0 :     txSpend.vout.resize(1);
      32                 :          0 :     txSpend.vin[0].scriptWitness = scriptWitness;
      33                 :          0 :     txSpend.vin[0].prevout.hash = txCredit.GetHash();
      34                 :          0 :     txSpend.vin[0].prevout.n = 0;
      35                 :          0 :     txSpend.vin[0].scriptSig = scriptSig;
      36                 :          0 :     txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL;
      37                 :          0 :     txSpend.vout[0].scriptPubKey = CScript();
      38                 :          0 :     txSpend.vout[0].nValue = txCredit.vout[0].nValue;
      39                 :            : 
      40                 :          0 :     return txSpend;
      41                 :          0 : }
      42                 :            : 
      43                 :          0 : std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues)
      44                 :            : {
      45                 :          0 :     std::vector<CMutableTransaction> dummyTransactions;
      46                 :          0 :     dummyTransactions.resize(2);
      47                 :            : 
      48                 :            :     // Add some keys to the keystore:
      49                 :          0 :     CKey key[4];
      50                 :          0 :     for (int i = 0; i < 4; i++) {
      51                 :          0 :         key[i].MakeNewKey(i % 2);
      52                 :          0 :         keystoreRet.AddKey(key[i]);
      53                 :          0 :     }
      54                 :            : 
      55                 :            :     // Create some dummy input transactions
      56                 :          0 :     dummyTransactions[0].vout.resize(2);
      57                 :          0 :     dummyTransactions[0].vout[0].nValue = nValues[0];
      58                 :          0 :     dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
      59                 :          0 :     dummyTransactions[0].vout[1].nValue = nValues[1];
      60                 :          0 :     dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
      61                 :          0 :     AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0);
      62                 :            : 
      63                 :          0 :     dummyTransactions[1].vout.resize(2);
      64                 :          0 :     dummyTransactions[1].vout[0].nValue = nValues[2];
      65                 :          0 :     dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey()));
      66                 :          0 :     dummyTransactions[1].vout[1].nValue = nValues[3];
      67                 :          0 :     dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey()));
      68                 :          0 :     AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0);
      69                 :            : 
      70                 :          0 :     return dummyTransactions;
      71                 :          0 : }

Generated by: LCOV version 1.14