LCOV - code coverage report
Current view: top level - src/test/util - transaction_utils.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 46 46 100.0 %
Date: 2020-09-26 01:30:44 Functions: 3 3 100.0 %

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

Generated by: LCOV version 1.15