mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-06 18:01:03 +02:00
test: Replace recursive lock with locking annotations
Also, use m_node.mempool instead of the global
This commit is contained in:
parent
fac07f2038
commit
8888ad02e2
@ -23,7 +23,17 @@
|
|||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
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<CTransactionRef>& 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
|
// BOOST_CHECK_EXCEPTION predicates to check the specific validation error
|
||||||
class HasReason {
|
class HasReason {
|
||||||
@ -89,16 +99,10 @@ static CBlockIndex CreateBlockIndex(int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_mai
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool TestSequenceLocks(const CTransaction &tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
|
||||||
{
|
|
||||||
LOCK(::mempool.cs);
|
|
||||||
return CheckSequenceLocks(::mempool, tx, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test suite for ancestor feerate transaction selection.
|
// Test suite for ancestor feerate transaction selection.
|
||||||
// Implemented as an additional function, rather than a separate test case,
|
// Implemented as an additional function, rather than a separate test case,
|
||||||
// to allow reusing the blockchain created in CreateNewBlock_validity.
|
// to allow reusing the blockchain created in CreateNewBlock_validity.
|
||||||
static void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs)
|
void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst)
|
||||||
{
|
{
|
||||||
// Test the ancestor feerate transaction selection.
|
// Test the ancestor feerate transaction selection.
|
||||||
TestMemPoolEntryHelper entry;
|
TestMemPoolEntryHelper entry;
|
||||||
|
@ -17,16 +17,6 @@ bool CheckInputs(const CTransaction& tx, TxValidationState &state, const CCoinsV
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
|
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
|
||||||
|
|
||||||
static bool
|
|
||||||
ToMemPool(const CMutableTransaction& tx)
|
|
||||||
{
|
|
||||||
LOCK(cs_main);
|
|
||||||
|
|
||||||
TxValidationState state;
|
|
||||||
return AcceptToMemoryPool(mempool, state, MakeTransactionRef(tx),
|
|
||||||
nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
|
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
|
||||||
{
|
{
|
||||||
// Make sure skipping validation of transactions that were
|
// Make sure skipping validation of transactions that were
|
||||||
@ -35,6 +25,14 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
|
|||||||
|
|
||||||
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
||||||
|
|
||||||
|
const auto ToMemPool = [this](const CMutableTransaction& tx) {
|
||||||
|
LOCK(cs_main);
|
||||||
|
|
||||||
|
TxValidationState state;
|
||||||
|
return AcceptToMemoryPool(*m_node.mempool, state, MakeTransactionRef(tx),
|
||||||
|
nullptr /* plTxnReplaced */, true /* bypass_limits */, 0 /* nAbsurdFee */);
|
||||||
|
};
|
||||||
|
|
||||||
// Create a double-spend of mature coinbase txn:
|
// Create a double-spend of mature coinbase txn:
|
||||||
std::vector<CMutableTransaction> spends;
|
std::vector<CMutableTransaction> spends;
|
||||||
spends.resize(2);
|
spends.resize(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user