diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2019-10-18 02:05:05 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2019-10-23 01:59:32 +0200 |
commit | a0fc0764763329df2c4b11a4e22715ccfc0cf7d3 (patch) | |
tree | 2faf74abfb0cd38ef1abb12a68aef0a68577d2d8 /src/test | |
parent | ec3ed5a4487886f1c2a35fda0a3289be7b280248 (diff) |
refactor: test/bench: dedup Build{Crediting,Spending}Transaction()
prototypes used in src/test/script_tests.cpp:
- CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue = 0);
- CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit);
prototypes used in bench/verify_script.cpp:
- CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey);
- CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMutableTransaction& txCredit);
The more generic versions from the script tests are moved into a new file pair
transaction_utils.cpp/h and the calls are adapted accordingly in the
verify_script benchmark (passing the nValue of 1 explicitely for
BuildCreditingTransaction(), passing empty scriptWitness explicitely and
converting txCredit parameter to CTransaction in BuildSpendingTransaction()).
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/lib/transaction_utils.cpp | 39 | ||||
-rw-r--r-- | src/test/lib/transaction_utils.h | 19 | ||||
-rw-r--r-- | src/test/script_tests.cpp | 35 |
3 files changed, 59 insertions, 34 deletions
diff --git a/src/test/lib/transaction_utils.cpp b/src/test/lib/transaction_utils.cpp new file mode 100644 index 0000000000..2619fb9006 --- /dev/null +++ b/src/test/lib/transaction_utils.cpp @@ -0,0 +1,39 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <test/lib/transaction_utils.h> + +CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue) +{ + CMutableTransaction txCredit; + txCredit.nVersion = 1; + txCredit.nLockTime = 0; + txCredit.vin.resize(1); + txCredit.vout.resize(1); + txCredit.vin[0].prevout.SetNull(); + txCredit.vin[0].scriptSig = CScript() << CScriptNum(0) << CScriptNum(0); + txCredit.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; + txCredit.vout[0].scriptPubKey = scriptPubKey; + txCredit.vout[0].nValue = nValue; + + return txCredit; +} + +CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit) +{ + CMutableTransaction txSpend; + txSpend.nVersion = 1; + txSpend.nLockTime = 0; + txSpend.vin.resize(1); + txSpend.vout.resize(1); + txSpend.vin[0].scriptWitness = scriptWitness; + txSpend.vin[0].prevout.hash = txCredit.GetHash(); + txSpend.vin[0].prevout.n = 0; + txSpend.vin[0].scriptSig = scriptSig; + txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; + txSpend.vout[0].scriptPubKey = CScript(); + txSpend.vout[0].nValue = txCredit.vout[0].nValue; + + return txSpend; +} diff --git a/src/test/lib/transaction_utils.h b/src/test/lib/transaction_utils.h new file mode 100644 index 0000000000..6f297ac34f --- /dev/null +++ b/src/test/lib/transaction_utils.h @@ -0,0 +1,19 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_TEST_LIB_TRANSACTION_UTILS_H +#define BITCOIN_TEST_LIB_TRANSACTION_UTILS_H + +#include <primitives/transaction.h> + +// create crediting transaction +// [1 coinbase input => 1 output with given scriptPubkey and value] +CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue = 0); + +// create spending transaction +// [1 input with referenced transaction outpoint, scriptSig, scriptWitness => +// 1 output with empty scriptPubKey, full value of referenced transaction] +CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit); + +#endif // BITCOIN_TEST_LIB_TRANSACTION_UTILS_H diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 84a70fe78b..caa99805c3 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -12,6 +12,7 @@ #include <script/signingprovider.h> #include <util/system.h> #include <util/strencodings.h> +#include <test/lib/transaction_utils.h> #include <test/setup_common.h> #include <rpc/util.h> #include <streams.h> @@ -121,40 +122,6 @@ static ScriptError_t ParseScriptError(const std::string &name) BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup) -CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue = 0) -{ - CMutableTransaction txCredit; - txCredit.nVersion = 1; - txCredit.nLockTime = 0; - txCredit.vin.resize(1); - txCredit.vout.resize(1); - txCredit.vin[0].prevout.SetNull(); - txCredit.vin[0].scriptSig = CScript() << CScriptNum(0) << CScriptNum(0); - txCredit.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; - txCredit.vout[0].scriptPubKey = scriptPubKey; - txCredit.vout[0].nValue = nValue; - - return txCredit; -} - -CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit) -{ - CMutableTransaction txSpend; - txSpend.nVersion = 1; - txSpend.nLockTime = 0; - txSpend.vin.resize(1); - txSpend.vout.resize(1); - txSpend.vin[0].scriptWitness = scriptWitness; - txSpend.vin[0].prevout.hash = txCredit.GetHash(); - txSpend.vin[0].prevout.n = 0; - txSpend.vin[0].scriptSig = scriptSig; - txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL; - txSpend.vout[0].scriptPubKey = CScript(); - txSpend.vout[0].nValue = txCredit.vout[0].nValue; - - return txSpend; -} - void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScriptWitness& scriptWitness, int flags, const std::string& message, int scriptError, CAmount nValue = 0) { bool expect = (scriptError == SCRIPT_ERR_OK); |