Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (int i = 0; i < 2; i++) { | ||||
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, | ||||
SIGHASH_ALL | SIGHASH_FORKID, | SIGHASH_ALL | SIGHASH_FORKID, | ||||
coinbaseTxns[0].vout[0].nValue); | coinbaseTxns[0].vout[0].nValue, CScript()); | ||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig)); | BOOST_CHECK(coinbaseKey.Sign(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 121 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
spend_tx.vout[3].nValue = 11 * CENT.GetSatoshis(); | spend_tx.vout[3].nValue = 11 * CENT.GetSatoshis(); | ||||
spend_tx.vout[3].scriptPubKey = p2sh_scriptPubKey; | spend_tx.vout[3].scriptPubKey = p2sh_scriptPubKey; | ||||
// Sign, with a non-DER signature | // Sign, with a non-DER signature | ||||
{ | { | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
uint256 hash = SignatureHash(p2pk_scriptPubKey, spend_tx, 0, | uint256 hash = SignatureHash(p2pk_scriptPubKey, spend_tx, 0, | ||||
SIGHASH_ALL | SIGHASH_FORKID, | SIGHASH_ALL | SIGHASH_FORKID, | ||||
coinbaseTxns[0].vout[0].nValue); | coinbaseTxns[0].vout[0].nValue, CScript()); | ||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig)); | BOOST_CHECK(coinbaseKey.Sign(hash, vchSig)); | ||||
// Negate S to ensure the signature is valid but non standard. | // Negate S to ensure the signature is valid but non standard. | ||||
NegateSignatureS(vchSig); | NegateSignatureS(vchSig); | ||||
vchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | vchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | ||||
spend_tx.vin[0].scriptSig << vchSig; | spend_tx.vin[0].scriptSig << vchSig; | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | // Test CHECKLOCKTIMEVERIFY | ||||
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; | ||||
uint256 hash = SignatureHash( | uint256 hash = SignatureHash( | ||||
spend_tx.vout[1].scriptPubKey, invalid_with_cltv_tx, 0, | spend_tx.vout[1].scriptPubKey, invalid_with_cltv_tx, 0, | ||||
SIGHASH_ALL | SIGHASH_FORKID, spend_tx.vout[1].nValue); | SIGHASH_ALL | SIGHASH_FORKID, spend_tx.vout[1].nValue, CScript()); | ||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig)); | BOOST_CHECK(coinbaseKey.Sign(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); | ||||
Show All 18 Lines | // TEST CHECKSEQUENCEVERIFY | ||||
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; | ||||
uint256 hash = SignatureHash( | uint256 hash = SignatureHash( | ||||
spend_tx.vout[2].scriptPubKey, invalid_with_csv_tx, 0, | spend_tx.vout[2].scriptPubKey, invalid_with_csv_tx, 0, | ||||
SIGHASH_ALL | SIGHASH_FORKID, spend_tx.vout[2].nValue); | SIGHASH_ALL | SIGHASH_FORKID, spend_tx.vout[2].nValue, CScript()); | ||||
BOOST_CHECK(coinbaseKey.Sign(hash, vchSig)); | BOOST_CHECK(coinbaseKey.Sign(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 | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |