Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 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 = COutPoint(coinbaseTxns[0].GetId(), 0); | spends[i].vin[0].prevout = COutPoint(m_coinbase_txns[0].GetId(), 0); | ||||
spends[i].vout.resize(1); | spends[i].vout.resize(1); | ||||
spends[i].vout[0].nValue = 11 * CENT; | spends[i].vout[0].nValue = 11 * CENT; | ||||
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, CTransaction(spends[i]), 0, | uint256 hash = SignatureHash(scriptPubKey, CTransaction(spends[i]), 0, | ||||
SigHashType().withForkId(), | SigHashType().withForkId(), | ||||
coinbaseTxns[0].vout[0].nValue); | m_coinbase_txns[0].vout[0].nValue); | ||||
BOOST_CHECK(coinbaseKey.SignECDSA(hash, vchSig)); | BOOST_CHECK(coinbaseKey.SignECDSA(hash, vchSig)); | ||||
vchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | vchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | ||||
spends[i].vin[0].scriptSig << vchSig; | spends[i].vin[0].scriptSig << vchSig; | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
// Test 1: block with both of those transactions should be rejected. | // Test 1: block with both of those transactions should be rejected. | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
// Needed when spending the output of this transaction | // Needed when spending the output of this transaction | ||||
CScript nulldummyPubKeyScript; | CScript nulldummyPubKeyScript; | ||||
// Create a funding transaction that can fail NULLDUMMY checks. This is for | // Create a funding transaction that can fail NULLDUMMY checks. This is for | ||||
// testing consensus vs non-standard rules in `checkinputs_test`. | // testing consensus vs non-standard rules in `checkinputs_test`. | ||||
{ | { | ||||
mutableFunding_tx.nVersion = 1; | mutableFunding_tx.nVersion = 1; | ||||
mutableFunding_tx.vin.resize(1); | mutableFunding_tx.vin.resize(1); | ||||
mutableFunding_tx.vin[0].prevout = | mutableFunding_tx.vin[0].prevout = | ||||
COutPoint(coinbaseTxns[0].GetId(), 0); | COutPoint(m_coinbase_txns[0].GetId(), 0); | ||||
mutableFunding_tx.vout.resize(1); | mutableFunding_tx.vout.resize(1); | ||||
mutableFunding_tx.vout[0].nValue = 50 * COIN; | mutableFunding_tx.vout[0].nValue = 50 * COIN; | ||||
CKey dummyKey; | CKey dummyKey; | ||||
dummyKey.MakeNewKey(true); | dummyKey.MakeNewKey(true); | ||||
nulldummyPubKeyScript << OP_1 << ToByteVector(coinbaseKey.GetPubKey()) | nulldummyPubKeyScript << OP_1 << ToByteVector(coinbaseKey.GetPubKey()) | ||||
<< ToByteVector(dummyKey.GetPubKey()) << OP_2 | << ToByteVector(dummyKey.GetPubKey()) << OP_2 | ||||
<< OP_CHECKMULTISIG; | << OP_CHECKMULTISIG; | ||||
mutableFunding_tx.vout[0].scriptPubKey = nulldummyPubKeyScript; | mutableFunding_tx.vout[0].scriptPubKey = nulldummyPubKeyScript; | ||||
std::vector<uint8_t> nullDummyVchSig; | std::vector<uint8_t> nullDummyVchSig; | ||||
uint256 nulldummySigHash = SignatureHash( | uint256 nulldummySigHash = SignatureHash( | ||||
p2pk_scriptPubKey, CTransaction(mutableFunding_tx), 0, | p2pk_scriptPubKey, CTransaction(mutableFunding_tx), 0, | ||||
SigHashType().withForkId(), coinbaseTxns[0].vout[0].nValue); | SigHashType().withForkId(), m_coinbase_txns[0].vout[0].nValue); | ||||
BOOST_CHECK(coinbaseKey.SignECDSA(nulldummySigHash, nullDummyVchSig)); | BOOST_CHECK(coinbaseKey.SignECDSA(nulldummySigHash, nullDummyVchSig)); | ||||
nullDummyVchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | nullDummyVchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | ||||
mutableFunding_tx.vin[0].scriptSig << nullDummyVchSig; | mutableFunding_tx.vin[0].scriptSig << nullDummyVchSig; | ||||
} | } | ||||
const CTransaction funding_tx = CTransaction(mutableFunding_tx); | const CTransaction funding_tx = CTransaction(mutableFunding_tx); | ||||
// Spend the funding transaction by mining it into a block | // Spend the funding transaction by mining it into a block | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 237 Lines • Show Last 20 Lines |