| 18 | static constexpr auto REMOVAL_REASON_DUMMY = MemPoolRemovalReason::REPLACED; |
| 19 | |
| 20 | BOOST_AUTO_TEST_CASE(MempoolRemoveTest) |
| 21 | { |
| 22 | // Test CTxMemPool::remove functionality |
| 23 | |
| 24 | TestMemPoolEntryHelper entry; |
| 25 | // Parent transaction with three children, |
| 26 | // and three grand-children: |
| 27 | CMutableTransaction txParent; |
| 28 | txParent.vin.resize(1); |
| 29 | txParent.vin[0].scriptSig = CScript() << OP_11; |
| 30 | txParent.vout.resize(3); |
| 31 | for (int i = 0; i < 3; i++) |
| 32 | { |
| 33 | txParent.vout[i].scriptPubKey = CScript() << OP_11 << OP_EQUAL; |
| 34 | txParent.vout[i].nValue = 33000LL; |
| 35 | } |
| 36 | CMutableTransaction txChild[3]; |
| 37 | for (int i = 0; i < 3; i++) |
| 38 | { |
| 39 | txChild[i].vin.resize(1); |
| 40 | txChild[i].vin[0].scriptSig = CScript() << OP_11; |
| 41 | txChild[i].vin[0].prevout.hash = txParent.GetHash(); |
| 42 | txChild[i].vin[0].prevout.n = i; |
| 43 | txChild[i].vout.resize(1); |
| 44 | txChild[i].vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; |
| 45 | txChild[i].vout[0].nValue = 11000LL; |
| 46 | } |
| 47 | CMutableTransaction txGrandChild[3]; |
| 48 | for (int i = 0; i < 3; i++) |
| 49 | { |
| 50 | txGrandChild[i].vin.resize(1); |
| 51 | txGrandChild[i].vin[0].scriptSig = CScript() << OP_11; |
| 52 | txGrandChild[i].vin[0].prevout.hash = txChild[i].GetHash(); |
| 53 | txGrandChild[i].vin[0].prevout.n = 0; |
| 54 | txGrandChild[i].vout.resize(1); |
| 55 | txGrandChild[i].vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL; |
| 56 | txGrandChild[i].vout[0].nValue = 11000LL; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | CTxMemPool testPool; |
| 61 | LOCK2(cs_main, testPool.cs); |
| 62 | |
| 63 | // Nothing in pool, remove should do nothing: |
| 64 | unsigned int poolSize = testPool.size(); |
| 65 | testPool.removeRecursive(CTransaction(txParent), REMOVAL_REASON_DUMMY); |
| 66 | BOOST_CHECK_EQUAL(testPool.size(), poolSize); |
| 67 | |
| 68 | // Just the parent: |
| 69 | testPool.addUnchecked(entry.FromTx(txParent)); |
| 70 | poolSize = testPool.size(); |
| 71 | testPool.removeRecursive(CTransaction(txParent), REMOVAL_REASON_DUMMY); |
| 72 | BOOST_CHECK_EQUAL(testPool.size(), poolSize - 1); |
| 73 | |
| 74 | // Parent, children, grandchildren: |
| 75 | testPool.addUnchecked(entry.FromTx(txParent)); |
| 76 | for (int i = 0; i < 3; i++) |
| 77 | { |
nothing calls this directly
no test coverage detected