diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -28,7 +28,20 @@ #include -BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup) +namespace miner_tests { +struct MinerTestingSetup : public TestingSetup { + void TestPackageSelection(const CChainParams &chainparams, + const CScript &scriptPubKey, + const std::vector &txFirst) + EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs); + bool TestSequenceLocks(const CTransaction &tx, int flags) + EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs) { + return CheckSequenceLocks(*m_node.mempool, tx, flags); + } +}; +} // namespace miner_tests + +BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup) // BOOST_CHECK_EXCEPTION predicates to check the specific validation error class HasReason { @@ -93,19 +106,12 @@ return index; } -static bool TestSequenceLocks(const CTransaction &tx, int flags) - EXCLUSIVE_LOCKS_REQUIRED(cs_main) { - LOCK(::g_mempool.cs); - return CheckSequenceLocks(::g_mempool, tx, flags); -} - // Test suite for ancestor feerate transaction selection. -// Implemented as an additional function, rather than a separate test case, to -// allow reusing the blockchain created in CreateNewBlock_validity. -static void TestPackageSelection(const CChainParams &chainparams, - const CScript &scriptPubKey, - const std::vector &txFirst) - EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs) { +// Implemented as an additional function, rather than a separate test case, +// to allow reusing the blockchain created in CreateNewBlock_validity. +void MinerTestingSetup::TestPackageSelection( + const CChainParams &chainparams, const CScript &scriptPubKey, + const std::vector &txFirst) { // Test the ancestor feerate transaction selection. TestMemPoolEntryHelper entry; diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp --- a/src/test/txvalidationcache_tests.cpp +++ b/src/test/txvalidationcache_tests.cpp @@ -22,16 +22,6 @@ BOOST_AUTO_TEST_SUITE(txvalidationcache_tests) -static bool ToMemPool(const CMutableTransaction &tx) { - LOCK(cs_main); - - CValidationState state; - return AcceptToMemoryPool( - GetConfig(), g_mempool, state, MakeTransactionRef(tx), - nullptr /* pfMissingInputs */, true /* bypass_limits */, - Amount::zero() /* nAbsurdFee */); -} - BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup) { // Make sure skipping validation of transactions that were validated going // into the memory pool does not allow double-spends in blocks to pass @@ -39,6 +29,16 @@ CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; + const auto ToMemPool = [this](const CMutableTransaction &tx) { + LOCK(cs_main); + + CValidationState state; + return AcceptToMemoryPool( + GetConfig(), *m_node.mempool, state, MakeTransactionRef(tx), + nullptr /* pfMissingInputs */, true /* bypass_limits */, + Amount::zero() /* nAbsurdFee */); + }; + // Create a double-spend of mature coinbase txn: std::vector spends; spends.resize(2);