Merge #17363: test: add "diamond" unit test to MempoolAncestryTests

b2ff500fb3e4fa05de366ab1900825bea1f70377 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 b2ff500fb3e4fa05de366ab1900825bea1f70377

Tree-SHA512: 82a6573cc7f0e82bf6fcfe207d7ddecbf297d2a203d22e95b73d887e3cb280f45a3c5f649161561c1be1eb560ff81b9b385868f205d1c12284211c2377e5ad99
This commit is contained in:
MarcoFalke 2019-11-05 13:19:46 -05:00 committed by Pasta
parent 06583cc33b
commit ffeffa1927
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -746,6 +746,43 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
pool.GetTransactionAncestry(ty6->GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 9ULL);
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(10000LL).FromTx(ta));
pool.addUnchecked(entry.Fee(10000LL).FromTx(tb));
pool.addUnchecked(entry.Fee(10000LL).FromTx(tc));
pool.addUnchecked(entry.Fee(10000LL).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->GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 1ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL);
pool.GetTransactionAncestry(tb->GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 2ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL);
pool.GetTransactionAncestry(tc->GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 3ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL);
pool.GetTransactionAncestry(td->GetHash(), ancestors, descendants);
BOOST_CHECK_EQUAL(ancestors, 4ULL);
BOOST_CHECK_EQUAL(descendants, 4ULL);
}
BOOST_AUTO_TEST_SUITE_END()