Changeset View
Changeset View
Standalone View
Standalone View
src/test/transaction_tests.cpp
Show First 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_Get) { | ||||
CBasicKeyStore keystore; | CBasicKeyStore keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = | std::vector<CMutableTransaction> dummyTransactions = | ||||
SetupDummyInputs(keystore, coins); | SetupDummyInputs(keystore, coins); | ||||
CMutableTransaction t1; | CMutableTransaction t1; | ||||
t1.vin.resize(3); | t1.vin.resize(3); | ||||
t1.vin[0].prevout.hash = dummyTransactions[0].GetId(); | t1.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
t1.vin[0].prevout.n = 1; | |||||
t1.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | t1.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | ||||
t1.vin[1].prevout.hash = dummyTransactions[1].GetId(); | t1.vin[1].prevout = COutPoint(dummyTransactions[1].GetId(), 0); | ||||
t1.vin[1].prevout.n = 0; | |||||
t1.vin[1].scriptSig << std::vector<uint8_t>(65, 0) | t1.vin[1].scriptSig << std::vector<uint8_t>(65, 0) | ||||
<< std::vector<uint8_t>(33, 4); | << std::vector<uint8_t>(33, 4); | ||||
t1.vin[2].prevout.hash = dummyTransactions[1].GetId(); | t1.vin[2].prevout = COutPoint(dummyTransactions[1].GetId(), 1); | ||||
t1.vin[2].prevout.n = 1; | |||||
t1.vin[2].scriptSig << std::vector<uint8_t>(65, 0) | t1.vin[2].scriptSig << std::vector<uint8_t>(65, 0) | ||||
<< std::vector<uint8_t>(33, 4); | << std::vector<uint8_t>(33, 4); | ||||
t1.vout.resize(2); | t1.vout.resize(2); | ||||
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)), | ||||
Show All 17 Lines | void CreateCreditAndSpend(const CKeyStore &keystore, const CScript &outscript, | ||||
BOOST_CHECK_EQUAL(output->vin.size(), 1UL); | BOOST_CHECK_EQUAL(output->vin.size(), 1UL); | ||||
BOOST_CHECK(output->vin[0] == outputm.vin[0]); | BOOST_CHECK(output->vin[0] == outputm.vin[0]); | ||||
BOOST_CHECK_EQUAL(output->vout.size(), 1UL); | BOOST_CHECK_EQUAL(output->vout.size(), 1UL); | ||||
BOOST_CHECK(output->vout[0] == outputm.vout[0]); | BOOST_CHECK(output->vout[0] == outputm.vout[0]); | ||||
CMutableTransaction inputm; | CMutableTransaction inputm; | ||||
inputm.nVersion = 1; | inputm.nVersion = 1; | ||||
inputm.vin.resize(1); | inputm.vin.resize(1); | ||||
inputm.vin[0].prevout.hash = output->GetId(); | inputm.vin[0].prevout = COutPoint(output->GetId(), 0); | ||||
inputm.vin[0].prevout.n = 0; | |||||
inputm.vout.resize(1); | inputm.vout.resize(1); | ||||
inputm.vout[0].nValue = Amount(1); | inputm.vout[0].nValue = Amount(1); | ||||
inputm.vout[0].scriptPubKey = CScript(); | inputm.vout[0].scriptPubKey = CScript(); | ||||
bool ret = | bool ret = | ||||
SignSignature(keystore, *output, inputm, 0, SigHashType().withForkId()); | SignSignature(keystore, *output, inputm, 0, SigHashType().withForkId()); | ||||
BOOST_CHECK_EQUAL(ret, success); | BOOST_CHECK_EQUAL(ret, success); | ||||
CDataStream ssin(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssin(SER_NETWORK, PROTOCOL_VERSION); | ||||
ssin << inputm; | ssin << inputm; | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < mtx.vin.size(); i++) { | ||||
CTxOut out; | CTxOut out; | ||||
out.nValue = Amount(1000); | out.nValue = Amount(1000); | ||||
out.scriptPubKey = scriptPubKey; | out.scriptPubKey = scriptPubKey; | ||||
coins.emplace_back(std::move(out), 1, false); | coins.emplace_back(std::move(out), 1, false); | ||||
} | } | ||||
for (size_t i = 0; i < mtx.vin.size(); i++) { | for (size_t i = 0; i < mtx.vin.size(); i++) { | ||||
std::vector<CScriptCheck> vChecks; | std::vector<CScriptCheck> vChecks; | ||||
CTxOut &out = coins[tx.vin[i].prevout.n].GetTxOut(); | CTxOut &out = coins[tx.vin[i].prevout.GetN()].GetTxOut(); | ||||
CScriptCheck check(out.scriptPubKey, out.nValue, tx, i, | CScriptCheck check(out.scriptPubKey, out.nValue, tx, i, | ||||
MANDATORY_SCRIPT_VERIFY_FLAGS, false, txdata); | MANDATORY_SCRIPT_VERIFY_FLAGS, false, txdata); | ||||
vChecks.push_back(CScriptCheck()); | vChecks.push_back(CScriptCheck()); | ||||
check.swap(vChecks.back()); | check.swap(vChecks.back()); | ||||
control.Add(vChecks); | control.Add(vChecks); | ||||
} | } | ||||
bool controlCheck = control.Wait(); | bool controlCheck = control.Wait(); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(test_IsStandard) { | ||||
CBasicKeyStore keystore; | CBasicKeyStore keystore; | ||||
CCoinsView coinsDummy; | CCoinsView coinsDummy; | ||||
CCoinsViewCache coins(&coinsDummy); | CCoinsViewCache coins(&coinsDummy); | ||||
std::vector<CMutableTransaction> dummyTransactions = | std::vector<CMutableTransaction> dummyTransactions = | ||||
SetupDummyInputs(keystore, coins); | SetupDummyInputs(keystore, coins); | ||||
CMutableTransaction t; | CMutableTransaction t; | ||||
t.vin.resize(1); | t.vin.resize(1); | ||||
t.vin[0].prevout.hash = dummyTransactions[0].GetId(); | t.vin[0].prevout = COutPoint(dummyTransactions[0].GetId(), 1); | ||||
t.vin[0].prevout.n = 1; | |||||
t.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | t.vin[0].scriptSig << std::vector<uint8_t>(65, 0); | ||||
t.vout.resize(1); | t.vout.resize(1); | ||||
t.vout[0].nValue = 90 * CENT; | t.vout[0].nValue = 90 * CENT; | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
t.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID()); | t.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID()); | ||||
std::string reason; | std::string reason; | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |