Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show All 14 Lines | |||||
#include <algorithm> | #include <algorithm> | ||||
#include <list> | #include <list> | ||||
#include <vector> | #include <vector> | ||||
BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup) | BOOST_FIXTURE_TEST_SUITE(mempool_tests, TestingSetup) | ||||
BOOST_AUTO_TEST_CASE(TestPackageAccounting) { | BOOST_AUTO_TEST_CASE(TestPackageAccounting) { | ||||
CTxMemPool testPool; | CTxMemPool testPool; | ||||
LOCK(testPool.cs); | LOCK2(cs_main, testPool.cs); | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
CMutableTransaction parentOfAll; | CMutableTransaction parentOfAll; | ||||
std::vector<CTxIn> outpoints; | std::vector<CTxIn> outpoints; | ||||
const size_t maxOutputs = 3; | const size_t maxOutputs = 3; | ||||
// Construct a parent for the rest of the chain | // Construct a parent for the rest of the chain | ||||
parentOfAll.vin.resize(1); | parentOfAll.vin.resize(1); | ||||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolClearTest) { | ||||
txParent.vin[0].scriptSig = CScript() << OP_11; | txParent.vin[0].scriptSig = CScript() << OP_11; | ||||
txParent.vout.resize(3); | txParent.vout.resize(3); | ||||
for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
txParent.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | txParent.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL; | ||||
txParent.vout[i].nValue = 33000 * SATOSHI; | txParent.vout[i].nValue = 33000 * SATOSHI; | ||||
} | } | ||||
CTxMemPool testPool; | CTxMemPool testPool; | ||||
LOCK(testPool.cs); | LOCK2(cs_main, testPool.cs); | ||||
// Nothing in pool, clear should do nothing: | // Nothing in pool, clear should do nothing: | ||||
testPool.clear(); | testPool.clear(); | ||||
BOOST_CHECK_EQUAL(testPool.size(), 0UL); | BOOST_CHECK_EQUAL(testPool.size(), 0UL); | ||||
// Add the transaction | // Add the transaction | ||||
testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); | testPool.addUnchecked(txParent.GetId(), entry.FromTx(txParent)); | ||||
BOOST_CHECK_EQUAL(testPool.size(), 1UL); | BOOST_CHECK_EQUAL(testPool.size(), 1UL); | ||||
▲ Show 20 Lines • Show All 596 Lines • ▼ Show 20 Lines | for (auto &disconnectedTxns : | ||||
DisconnectedBlockTransactions disconnectPool; | DisconnectedBlockTransactions disconnectPool; | ||||
disconnectPool.addForBlock(vtx); | disconnectPool.addForBlock(vtx); | ||||
CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | ||||
disconnectedTxns.size()); | disconnectedTxns.size()); | ||||
// If the mempool is empty, importMempool doesn't change | // If the mempool is empty, importMempool doesn't change | ||||
// disconnectPool | // disconnectPool | ||||
CTxMemPool testPool; | CTxMemPool testPool; | ||||
disconnectPool.importMempool(testPool); | disconnectPool.importMempool(testPool); | ||||
CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | ||||
disconnectedTxns.size()); | disconnectedTxns.size()); | ||||
{ | |||||
LOCK2(cs_main, testPool.cs); | |||||
// Add all unconfirmed transactions in testPool | // Add all unconfirmed transactions in testPool | ||||
for (auto tx : unconfTxns) { | for (auto tx : unconfTxns) { | ||||
TestMemPoolEntryHelper entry; | TestMemPoolEntryHelper entry; | ||||
testPool.addUnchecked(tx->GetId(), entry.FromTx(*tx)); | testPool.addUnchecked(tx->GetId(), entry.FromTx(*tx)); | ||||
} | } | ||||
} | |||||
// Now we test importMempool with a non empty mempool | // Now we test importMempool with a non empty mempool | ||||
disconnectPool.importMempool(testPool); | disconnectPool.importMempool(testPool); | ||||
CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | ||||
disconnectedTxns.size() + | disconnectedTxns.size() + | ||||
unconfTxns.size()); | unconfTxns.size()); | ||||
// We must clear disconnectPool to not trigger the assert in its | // We must clear disconnectPool to not trigger the assert in its | ||||
// destructor | // destructor | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |