DRY: Avoid repetitions in script_test

This commit is contained in:
jtimon 2014-09-28 06:33:33 +02:00
parent 6faee79426
commit 54510f2672

View file

@ -70,7 +70,7 @@ CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey)
return txCredit; return txCredit;
} }
CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CTransaction& txCredit) CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMutableTransaction& txCredit)
{ {
CMutableTransaction txSpend; CMutableTransaction txSpend;
txSpend.nVersion = 1; txSpend.nVersion = 1;
@ -521,16 +521,8 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12)
CScript scriptPubKey12; CScript scriptPubKey12;
scriptPubKey12 << OP_1 << key1.GetPubKey() << key2.GetPubKey() << OP_2 << OP_CHECKMULTISIG; scriptPubKey12 << OP_1 << key1.GetPubKey() << key2.GetPubKey() << OP_2 << OP_CHECKMULTISIG;
CMutableTransaction txFrom12; CMutableTransaction txFrom12 = BuildCreditingTransaction(scriptPubKey12);
txFrom12.vout.resize(1); CMutableTransaction txTo12 = BuildSpendingTransaction(CScript(), txFrom12);
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;
CScript goodsig1 = sign_multisig(scriptPubKey12, key1, txTo12); CScript goodsig1 = sign_multisig(scriptPubKey12, key1, txTo12);
BOOST_CHECK(VerifyScript(goodsig1, scriptPubKey12, txTo12, 0, flags)); BOOST_CHECK(VerifyScript(goodsig1, scriptPubKey12, txTo12, 0, flags));
@ -555,16 +547,8 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23)
CScript scriptPubKey23; CScript scriptPubKey23;
scriptPubKey23 << OP_2 << key1.GetPubKey() << key2.GetPubKey() << key3.GetPubKey() << OP_3 << OP_CHECKMULTISIG; scriptPubKey23 << OP_2 << key1.GetPubKey() << key2.GetPubKey() << key3.GetPubKey() << OP_3 << OP_CHECKMULTISIG;
CMutableTransaction txFrom23; CMutableTransaction txFrom23 = BuildCreditingTransaction(scriptPubKey23);
txFrom23.vout.resize(1); CMutableTransaction txTo23 = BuildSpendingTransaction(CScript(), txFrom23);
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;
std::vector<CKey> keys; std::vector<CKey> keys;
keys.push_back(key1); keys.push_back(key2); keys.push_back(key1); keys.push_back(key2);
@ -626,17 +610,10 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
keystore.AddKey(key); keystore.AddKey(key);
} }
CMutableTransaction txFrom; CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(keys[0].GetPubKey().GetID()));
txFrom.vout.resize(1); CMutableTransaction txTo = BuildSpendingTransaction(CScript(), txFrom);
txFrom.vout[0].scriptPubKey = GetScriptForDestination(keys[0].GetPubKey().GetID());
CScript& scriptPubKey = txFrom.vout[0].scriptPubKey; 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; CScript& scriptSig = txTo.vin[0].scriptSig;
txTo.vout[0].nValue = 1;
CScript empty; CScript empty;
CScript combined = CombineSignatures(scriptPubKey, txTo, 0, empty, empty); CScript combined = CombineSignatures(scriptPubKey, txTo, 0, empty, empty);