mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
refactor: test/bench: dedup SetupDummyInputs()
The only difference between SetupDummyInputs() in test/transaction_tests.cpp and the one in bench/ccoins_caching.cpp was the nValue amounts of the outputs, so we allow to pass those in an extra (fixed-size) array parameter.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/util/transaction_utils.h>
|
||||
#include <coins.h>
|
||||
#include <script/signingprovider.h>
|
||||
|
||||
CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue)
|
||||
{
|
||||
@@ -37,3 +39,33 @@ CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CSc
|
||||
|
||||
return txSpend;
|
||||
}
|
||||
|
||||
std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues)
|
||||
{
|
||||
std::vector<CMutableTransaction> dummyTransactions;
|
||||
dummyTransactions.resize(2);
|
||||
|
||||
// Add some keys to the keystore:
|
||||
CKey key[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
key[i].MakeNewKey(i % 2);
|
||||
keystoreRet.AddKey(key[i]);
|
||||
}
|
||||
|
||||
// Create some dummy input transactions
|
||||
dummyTransactions[0].vout.resize(2);
|
||||
dummyTransactions[0].vout[0].nValue = nValues[0];
|
||||
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
||||
dummyTransactions[0].vout[1].nValue = nValues[1];
|
||||
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
||||
AddCoins(coinsRet, CTransaction(dummyTransactions[0]), 0);
|
||||
|
||||
dummyTransactions[1].vout.resize(2);
|
||||
dummyTransactions[1].vout[0].nValue = nValues[2];
|
||||
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey()));
|
||||
dummyTransactions[1].vout[1].nValue = nValues[3];
|
||||
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey()));
|
||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0);
|
||||
|
||||
return dummyTransactions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user