Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show First 20 Lines • Show All 58 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); | ||||
{ | |||||
LOCK(cs_main); | |||||
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); | ||||
{ | |||||
LOCK(cs_main); | |||||
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); | ||||
{ | |||||
LOCK(cs_main); | |||||
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); | ||||
{ | |||||
LOCK(cs_main); | |||||
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 561 Lines • Show Last 20 Lines |