@@ -105,63 +105,52 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
105105{
106106 CTxMemPool pool (CFeeRate (0 ));
107107
108- /* 3rd highest fee, 2nd highest priority */
108+ /* 3rd highest fee */
109109 CMutableTransaction tx1 = CMutableTransaction ();
110110 tx1.vout .resize (1 );
111111 tx1.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
112112 tx1.vout [0 ].nValue = 10 * COIN;
113113 pool.addUnchecked (tx1.GetHash (), CTxMemPoolEntry (tx1, 10000LL , 0 , 10.0 , 1 , true ));
114114
115- /* highest fee, 3rd highest priority */
115+ /* highest fee */
116116 CMutableTransaction tx2 = CMutableTransaction ();
117117 tx2.vout .resize (1 );
118118 tx2.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
119119 tx2.vout [0 ].nValue = 2 * COIN;
120120 pool.addUnchecked (tx2.GetHash (), CTxMemPoolEntry (tx2, 20000LL , 0 , 9.0 , 1 , true ));
121121
122- /* lowest fee, highest priority */
122+ /* lowest fee */
123123 CMutableTransaction tx3 = CMutableTransaction ();
124124 tx3.vout .resize (1 );
125125 tx3.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
126126 tx3.vout [0 ].nValue = 5 * COIN;
127127 pool.addUnchecked (tx3.GetHash (), CTxMemPoolEntry (tx3, 0LL , 0 , 100.0 , 1 , true ));
128128
129- /* 2nd highest fee, lowest priority */
129+ /* 2nd highest fee */
130130 CMutableTransaction tx4 = CMutableTransaction ();
131131 tx4.vout .resize (1 );
132132 tx4.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
133133 tx4.vout [0 ].nValue = 6 * COIN;
134134 pool.addUnchecked (tx4.GetHash (), CTxMemPoolEntry (tx4, 15000LL , 0 , 1.0 , 1 , true ));
135135
136+ /* equal fee rate to tx1, but newer */
137+ CMutableTransaction tx5 = CMutableTransaction ();
138+ tx5.vout .resize (1 );
139+ tx5.vout [0 ].scriptPubKey = CScript () << OP_11 << OP_EQUAL;
140+ tx5.vout [0 ].nValue = 11 * COIN;
141+ pool.addUnchecked (tx5.GetHash (), CTxMemPoolEntry (tx5, 10000LL , 1 , 10.0 , 1 , true ));
142+
136143 // there should be 4 transactions in the mempool
137- BOOST_CHECK_EQUAL (pool.size (), 4 );
144+ BOOST_CHECK_EQUAL (pool.size (), 5 );
138145
139- // Check the fee-rate index is in order, should be tx2, tx4, tx1, tx3
146+ // Check the fee-rate index is in order, should be tx2, tx4, tx1, tx5, tx3
140147 CTxMemPool::indexed_transaction_set::nth_index<1 >::type::iterator it = pool.mapTx .get <1 >().begin ();
141148 BOOST_CHECK_EQUAL (it++->GetTx ().GetHash ().ToString (), tx2.GetHash ().ToString ());
142149 BOOST_CHECK_EQUAL (it++->GetTx ().GetHash ().ToString (), tx4.GetHash ().ToString ());
143150 BOOST_CHECK_EQUAL (it++->GetTx ().GetHash ().ToString (), tx1.GetHash ().ToString ());
151+ BOOST_CHECK_EQUAL (it++->GetTx ().GetHash ().ToString (), tx5.GetHash ().ToString ());
144152 BOOST_CHECK_EQUAL (it++->GetTx ().GetHash ().ToString (), tx3.GetHash ().ToString ());
145153 BOOST_CHECK (it == pool.mapTx .get <1 >().end ());
146-
147- // Check the priority index is in order, should be tx3, tx1, tx2, tx4
148- CTxMemPool::indexed_transaction_set::nth_index<2 >::type::iterator it2 = pool.mapTx .get <2 >().begin ();
149- BOOST_CHECK_EQUAL (it2++->GetTx ().GetHash ().ToString (), tx3.GetHash ().ToString ());
150- BOOST_CHECK_EQUAL (it2++->GetTx ().GetHash ().ToString (), tx1.GetHash ().ToString ());
151- BOOST_CHECK_EQUAL (it2++->GetTx ().GetHash ().ToString (), tx2.GetHash ().ToString ());
152- BOOST_CHECK_EQUAL (it2++->GetTx ().GetHash ().ToString (), tx4.GetHash ().ToString ());
153- BOOST_CHECK (it2 == pool.mapTx .get <2 >().end ());
154-
155- // Now advance the height of the mempool by 1 block
156- pool.recalcPriorities (2 );
157-
158- // Check the priority index has been adjusted. Should be tx1, tx4, tx3, tx2
159- CTxMemPool::indexed_transaction_set::nth_index<2 >::type::iterator it3 = pool.mapTx .get <2 >().begin ();
160- BOOST_CHECK_EQUAL (it3++->GetTx ().GetHash ().ToString (), tx1.GetHash ().ToString ());
161- BOOST_CHECK_EQUAL (it3++->GetTx ().GetHash ().ToString (), tx4.GetHash ().ToString ());
162- BOOST_CHECK_EQUAL (it3++->GetTx ().GetHash ().ToString (), tx3.GetHash ().ToString ());
163- BOOST_CHECK_EQUAL (it3++->GetTx ().GetHash ().ToString (), tx2.GetHash ().ToString ());
164- BOOST_CHECK (it3 == pool.mapTx .get <2 >().end ());
165154}
166155
167156BOOST_AUTO_TEST_SUITE_END ()
0 commit comments