Skip to content

Commit 22e7eea

Browse files
author
MarcoFalke
committed
Merge #17363: test: add "diamond" unit test to MempoolAncestryTests
b2ff500 test: add "diamond" unit test to MempoolAncestryTests (Sebastian Falbesoner) Pull request description: Approaches #17271 (_Missing Unit Test for Ancestors "diamond"_). If ancestors are represented more than once (in this case `ta` and `tb`), check that those are not overcounted. ACKs for top commit: laanwj: ACK b2ff500 Tree-SHA512: 82a6573cc7f0e82bf6fcfe207d7ddecbf297d2a203d22e95b73d887e3cb280f45a3c5f649161561c1be1eb560ff81b9b385868f205d1c12284211c2377e5ad99
2 parents 50591f6 + b2ff500 commit 22e7eea

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/test/mempool_tests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,43 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
749749
pool.GetTransactionAncestry(ty6->GetHash(), ancestors, descendants);
750750
BOOST_CHECK_EQUAL(ancestors, 9ULL);
751751
BOOST_CHECK_EQUAL(descendants, 6ULL);
752+
753+
/* Ancestors represented more than once ("diamond") */
754+
//
755+
// [ta].0 <- [tb].0 -----<------- [td].0
756+
// | |
757+
// \---1 <- [tc].0 --<--/
758+
//
759+
CTransactionRef ta, tb, tc, td;
760+
ta = make_tx(/* output_values */ {10 * COIN});
761+
tb = make_tx(/* output_values */ {5 * COIN, 3 * COIN}, /* inputs */ {ta});
762+
tc = make_tx(/* output_values */ {2 * COIN}, /* inputs */ {tb}, /* input_indices */ {1});
763+
td = make_tx(/* output_values */ {6 * COIN}, /* inputs */ {tb, tc}, /* input_indices */ {0, 0});
764+
pool.clear();
765+
pool.addUnchecked(entry.Fee(10000LL).FromTx(ta));
766+
pool.addUnchecked(entry.Fee(10000LL).FromTx(tb));
767+
pool.addUnchecked(entry.Fee(10000LL).FromTx(tc));
768+
pool.addUnchecked(entry.Fee(10000LL).FromTx(td));
769+
770+
// Ancestors / descendants should be:
771+
// transaction ancestors descendants
772+
// ============ =================== ===========
773+
// ta 1 (ta 4 (ta,tb,tc,td)
774+
// tb 2 (ta,tb) 4 (ta,tb,tc,td)
775+
// tc 3 (ta,tb,tc) 4 (ta,tb,tc,td)
776+
// td 4 (ta,tb,tc,td) 4 (ta,tb,tc,td)
777+
pool.GetTransactionAncestry(ta->GetHash(), ancestors, descendants);
778+
BOOST_CHECK_EQUAL(ancestors, 1ULL);
779+
BOOST_CHECK_EQUAL(descendants, 4ULL);
780+
pool.GetTransactionAncestry(tb->GetHash(), ancestors, descendants);
781+
BOOST_CHECK_EQUAL(ancestors, 2ULL);
782+
BOOST_CHECK_EQUAL(descendants, 4ULL);
783+
pool.GetTransactionAncestry(tc->GetHash(), ancestors, descendants);
784+
BOOST_CHECK_EQUAL(ancestors, 3ULL);
785+
BOOST_CHECK_EQUAL(descendants, 4ULL);
786+
pool.GetTransactionAncestry(td->GetHash(), ancestors, descendants);
787+
BOOST_CHECK_EQUAL(ancestors, 4ULL);
788+
BOOST_CHECK_EQUAL(descendants, 4ULL);
752789
}
753790

754791
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)