Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 1,130 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolAncestryTests) { | ||||
pool.GetTransactionAncestry(tc->GetId(), ancestors, descendants); | pool.GetTransactionAncestry(tc->GetId(), ancestors, descendants); | ||||
BOOST_CHECK_EQUAL(ancestors, 3ULL); | BOOST_CHECK_EQUAL(ancestors, 3ULL); | ||||
BOOST_CHECK_EQUAL(descendants, 4ULL); | BOOST_CHECK_EQUAL(descendants, 4ULL); | ||||
pool.GetTransactionAncestry(td->GetId(), ancestors, descendants); | pool.GetTransactionAncestry(td->GetId(), ancestors, descendants); | ||||
BOOST_CHECK_EQUAL(ancestors, 4ULL); | BOOST_CHECK_EQUAL(ancestors, 4ULL); | ||||
BOOST_CHECK_EQUAL(descendants, 4ULL); | BOOST_CHECK_EQUAL(descendants, 4ULL); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(MempoolDynamicUsageTests) { | |||||
CTxMemPool pool; | |||||
BOOST_CHECK_EQUAL(pool.DynamicMemoryUsage(), 0); | |||||
#if !(defined(__x86_64__) and defined(__GLIBCXX__)) | |||||
/* | |||||
* FIXME make the calculated value architecture independent. This will | |||||
* ensure there is no behavior difference between the various Bitcoin ABC | |||||
* versions. | |||||
* For now skip the following tests if the tests is not built for a 64 bits | |||||
* target. | |||||
*/ | |||||
return; | |||||
#endif | |||||
const size_t nTxs = 10; | |||||
std::vector<CTransactionRef> txs(nTxs); | |||||
txs[0] = make_tx(MK_OUTPUTS(1 * COIN)); | |||||
for (size_t i = 1; i < nTxs; i++) { | |||||
txs[i] = make_tx(MK_OUTPUTS(1000 * SATOSHI), MK_INPUTS(txs[i - 1])); | |||||
} | |||||
LOCK2(cs_main, pool.cs); | |||||
TestMemPoolEntryHelper entry; | |||||
pool.addUnchecked(entry.Fee(1000 * SATOSHI).FromTx(txs[0])); | |||||
size_t dynamicMemoryUsage = pool.DynamicMemoryUsage(); | |||||
BOOST_CHECK_EQUAL(dynamicMemoryUsage, 736); | |||||
for (size_t i = 1; i < nTxs; i++) { | |||||
pool.addUnchecked(entry.Fee(1000 * SATOSHI).FromTx(txs[i])); | |||||
BOOST_CHECK_GT(pool.DynamicMemoryUsage(), dynamicMemoryUsage); | |||||
dynamicMemoryUsage = pool.DynamicMemoryUsage(); | |||||
} | |||||
BOOST_CHECK_EQUAL(dynamicMemoryUsage, 9968); | |||||
for (size_t i = nTxs - 1; i > 1; i--) { | |||||
pool.removeRecursive(*txs[i]); | |||||
BOOST_CHECK_LT(pool.DynamicMemoryUsage(), dynamicMemoryUsage); | |||||
dynamicMemoryUsage = pool.DynamicMemoryUsage(); | |||||
} | |||||
BOOST_CHECK_EQUAL(dynamicMemoryUsage, 1776); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |