Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 877 Lines • ▼ Show 20 Lines | for (auto &disconnectedTxns : | ||||
CTxMemPool testPool; | CTxMemPool testPool; | ||||
// addForBlock inserts disconnectTxns in disconnectPool. They | // addForBlock inserts disconnectTxns in disconnectPool. They | ||||
// simulate transactions that were once confirmed in a block | // simulate transactions that were once confirmed in a block | ||||
std::vector<CTransactionRef> vtx; | std::vector<CTransactionRef> vtx; | ||||
for (auto tx : disconnectedTxns) { | for (auto tx : disconnectedTxns) { | ||||
vtx.push_back(MakeTransactionRef(*tx)); | vtx.push_back(MakeTransactionRef(*tx)); | ||||
} | } | ||||
DisconnectedBlockTransactions disconnectPool; | DisconnectedBlockTransactions disconnectPool; | ||||
LOCK(testPool.cs); | |||||
{ | |||||
disconnectPool.addForBlock(vtx, testPool); | disconnectPool.addForBlock(vtx, testPool); | ||||
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 | ||||
disconnectPool.importMempool(testPool); | disconnectPool.importMempool(testPool); | ||||
CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | CheckDisconnectPoolOrder(disconnectPool, correctlyOrderedIds, | ||||
disconnectedTxns.size()); | disconnectedTxns.size()); | ||||
{ | { | ||||
LOCK2(cs_main, testPool.cs); | LOCK(cs_main); | ||||
// 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(entry.FromTx(*tx)); | testPool.addUnchecked(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 | ||||
disconnectPool.clear(); | disconnectPool.clear(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 226 Lines • Show Last 20 Lines |