Skip to content

Commit 8888ad0

Browse files
author
MarcoFalke
committed
test: Replace recursive lock with locking annotations
Also, use m_node.mempool instead of the global
1 parent fac07f2 commit 8888ad0

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/test/miner_tests.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@
2323

2424
#include <boost/test/unit_test.hpp>
2525

26-
BOOST_FIXTURE_TEST_SUITE(miner_tests, TestingSetup)
26+
namespace miner_tests {
27+
struct MinerTestingSetup : public TestingSetup {
28+
void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
29+
bool TestSequenceLocks(const CTransaction& tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
30+
{
31+
return CheckSequenceLocks(*m_node.mempool, tx, flags);
32+
}
33+
};
34+
} // namespace miner_tests
35+
36+
BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup)
2737

2838
// BOOST_CHECK_EXCEPTION predicates to check the specific validation error
2939
class HasReason {
@@ -89,16 +99,10 @@ static CBlockIndex CreateBlockIndex(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_mai
8999
return index;
90100
}
91101

92-
static bool TestSequenceLocks(const CTransaction &tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
93-
{
94-
LOCK(::mempool.cs);
95-
return CheckSequenceLocks(::mempool, tx, flags);
96-
}
97-
98102
// Test suite for ancestor feerate transaction selection.
99103
// Implemented as an additional function, rather than a separate test case,
100104
// to allow reusing the blockchain created in CreateNewBlock_validity.
101-
static void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs)
105+
void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
102106
{
103107
// Test the ancestor feerate transaction selection.
104108
TestMemPoolEntryHelper entry;

src/test/txvalidationcache_tests.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ bool CheckInputs(const CTransaction& tx, TxValidationState &state, const CCoinsV
1717

1818
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
1919

20-
static bool
21-
ToMemPool(const CMutableTransaction& tx)
22-
{
23-
LOCK(cs_main);
24-
25-
TxValidationState state;
26-
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx),
27-
nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */);
28-
}
29-
3020
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
3121
{
3222
// Make sure skipping validation of transactions that were
@@ -35,6 +25,14 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
3525

3626
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
3727

28+
const auto ToMemPool = [this](const CMutableTransaction& tx) {
29+
LOCK(cs_main);
30+
31+
TxValidationState state;
32+
return AcceptToMemoryPool(*m_node.mempool, state, MakeTransactionRef(tx),
33+
nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */);
34+
};
35+
3836
// Create a double-spend of mature coinbase txn:
3937
std::vector<CMutableTransaction> spends;
4038
spends.resize(2);

0 commit comments

Comments
 (0)