Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show All 38 Lines | CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) | ||||
<< OP_CHECKSIG; | << OP_CHECKSIG; | ||||
// Create a double-spend of mature coinbase txn: | // Create a double-spend of mature coinbase txn: | ||||
std::vector<CMutableTransaction> spends; | std::vector<CMutableTransaction> spends; | ||||
spends.resize(2); | spends.resize(2); | ||||
for (int i = 0; i < 2; i++) { | for (int i = 0; i < 2; i++) { | ||||
spends[i].nVersion = 1; | spends[i].nVersion = 1; | ||||
spends[i].vin.resize(1); | spends[i].vin.resize(1); | ||||
spends[i].vin[0].prevout.hash = coinbaseTxns[0].GetId(); | spends[i].vin[0].prevout.hash = coinbaseTxns[0].GetHash(); | ||||
spends[i].vin[0].prevout.n = 0; | spends[i].vin[0].prevout.n = 0; | ||||
spends[i].vout.resize(1); | spends[i].vout.resize(1); | ||||
spends[i].vout[0].nValue = 11 * CENT.GetSatoshis(); | spends[i].vout[0].nValue = 11 * CENT.GetSatoshis(); | ||||
spends[i].vout[0].scriptPubKey = scriptPubKey; | spends[i].vout[0].scriptPubKey = scriptPubKey; | ||||
// Sign: | // Sign: | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
uint256 hash = SignatureHash(scriptPubKey, spends[i], 0, | uint256 hash = SignatureHash(scriptPubKey, spends[i], 0, | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
// pubkey thing | // pubkey thing | ||||
// Create 2 outputs that match the three scripts above, spending the first | // Create 2 outputs that match the three scripts above, spending the first | ||||
// coinbase tx. | // coinbase tx. | ||||
CMutableTransaction spend_tx; | CMutableTransaction spend_tx; | ||||
spend_tx.nVersion = 1; | spend_tx.nVersion = 1; | ||||
spend_tx.vin.resize(1); | spend_tx.vin.resize(1); | ||||
spend_tx.vin[0].prevout.hash = coinbaseTxns[0].GetId(); | spend_tx.vin[0].prevout.hash = coinbaseTxns[0].GetHash(); | ||||
spend_tx.vin[0].prevout.n = 0; | spend_tx.vin[0].prevout.n = 0; | ||||
spend_tx.vout.resize(4); | spend_tx.vout.resize(4); | ||||
spend_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | spend_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | ||||
spend_tx.vout[0].scriptPubKey = p2sh_scriptPubKey; | spend_tx.vout[0].scriptPubKey = p2sh_scriptPubKey; | ||||
spend_tx.vout[1].nValue = 11 * CENT.GetSatoshis(); | spend_tx.vout[1].nValue = 11 * CENT.GetSatoshis(); | ||||
spend_tx.vout[1].scriptPubKey = | spend_tx.vout[1].scriptPubKey = | ||||
CScript() << OP_CHECKLOCKTIMEVERIFY << OP_DROP | CScript() << OP_CHECKLOCKTIMEVERIFY << OP_DROP | ||||
<< ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; | << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
} | } | ||||
// Test P2SH: construct a transaction that is valid without P2SH, and then | // Test P2SH: construct a transaction that is valid without P2SH, and then | ||||
// test validity with P2SH. | // test validity with P2SH. | ||||
{ | { | ||||
CMutableTransaction invalid_under_p2sh_tx; | CMutableTransaction invalid_under_p2sh_tx; | ||||
invalid_under_p2sh_tx.nVersion = 1; | invalid_under_p2sh_tx.nVersion = 1; | ||||
invalid_under_p2sh_tx.vin.resize(1); | invalid_under_p2sh_tx.vin.resize(1); | ||||
invalid_under_p2sh_tx.vin[0].prevout.hash = spend_tx.GetId(); | invalid_under_p2sh_tx.vin[0].prevout.hash = spend_tx.GetHash(); | ||||
invalid_under_p2sh_tx.vin[0].prevout.n = 0; | invalid_under_p2sh_tx.vin[0].prevout.n = 0; | ||||
invalid_under_p2sh_tx.vout.resize(1); | invalid_under_p2sh_tx.vout.resize(1); | ||||
invalid_under_p2sh_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | invalid_under_p2sh_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | ||||
invalid_under_p2sh_tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | invalid_under_p2sh_tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | ||||
std::vector<uint8_t> vchSig2(p2pk_scriptPubKey.begin(), | std::vector<uint8_t> vchSig2(p2pk_scriptPubKey.begin(), | ||||
p2pk_scriptPubKey.end()); | p2pk_scriptPubKey.end()); | ||||
invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2; | invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2; | ||||
ValidateCheckInputsForAllFlags(invalid_under_p2sh_tx, | ValidateCheckInputsForAllFlags(invalid_under_p2sh_tx, | ||||
SCRIPT_VERIFY_P2SH, true, false); | SCRIPT_VERIFY_P2SH, true, false); | ||||
} | } | ||||
// Test CHECKLOCKTIMEVERIFY | // Test CHECKLOCKTIMEVERIFY | ||||
{ | { | ||||
CMutableTransaction invalid_with_cltv_tx; | CMutableTransaction invalid_with_cltv_tx; | ||||
invalid_with_cltv_tx.nVersion = 1; | invalid_with_cltv_tx.nVersion = 1; | ||||
invalid_with_cltv_tx.nLockTime = 100; | invalid_with_cltv_tx.nLockTime = 100; | ||||
invalid_with_cltv_tx.vin.resize(1); | invalid_with_cltv_tx.vin.resize(1); | ||||
invalid_with_cltv_tx.vin[0].prevout.hash = spend_tx.GetId(); | invalid_with_cltv_tx.vin[0].prevout.hash = spend_tx.GetHash(); | ||||
invalid_with_cltv_tx.vin[0].prevout.n = 1; | invalid_with_cltv_tx.vin[0].prevout.n = 1; | ||||
invalid_with_cltv_tx.vin[0].nSequence = 0; | invalid_with_cltv_tx.vin[0].nSequence = 0; | ||||
invalid_with_cltv_tx.vout.resize(1); | invalid_with_cltv_tx.vout.resize(1); | ||||
invalid_with_cltv_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | invalid_with_cltv_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | ||||
invalid_with_cltv_tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | invalid_with_cltv_tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | ||||
// Sign | // Sign | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
Show All 18 Lines | // Test CHECKLOCKTIMEVERIFY | ||||
true, true, txdata, nullptr)); | true, true, txdata, nullptr)); | ||||
} | } | ||||
// TEST CHECKSEQUENCEVERIFY | // TEST CHECKSEQUENCEVERIFY | ||||
{ | { | ||||
CMutableTransaction invalid_with_csv_tx; | CMutableTransaction invalid_with_csv_tx; | ||||
invalid_with_csv_tx.nVersion = 2; | invalid_with_csv_tx.nVersion = 2; | ||||
invalid_with_csv_tx.vin.resize(1); | invalid_with_csv_tx.vin.resize(1); | ||||
invalid_with_csv_tx.vin[0].prevout.hash = spend_tx.GetId(); | invalid_with_csv_tx.vin[0].prevout.hash = spend_tx.GetHash(); | ||||
invalid_with_csv_tx.vin[0].prevout.n = 2; | invalid_with_csv_tx.vin[0].prevout.n = 2; | ||||
invalid_with_csv_tx.vin[0].nSequence = 100; | invalid_with_csv_tx.vin[0].nSequence = 100; | ||||
invalid_with_csv_tx.vout.resize(1); | invalid_with_csv_tx.vout.resize(1); | ||||
invalid_with_csv_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | invalid_with_csv_tx.vout[0].nValue = 11 * CENT.GetSatoshis(); | ||||
invalid_with_csv_tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | invalid_with_csv_tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | ||||
// Sign | // Sign | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
Show All 20 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
// TODO: add tests for remaining script flags | // TODO: add tests for remaining script flags | ||||
{ | { | ||||
// Test a transaction with multiple inputs. | // Test a transaction with multiple inputs. | ||||
CMutableTransaction tx; | CMutableTransaction tx; | ||||
tx.nVersion = 1; | tx.nVersion = 1; | ||||
tx.vin.resize(2); | tx.vin.resize(2); | ||||
tx.vin[0].prevout.hash = spend_tx.GetId(); | tx.vin[0].prevout.hash = spend_tx.GetHash(); | ||||
tx.vin[0].prevout.n = 0; | tx.vin[0].prevout.n = 0; | ||||
tx.vin[1].prevout.hash = spend_tx.GetId(); | tx.vin[1].prevout.hash = spend_tx.GetHash(); | ||||
tx.vin[1].prevout.n = 3; | tx.vin[1].prevout.n = 3; | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
tx.vout[0].nValue = 22 * CENT.GetSatoshis(); | tx.vout[0].nValue = 22 * CENT.GetSatoshis(); | ||||
tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | tx.vout[0].scriptPubKey = p2pk_scriptPubKey; | ||||
// Sign | // Sign | ||||
SignatureData sigdata; | SignatureData sigdata; | ||||
ProduceSignature(MutableTransactionSignatureCreator( | ProduceSignature(MutableTransactionSignatureCreator( | ||||
Show All 40 Lines |