Changeset View
Changeset View
Standalone View
Standalone View
src/test/txvalidationcache_tests.cpp
Show All 21 Lines | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
BOOST_AUTO_TEST_SUITE(txvalidationcache_tests) | BOOST_AUTO_TEST_SUITE(txvalidationcache_tests) | ||||
static bool ToMemPool(const CMutableTransaction &tx) { | static bool ToMemPool(const CMutableTransaction &tx) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CValidationState state; | CValidationState state; | ||||
return AcceptToMemoryPool(GetConfig(), mempool, state, | return AcceptToMemoryPool(GetConfig(), g_mempool, state, | ||||
MakeTransactionRef(tx), false, nullptr, true, | MakeTransactionRef(tx), false, nullptr, true, | ||||
Amount::zero()); | Amount::zero()); | ||||
} | } | ||||
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup) { | ||||
// Make sure skipping validation of transctions that were validated going | // Make sure skipping validation of transctions that were validated going | ||||
// into the memory pool does not allow double-spends in blocks to pass | // into the memory pool does not allow double-spends in blocks to pass | ||||
// validation when they should not. | // validation when they should not. | ||||
Show All 26 Lines | BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup) { | ||||
// 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()); | ||||
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()); | ||||
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(mempool.size(), 0); | BOOST_CHECK_EQUAL(g_mempool.size(), 0); | ||||
} | } | ||||
// Run CheckInputs (using pcoinsTip) on the given transaction, for all script | // Run CheckInputs (using pcoinsTip) on the given transaction, for all script | ||||
// flags. Test that CheckInputs passes for all flags that don't overlap with the | // flags. Test that CheckInputs passes for all flags that don't overlap with the | ||||
// failing_flags argument, but otherwise fails. | // failing_flags argument, but otherwise fails. | ||||
// CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY (and future NOP codes that may | // CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY (and future NOP codes that may | ||||
// get reassigned) have an interaction with DISCOURAGE_UPGRADABLE_NOPS: if the | // get reassigned) have an interaction with DISCOURAGE_UPGRADABLE_NOPS: if the | ||||
// script flags used contain DISCOURAGE_UPGRADABLE_NOPS but don't contain | // script flags used contain DISCOURAGE_UPGRADABLE_NOPS but don't contain | ||||
▲ Show 20 Lines • Show All 336 Lines • Show Last 20 Lines |