Changeset View
Changeset View
Standalone View
Standalone View
src/test/mempool_tests.cpp
Show First 20 Lines • Show All 1,036 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(MempoolAncestryTests) { | ||||
BOOST_CHECK_EQUAL(ancestors, 4ULL); | BOOST_CHECK_EQUAL(ancestors, 4ULL); | ||||
BOOST_CHECK_EQUAL(descendants, 6ULL); | BOOST_CHECK_EQUAL(descendants, 6ULL); | ||||
pool.GetTransactionAncestry(ty5->GetId(), ancestors, descendants); | pool.GetTransactionAncestry(ty5->GetId(), ancestors, descendants); | ||||
BOOST_CHECK_EQUAL(ancestors, 5ULL); | BOOST_CHECK_EQUAL(ancestors, 5ULL); | ||||
BOOST_CHECK_EQUAL(descendants, 6ULL); | BOOST_CHECK_EQUAL(descendants, 6ULL); | ||||
pool.GetTransactionAncestry(ty6->GetId(), ancestors, descendants); | pool.GetTransactionAncestry(ty6->GetId(), ancestors, descendants); | ||||
BOOST_CHECK_EQUAL(ancestors, 9ULL); | BOOST_CHECK_EQUAL(ancestors, 9ULL); | ||||
BOOST_CHECK_EQUAL(descendants, 6ULL); | BOOST_CHECK_EQUAL(descendants, 6ULL); | ||||
/* Ancestors represented more than once ("diamond") */ | |||||
// | |||||
// [ta].0 <- [tb].0 -----<------- [td].0 | |||||
// | | | |||||
// \---1 <- [tc].0 --<--/ | |||||
// | |||||
CTransactionRef ta, tb, tc, td; | |||||
ta = make_tx(/* output_values */ {10 * COIN}); | |||||
tb = make_tx(/* output_values */ {5 * COIN, 3 * COIN}, /* inputs */ {ta}); | |||||
tc = make_tx(/* output_values */ {2 * COIN}, /* inputs */ {tb}, | |||||
/* input_indices */ {1}); | |||||
td = make_tx(/* output_values */ {6 * COIN}, /* inputs */ {tb, tc}, | |||||
/* input_indices */ {0, 0}); | |||||
pool.clear(); | |||||
pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(ta)); | |||||
pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tb)); | |||||
pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(tc)); | |||||
pool.addUnchecked(entry.Fee(10000 * SATOSHI).FromTx(td)); | |||||
// Ancestors / descendants should be: | |||||
// transaction ancestors descendants | |||||
// ============ =================== =========== | |||||
// ta 1 (ta 4 (ta,tb,tc,td) | |||||
// tb 2 (ta,tb) 4 (ta,tb,tc,td) | |||||
// tc 3 (ta,tb,tc) 4 (ta,tb,tc,td) | |||||
// td 4 (ta,tb,tc,td) 4 (ta,tb,tc,td) | |||||
pool.GetTransactionAncestry(ta->GetId(), ancestors, descendants); | |||||
BOOST_CHECK_EQUAL(ancestors, 1ULL); | |||||
BOOST_CHECK_EQUAL(descendants, 4ULL); | |||||
pool.GetTransactionAncestry(tb->GetId(), ancestors, descendants); | |||||
BOOST_CHECK_EQUAL(ancestors, 2ULL); | |||||
BOOST_CHECK_EQUAL(descendants, 4ULL); | |||||
pool.GetTransactionAncestry(tc->GetId(), ancestors, descendants); | |||||
BOOST_CHECK_EQUAL(ancestors, 3ULL); | |||||
BOOST_CHECK_EQUAL(descendants, 4ULL); | |||||
pool.GetTransactionAncestry(td->GetId(), ancestors, descendants); | |||||
BOOST_CHECK_EQUAL(ancestors, 4ULL); | |||||
BOOST_CHECK_EQUAL(descendants, 4ULL); | |||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |