LCOV - code coverage report
Current view: top level - src/test/util - transaction_utils.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 95.9 % 49 47
Test Date: 2024-08-28 04:44:32 Functions: 100.0 % 3 3
Branches: 51.4 % 70 36

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

Generated by: LCOV version 2.0-1