@@ -420,93 +420,6 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
420420 CheckSort<ancestor_score>(pool, sortedOrder);
421421}
422422
423- // ELEMENTS:
424- BOOST_AUTO_TEST_CASE (PeginSpentTest)
425- {
426- CBlockPolicyEstimator feeEst;
427- CTxMemPool pool (&feeEst);
428- LOCK (pool.cs );
429-
430- std::set<std::pair<uint256, COutPoint> > setPeginsSpent;
431- TestMemPoolEntryHelper entry;
432-
433- std::pair<uint256, COutPoint> pegin1, pegin2, pegin3;
434- GetRandBytes (pegin1.first .begin (), pegin1.first .size ());
435- GetRandBytes (pegin2.first .begin (), pegin2.first .size ());
436- GetRandBytes (pegin3.first .begin (), pegin3.first .size ());
437- GetRandBytes (pegin1.second .hash .begin (), pegin1.second .hash .size ());
438- GetRandBytes (pegin2.second .hash .begin (), pegin2.second .hash .size ());
439- pegin3.second .hash = pegin2.second .hash ;
440- pegin1.second .n = 0 ;
441- pegin2.second .n = 0 ;
442- pegin3.second .n = 1 ;
443-
444- CMutableTransaction tx;
445- tx.vin .resize (1 );
446- tx.vout .resize (1 );
447- tx.vout [0 ].nValue = 0 ;
448- pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
449- BOOST_CHECK (pool.mapPeginsSpentToTxid .empty ());
450-
451- setPeginsSpent = {pegin1};
452- GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
453- tx.vout .resize (2 );
454- tx.vout [1 ].nValue = 0 ;
455- const uint256 tx2Hash (tx.GetHash ());
456- pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
457- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin1].ToString (), tx2Hash.ToString ());
458-
459- setPeginsSpent = {pegin2};
460- GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
461- tx.vout .resize (3 );
462- tx.vout [2 ].nValue = 0 ;
463- const uint256 tx3Hash (tx.GetHash ());
464- pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
465- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin2].ToString (), tx3Hash.ToString ());
466-
467- setPeginsSpent = {pegin3};
468- GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
469- tx.vout .resize (4 );
470- tx.vout [3 ].nValue = 0 ;
471- CTransactionRef txref (MakeTransactionRef (tx));
472- pool.removeForBlock ({txref}, 1 , setPeginsSpent);
473-
474- BOOST_CHECK_EQUAL (pool.size (), 3 );
475- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid .size (), 2 );
476- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin1].ToString (), tx2Hash.ToString ());
477- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin2].ToString (), tx3Hash.ToString ());
478-
479- setPeginsSpent = {pegin1};
480- GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
481- tx.vout .resize (5 );
482- tx.vout [4 ].nValue = 0 ;
483- txref = MakeTransactionRef (tx);
484- pool.removeForBlock ({txref}, 2 , setPeginsSpent);
485-
486- BOOST_CHECK_EQUAL (pool.size (), 2 );
487- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid .size (), 1 );
488- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin2].ToString (), tx3Hash.ToString ());
489-
490- setPeginsSpent = {pegin1, pegin3};
491- GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
492- tx.vout .resize (6 );
493- tx.vout [5 ].nValue = 0 ;
494- const uint256 tx4Hash (tx.GetHash ());
495- pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
496- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin1].ToString (), tx4Hash.ToString ());
497- BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin3].ToString (), tx4Hash.ToString ());
498-
499- setPeginsSpent = {pegin2, pegin3};
500- GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
501- tx.vout .resize (7 );
502- tx.vout [6 ].nValue = 0 ;
503- txref = MakeTransactionRef (tx);
504- pool.removeForBlock ({txref}, 3 , setPeginsSpent);
505-
506- BOOST_CHECK_EQUAL (pool.size (), 1 );
507- BOOST_CHECK (pool.mapPeginsSpentToTxid .empty ());
508- }
509-
510423BOOST_AUTO_TEST_CASE (MempoolSizeLimitTest)
511424{
512425 CTxMemPool pool;
@@ -838,4 +751,91 @@ BOOST_AUTO_TEST_CASE(MempoolAncestryTests)
838751 BOOST_CHECK_EQUAL (descendants, 6ULL );
839752}
840753
754+ // ELEMENTS:
755+ BOOST_AUTO_TEST_CASE (PeginSpentTest)
756+ {
757+ CBlockPolicyEstimator feeEst;
758+ CTxMemPool pool (&feeEst);
759+ LOCK2 (cs_main, pool.cs );
760+
761+ std::set<std::pair<uint256, COutPoint> > setPeginsSpent;
762+ TestMemPoolEntryHelper entry;
763+
764+ std::pair<uint256, COutPoint> pegin1, pegin2, pegin3;
765+ GetRandBytes (pegin1.first .begin (), pegin1.first .size ());
766+ GetRandBytes (pegin2.first .begin (), pegin2.first .size ());
767+ GetRandBytes (pegin3.first .begin (), pegin3.first .size ());
768+ GetRandBytes (pegin1.second .hash .begin (), pegin1.second .hash .size ());
769+ GetRandBytes (pegin2.second .hash .begin (), pegin2.second .hash .size ());
770+ pegin3.second .hash = pegin2.second .hash ;
771+ pegin1.second .n = 0 ;
772+ pegin2.second .n = 0 ;
773+ pegin3.second .n = 1 ;
774+
775+ CMutableTransaction tx;
776+ tx.vin .resize (1 );
777+ tx.vout .resize (1 );
778+ tx.vout [0 ].nValue = 0 ;
779+ pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
780+ BOOST_CHECK (pool.mapPeginsSpentToTxid .empty ());
781+
782+ setPeginsSpent = {pegin1};
783+ GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
784+ tx.vout .resize (2 );
785+ tx.vout [1 ].nValue = 0 ;
786+ const uint256 tx2Hash (tx.GetHash ());
787+ pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
788+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin1].ToString (), tx2Hash.ToString ());
789+
790+ setPeginsSpent = {pegin2};
791+ GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
792+ tx.vout .resize (3 );
793+ tx.vout [2 ].nValue = 0 ;
794+ const uint256 tx3Hash (tx.GetHash ());
795+ pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
796+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin2].ToString (), tx3Hash.ToString ());
797+
798+ setPeginsSpent = {pegin3};
799+ GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
800+ tx.vout .resize (4 );
801+ tx.vout [3 ].nValue = 0 ;
802+ CTransactionRef txref (MakeTransactionRef (tx));
803+ pool.removeForBlock ({txref}, 1 , setPeginsSpent);
804+
805+ BOOST_CHECK_EQUAL (pool.size (), 3 );
806+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid .size (), 2 );
807+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin1].ToString (), tx2Hash.ToString ());
808+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin2].ToString (), tx3Hash.ToString ());
809+
810+ setPeginsSpent = {pegin1};
811+ GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
812+ tx.vout .resize (5 );
813+ tx.vout [4 ].nValue = 0 ;
814+ txref = MakeTransactionRef (tx);
815+ pool.removeForBlock ({txref}, 2 , setPeginsSpent);
816+
817+ BOOST_CHECK_EQUAL (pool.size (), 2 );
818+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid .size (), 1 );
819+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin2].ToString (), tx3Hash.ToString ());
820+
821+ setPeginsSpent = {pegin1, pegin3};
822+ GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
823+ tx.vout .resize (6 );
824+ tx.vout [5 ].nValue = 0 ;
825+ const uint256 tx4Hash (tx.GetHash ());
826+ pool.addUnchecked (entry.PeginsSpent (setPeginsSpent).FromTx (tx));
827+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin1].ToString (), tx4Hash.ToString ());
828+ BOOST_CHECK_EQUAL (pool.mapPeginsSpentToTxid [pegin3].ToString (), tx4Hash.ToString ());
829+
830+ setPeginsSpent = {pegin2, pegin3};
831+ GetRandBytes (tx.vin [0 ].prevout .hash .begin (), tx.vin [0 ].prevout .hash .size ());
832+ tx.vout .resize (7 );
833+ tx.vout [6 ].nValue = 0 ;
834+ txref = MakeTransactionRef (tx);
835+ pool.removeForBlock ({txref}, 3 , setPeginsSpent);
836+
837+ BOOST_CHECK_EQUAL (pool.size (), 1 );
838+ BOOST_CHECK (pool.mapPeginsSpentToTxid .empty ());
839+ }
840+
841841BOOST_AUTO_TEST_SUITE_END ()
0 commit comments