Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | for (int i = 0; i < 2; i++) { | ||||
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); | ||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() != block.GetHash()); | BOOST_CHECK(::ChainActive().Tip()->GetBlockHash() != block.GetHash()); | ||||
// Test 2: ... and should be rejected if spend1 is in the memory pool | // Test 2: ... and should be rejected if spend1 is in the memory pool | ||||
BOOST_CHECK(ToMemPool(spends[0])); | BOOST_CHECK(ToMemPool(spends[0])); | ||||
block = CreateAndProcessBlock(spends, scriptPubKey); | block = CreateAndProcessBlock(spends, scriptPubKey); | ||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() != block.GetHash()); | BOOST_CHECK(::ChainActive().Tip()->GetBlockHash() != block.GetHash()); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Test 3: ... and should be rejected if spend2 is in the memory pool | // Test 3: ... and should be rejected if spend2 is in the memory pool | ||||
BOOST_CHECK(ToMemPool(spends[1])); | BOOST_CHECK(ToMemPool(spends[1])); | ||||
block = CreateAndProcessBlock(spends, scriptPubKey); | block = CreateAndProcessBlock(spends, scriptPubKey); | ||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() != block.GetHash()); | BOOST_CHECK(::ChainActive().Tip()->GetBlockHash() != block.GetHash()); | ||||
g_mempool.clear(); | g_mempool.clear(); | ||||
// Final sanity test: first spend in mempool, second in block, that's OK: | // Final sanity test: first spend in mempool, second in block, that's OK: | ||||
std::vector<CMutableTransaction> oneSpend; | std::vector<CMutableTransaction> oneSpend; | ||||
oneSpend.push_back(spends[0]); | oneSpend.push_back(spends[0]); | ||||
BOOST_CHECK(ToMemPool(spends[1])); | BOOST_CHECK(ToMemPool(spends[1])); | ||||
block = CreateAndProcessBlock(oneSpend, scriptPubKey); | block = CreateAndProcessBlock(oneSpend, scriptPubKey); | ||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() == block.GetHash()); | BOOST_CHECK(::ChainActive().Tip()->GetBlockHash() == block.GetHash()); | ||||
// spends[1] should have been removed from the mempool when the block with | // spends[1] should have been removed from the mempool when the block with | ||||
// spends[0] is accepted: | // spends[0] is accepted: | ||||
BOOST_CHECK_EQUAL(g_mempool.size(), 0U); | BOOST_CHECK_EQUAL(g_mempool.size(), 0U); | ||||
} | } | ||||
static inline bool | static inline bool | ||||
CheckInputs(const CTransaction &tx, CValidationState &state, | CheckInputs(const CTransaction &tx, CValidationState &state, | ||||
const CCoinsViewCache &view, bool fScriptChecks, | const CCoinsViewCache &view, bool fScriptChecks, | ||||
▲ Show 20 Lines • Show All 123 Lines • ▼ Show 20 Lines | // `checkinputs_test`. | ||||
BOOST_CHECK(coinbaseKey.SignECDSA(fundingSigHash, fundingVchSig)); | BOOST_CHECK(coinbaseKey.SignECDSA(fundingSigHash, fundingVchSig)); | ||||
fundingVchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | fundingVchSig.push_back(uint8_t(SIGHASH_ALL | SIGHASH_FORKID)); | ||||
funding_tx.vin[0].scriptSig << fundingVchSig; | funding_tx.vin[0].scriptSig << fundingVchSig; | ||||
} | } | ||||
// Spend the funding transaction by mining it into a block | // Spend the funding transaction by mining it into a block | ||||
{ | { | ||||
CBlock block = CreateAndProcessBlock({funding_tx}, p2pk_scriptPubKey); | CBlock block = CreateAndProcessBlock({funding_tx}, p2pk_scriptPubKey); | ||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() == block.GetHash()); | BOOST_CHECK(::ChainActive().Tip()->GetBlockHash() == block.GetHash()); | ||||
BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash()); | BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash()); | ||||
} | } | ||||
// flags to test: SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, | // flags to test: SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, | ||||
// SCRIPT_VERIFY_CHECKSEQUENCE_VERIFY, | // SCRIPT_VERIFY_CHECKSEQUENCE_VERIFY, | ||||
// SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS, uncompressed pubkey thing | // SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS, uncompressed 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 | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup) { | ||||
} | } | ||||
// And if we produce a block with this tx, it should be valid, even though | // And if we produce a block with this tx, it should be valid, even though | ||||
// there's no cache entry. | // there's no cache entry. | ||||
CBlock block; | CBlock block; | ||||
block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey); | block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BOOST_CHECK(chainActive.Tip()->GetBlockHash() == block.GetHash()); | BOOST_CHECK(::ChainActive().Tip()->GetBlockHash() == block.GetHash()); | ||||
BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash()); | BOOST_CHECK(pcoinsTip->GetBestBlock() == block.GetHash()); | ||||
// 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); | ||||
▲ Show 20 Lines • Show All 348 Lines • Show Last 20 Lines |