Changeset View
Changeset View
Standalone View
Standalone View
src/test/transaction_tests.cpp
Show First 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_Get) { | ||||
t1.vout[0].nValue = 90 * CENT; | t1.vout[0].nValue = 90 * CENT; | ||||
t1.vout[0].scriptPubKey << OP_1; | t1.vout[0].scriptPubKey << OP_1; | ||||
BOOST_CHECK(AreInputsStandard(CTransaction(t1), coins)); | BOOST_CHECK(AreInputsStandard(CTransaction(t1), coins)); | ||||
BOOST_CHECK_EQUAL(coins.GetValueIn(CTransaction(t1)), | BOOST_CHECK_EQUAL(coins.GetValueIn(CTransaction(t1)), | ||||
(50 + 21 + 22) * CENT); | (50 + 21 + 22) * CENT); | ||||
} | } | ||||
void CreateCreditAndSpend(const CKeyStore &keystore, const CScript &outscript, | static void CreateCreditAndSpend(const CKeyStore &keystore, | ||||
CTransactionRef &output, CMutableTransaction &input, | const CScript &outscript, | ||||
CTransactionRef &output, | |||||
CMutableTransaction &input, | |||||
bool success = true) { | bool success = true) { | ||||
CMutableTransaction outputm; | CMutableTransaction outputm; | ||||
outputm.nVersion = 1; | outputm.nVersion = 1; | ||||
outputm.vin.resize(1); | outputm.vin.resize(1); | ||||
outputm.vin[0].prevout = COutPoint(); | outputm.vin[0].prevout = COutPoint(); | ||||
outputm.vin[0].scriptSig = CScript(); | outputm.vin[0].scriptSig = CScript(); | ||||
outputm.vout.resize(1); | outputm.vout.resize(1); | ||||
outputm.vout[0].nValue = SATOSHI; | outputm.vout[0].nValue = SATOSHI; | ||||
outputm.vout[0].scriptPubKey = outscript; | outputm.vout[0].scriptPubKey = outscript; | ||||
Show All 19 Lines | static void CreateCreditAndSpend(const CKeyStore &keystore, | ||||
ssin << inputm; | ssin << inputm; | ||||
ssin >> input; | ssin >> input; | ||||
BOOST_CHECK_EQUAL(input.vin.size(), 1UL); | BOOST_CHECK_EQUAL(input.vin.size(), 1UL); | ||||
BOOST_CHECK(input.vin[0] == inputm.vin[0]); | BOOST_CHECK(input.vin[0] == inputm.vin[0]); | ||||
BOOST_CHECK_EQUAL(input.vout.size(), 1UL); | BOOST_CHECK_EQUAL(input.vout.size(), 1UL); | ||||
BOOST_CHECK(input.vout[0] == inputm.vout[0]); | BOOST_CHECK(input.vout[0] == inputm.vout[0]); | ||||
} | } | ||||
void CheckWithFlag(const CTransactionRef &output, | static void CheckWithFlag(const CTransactionRef &output, | ||||
const CMutableTransaction &input, int flags, bool success) { | const CMutableTransaction &input, int flags, | ||||
bool success) { | |||||
ScriptError error; | ScriptError error; | ||||
CTransaction inputi(input); | CTransaction inputi(input); | ||||
bool ret = VerifyScript( | bool ret = VerifyScript( | ||||
inputi.vin[0].scriptSig, output->vout[0].scriptPubKey, | inputi.vin[0].scriptSig, output->vout[0].scriptPubKey, | ||||
flags | SCRIPT_ENABLE_SIGHASH_FORKID, | flags | SCRIPT_ENABLE_SIGHASH_FORKID, | ||||
TransactionSignatureChecker(&inputi, 0, output->vout[0].nValue), | TransactionSignatureChecker(&inputi, 0, output->vout[0].nValue), | ||||
&error); | &error); | ||||
BOOST_CHECK_EQUAL(ret, success); | BOOST_CHECK_EQUAL(ret, success); | ||||
} | } | ||||
static CScript PushAll(const std::vector<valtype> &values) { | static CScript PushAll(const std::vector<valtype> &values) { | ||||
CScript result; | CScript result; | ||||
for (const valtype &v : values) { | for (const valtype &v : values) { | ||||
if (v.size() == 0) { | if (v.size() == 0) { | ||||
result << OP_0; | result << OP_0; | ||||
} else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) { | } else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) { | ||||
result << CScript::EncodeOP_N(v[0]); | result << CScript::EncodeOP_N(v[0]); | ||||
} else { | } else { | ||||
result << v; | result << v; | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
void ReplaceRedeemScript(CScript &script, const CScript &redeemScript) { | static void ReplaceRedeemScript(CScript &script, const CScript &redeemScript) { | ||||
std::vector<valtype> stack; | std::vector<valtype> stack; | ||||
EvalScript(stack, script, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker()); | EvalScript(stack, script, SCRIPT_VERIFY_STRICTENC, BaseSignatureChecker()); | ||||
BOOST_CHECK(stack.size() > 0); | BOOST_CHECK(stack.size() > 0); | ||||
stack.back() = | stack.back() = | ||||
std::vector<uint8_t>(redeemScript.begin(), redeemScript.end()); | std::vector<uint8_t>(redeemScript.begin(), redeemScript.end()); | ||||
script = PushAll(stack); | script = PushAll(stack); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 387 Lines • Show Last 20 Lines |