Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | for (int i = 0; i < 2; i++) { | ||||
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); | coinbaseTxns[0].vout[0].nValue); | ||||
BOOST_CHECK(coinbaseKey.Sign(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. | ||||
block = CreateAndProcessBlock(spends, scriptPubKey); | block = CreateAndProcessBlock(spends, scriptPubKey); | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | // testing consensus vs non-standard rules in `checkinputs_test`. | ||||
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(), coinbaseTxns[0].vout[0].nValue); | ||||
BOOST_CHECK(coinbaseKey.Sign(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 | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
Show All 27 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
mutableSpend_tx.vout[3].scriptPubKey = p2sh_scriptPubKey; | mutableSpend_tx.vout[3].scriptPubKey = p2sh_scriptPubKey; | ||||
// Sign the main transaction that we spend from. | // Sign the main transaction that we spend from. | ||||
{ | { | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
uint256 hash = SignatureHash( | uint256 hash = SignatureHash( | ||||
nulldummyPubKeyScript, CTransaction(mutableSpend_tx), 0, | nulldummyPubKeyScript, CTransaction(mutableSpend_tx), 0, | ||||
SigHashType().withForkId(), funding_tx.vout[0].nValue); | SigHashType().withForkId(), funding_tx.vout[0].nValue); | ||||
coinbaseKey.Sign(hash, vchSig); | coinbaseKey.SignECDSA(hash, vchSig); | ||||
vchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | vchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | ||||
// The last item on the stack will be dropped by CHECKMULTISIG This is | // The last item on the stack will be dropped by CHECKMULTISIG This is | ||||
// to check nulldummy enforcement. It is OP_1 instead of OP_0. | // to check nulldummy enforcement. It is OP_1 instead of OP_0. | ||||
mutableSpend_tx.vin[0].scriptSig << OP_1 << vchSig; | mutableSpend_tx.vin[0].scriptSig << OP_1 << vchSig; | ||||
} | } | ||||
const CTransaction spend_tx(mutableSpend_tx); | const CTransaction spend_tx(mutableSpend_tx); | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | // Test CHECKLOCKTIMEVERIFY | ||||
invalid_with_cltv_tx.vout[0].nValue = 11 * CENT; | invalid_with_cltv_tx.vout[0].nValue = 11 * CENT; | ||||
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; | ||||
uint256 hash = SignatureHash( | uint256 hash = SignatureHash( | ||||
spend_tx.vout[1].scriptPubKey, CTransaction(invalid_with_cltv_tx), | spend_tx.vout[1].scriptPubKey, CTransaction(invalid_with_cltv_tx), | ||||
0, SigHashType().withForkId(), spend_tx.vout[1].nValue); | 0, SigHashType().withForkId(), spend_tx.vout[1].nValue); | ||||
BOOST_CHECK(coinbaseKey.Sign(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)); | ||||
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101; | invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101; | ||||
ValidateCheckInputsForAllFlags(invalid_with_cltv_tx, | ValidateCheckInputsForAllFlags(invalid_with_cltv_tx, | ||||
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, | SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, | ||||
true); | true); | ||||
// Make it valid, and check again | // Make it valid, and check again | ||||
Show All 20 Lines | // TEST CHECKSEQUENCEVERIFY | ||||
invalid_with_csv_tx.vout[0].nValue = 11 * CENT; | invalid_with_csv_tx.vout[0].nValue = 11 * CENT; | ||||
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; | ||||
uint256 hash = SignatureHash( | uint256 hash = SignatureHash( | ||||
spend_tx.vout[2].scriptPubKey, CTransaction(invalid_with_csv_tx), 0, | spend_tx.vout[2].scriptPubKey, CTransaction(invalid_with_csv_tx), 0, | ||||
SigHashType().withForkId(), spend_tx.vout[2].nValue); | SigHashType().withForkId(), spend_tx.vout[2].nValue); | ||||
BOOST_CHECK(coinbaseKey.Sign(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)); | ||||
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101; | invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101; | ||||
ValidateCheckInputsForAllFlags( | ValidateCheckInputsForAllFlags( | ||||
invalid_with_csv_tx, SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true); | invalid_with_csv_tx, SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true); | ||||
// Make it valid, and check again | // Make it valid, and check again | ||||
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100; | invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100; | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |