@@ -67,6 +67,40 @@ Value Find(const std::map<Key, Value>& map, const Key& key)
67
67
return it->second ;
68
68
}
69
69
70
+ BOOST_FIXTURE_TEST_CASE (miniminer_negative, TestChain100Setup)
71
+ {
72
+ CTxMemPool& pool = *Assert (m_node.mempool );
73
+ LOCK2 (::cs_main, pool.cs );
74
+ TestMemPoolEntryHelper entry;
75
+
76
+ // Create a transaction that will be prioritised to have a negative modified fee.
77
+ const CAmount positive_base_fee{1000 };
78
+ const CAmount negative_fee_delta{-50000 };
79
+ const CAmount negative_modified_fees{positive_base_fee + negative_fee_delta};
80
+ BOOST_CHECK (negative_modified_fees < 0 );
81
+ const auto tx_mod_negative = make_tx ({COutPoint{m_coinbase_txns[4 ]->GetHash (), 0 }}, /* num_outputs=*/ 1 );
82
+ pool.addUnchecked (entry.Fee (positive_base_fee).FromTx (tx_mod_negative));
83
+ pool.PrioritiseTransaction (tx_mod_negative->GetHash (), negative_fee_delta);
84
+ const COutPoint only_outpoint{tx_mod_negative->GetHash (), 0 };
85
+
86
+ // When target feerate is 0, transactions with negative fees are not selected.
87
+ node::MiniMiner mini_miner_target0 (pool, {only_outpoint});
88
+ BOOST_CHECK (mini_miner_target0.IsReadyToCalculate ());
89
+ const CFeeRate feerate_zero (0 );
90
+ mini_miner_target0.BuildMockTemplate (feerate_zero);
91
+ // Check the quit condition:
92
+ BOOST_CHECK (negative_modified_fees < feerate_zero.GetFee (pool.GetIter (tx_mod_negative->GetHash ()).value ()->GetTxSize ()));
93
+ BOOST_CHECK (mini_miner_target0.GetMockTemplateTxids ().empty ());
94
+
95
+ // With no target feerate, the template includes all transactions, even negative feerate ones.
96
+ node::MiniMiner mini_miner_no_target (pool, {only_outpoint});
97
+ BOOST_CHECK (mini_miner_no_target.IsReadyToCalculate ());
98
+ mini_miner_no_target.BuildMockTemplate (std::nullopt);
99
+ const auto template_txids{mini_miner_no_target.GetMockTemplateTxids ()};
100
+ BOOST_CHECK_EQUAL (template_txids.size (), 1 );
101
+ BOOST_CHECK (template_txids.count (tx_mod_negative->GetHash ().ToUint256 ()) > 0 );
102
+ }
103
+
70
104
BOOST_FIXTURE_TEST_CASE (miniminer_1p1c, TestChain100Setup)
71
105
{
72
106
CTxMemPool& pool = *Assert (m_node.mempool );
0 commit comments