aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-10-02 22:41:30 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-10-02 22:41:54 +0200
commit29f96e8bc652cb14c6fdefe5279ee983054faa2a (patch)
tree106f3ef8cff4aa3af705a7f574c87ccfbae815f7 /src
parent0e64566a829a2d6a59d83c7f6731f9849f6dbc90 (diff)
parent54510f267228e3f6934fdcf8d02d02a95a06d876 (diff)
Merge pull request #4994
54510f2 DRY: Avoid repetitions in script_test (jtimon)
Diffstat (limited to 'src')
-rw-r--r--src/test/script_tests.cpp37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 7f09b3daa1..48a5635d8f 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -70,7 +70,7 @@ CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey)
return txCredit;
}
-CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CTransaction& txCredit)
+CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMutableTransaction& txCredit)
{
CMutableTransaction txSpend;
txSpend.nVersion = 1;
@@ -521,16 +521,8 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12)
CScript scriptPubKey12;
scriptPubKey12 << OP_1 << key1.GetPubKey() << key2.GetPubKey() << OP_2 << OP_CHECKMULTISIG;
- CMutableTransaction txFrom12;
- txFrom12.vout.resize(1);
- txFrom12.vout[0].scriptPubKey = scriptPubKey12;
-
- CMutableTransaction txTo12;
- txTo12.vin.resize(1);
- txTo12.vout.resize(1);
- txTo12.vin[0].prevout.n = 0;
- txTo12.vin[0].prevout.hash = txFrom12.GetHash();
- txTo12.vout[0].nValue = 1;
+ CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12);
+ CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), txFrom12);
CScript goodsig1 = sign_multisig(scriptPubKey12, key1, txTo12);
BOOST_CHECK(VerifyScript(goodsig1, scriptPubKey12, txTo12, 0, flags));
@@ -555,16 +547,8 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
CScript scriptPubKey23;
scriptPubKey23 << OP_2 << key1.GetPubKey() << key2.GetPubKey() << key3.GetPubKey() << OP_3 << OP_CHECKMULTISIG;
- CMutableTransaction txFrom23;
- txFrom23.vout.resize(1);
- txFrom23.vout[0].scriptPubKey = scriptPubKey23;
-
- CMutableTransaction txTo23;
- txTo23.vin.resize(1);
- txTo23.vout.resize(1);
- txTo23.vin[0].prevout.n = 0;
- txTo23.vin[0].prevout.hash = txFrom23.GetHash();
- txTo23.vout[0].nValue = 1;
+ CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23);
+ CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), txFrom23);
std::vector<CKey> keys;
keys.push_back(key1); keys.push_back(key2);
@@ -626,17 +610,10 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
keystore.AddKey(key);
}
- CMutableTransaction txFrom;
- txFrom.vout.resize(1);
- txFrom.vout[0].scriptPubKey = GetScriptForDestination(keys[0].GetPubKey().GetID());
+ CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(keys[0].GetPubKey().GetID()));
+ CMutableTransaction txTo = BuildSpendingTransaction(CScript(), txFrom);
CScript& scriptPubKey = txFrom.vout[0].scriptPubKey;
- CMutableTransaction txTo;
- txTo.vin.resize(1);
- txTo.vout.resize(1);
- txTo.vin[0].prevout.n = 0;
- txTo.vin[0].prevout.hash = txFrom.GetHash();
CScript& scriptSig = txTo.vin[0].scriptSig;
- txTo.vout[0].nValue = 1;
CScript empty;
CScript combined = CombineSignatures(scriptPubKey, txTo, 0, empty, empty);