Skip to content

Commit

Permalink
test: unit test for ImprovesFeerateDiagram
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Jan 19, 2024
1 parent fca8475 commit a4b92cf
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/rbf_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,42 @@ BOOST_FIXTURE_TEST_CASE(rbf_helper_functions, TestChain100Setup)
BOOST_CHECK(pool.CheckConflictTopology({entry9_unchained, entry10_child2, entry11_unchained}).has_value());
}

BOOST_FIXTURE_TEST_CASE(improves_feerate, TestChain100Setup)
{
CTxMemPool& pool = *Assert(m_node.mempool);
LOCK2(::cs_main, pool.cs);
TestMemPoolEntryHelper entry;

const CAmount low_fee{CENT/100};
const CAmount normal_fee{CENT/10};

// One low feerate txn followed be normal feerate
const auto tx1 = make_tx(/*inputs=*/ {m_coinbase_txns[0]}, /*output_values=*/ {10 * COIN});
pool.addUnchecked(entry.Fee(low_fee).FromTx(tx1));
const auto tx2 = make_tx(/*inputs=*/ {tx1}, /*output_values=*/ {995 * CENT});
pool.addUnchecked(entry.Fee(normal_fee).FromTx(tx2));

const auto entry1 = pool.GetIter(tx1->GetHash()).value();
const auto tx1_fee = entry1->GetModifiedFee();
const auto tx1_size = entry1->GetTxSize();
const auto entry2 = pool.GetIter(tx2->GetHash()).value();
const auto tx2_fee = entry2->GetModifiedFee();
const auto tx2_size = entry2->GetTxSize();

// Now test ImprovesFeerateDiagram with various levels of "package rbf" feerates

// It doesn't improve itself
BOOST_CHECK(ImprovesFeerateDiagram(pool, {entry1}, {entry1, entry2}, tx1_fee + tx2_fee, tx1_size + tx2_size).has_value());

// With one more satoshi it does
BOOST_CHECK(ImprovesFeerateDiagram(pool, {entry1}, {entry1, entry2}, tx1_fee + tx2_fee + 1, tx1_size + tx2_size) == std::nullopt);

// Make conflict un-calculable(for now)
const auto tx3 = make_tx(/*inputs=*/ {tx2}, /*output_values=*/ {995 * CENT});
pool.addUnchecked(entry.Fee(normal_fee).FromTx(tx3));
BOOST_CHECK(ImprovesFeerateDiagram(pool, {entry1}, {entry1, entry2}, tx1_fee + tx2_fee + 1, tx1_size + tx2_size).has_value());
}

BOOST_AUTO_TEST_CASE(feerate_diagram_utilities)
{
// Sanity check the correctness of the feerate diagram comparison.
Expand Down

0 comments on commit a4b92cf

Please sign in to comment.