|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
5 | 5 | #include <consensus/validation.h>
|
| 6 | +#include <key_io.h> |
6 | 7 | #include <primitives/transaction.h>
|
7 | 8 | #include <script/script.h>
|
| 9 | +#include <script/standard.h> |
8 | 10 | #include <test/util/setup_common.h>
|
9 | 11 | #include <validation.h>
|
10 | 12 |
|
@@ -47,4 +49,42 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
|
47 | 49 | BOOST_CHECK(result.m_state.GetResult() == TxValidationResult::TX_CONSENSUS);
|
48 | 50 | }
|
49 | 51 |
|
| 52 | +BOOST_FIXTURE_TEST_CASE(package_tests, TestChain100Setup) |
| 53 | +{ |
| 54 | + LOCK(cs_main); |
| 55 | + unsigned int initialPoolSize = m_node.mempool->size(); |
| 56 | + |
| 57 | + // Parent and Child Package |
| 58 | + CKey parent_key; |
| 59 | + parent_key.MakeNewKey(true); |
| 60 | + CScript parent_locking_script = GetScriptForDestination(PKHash(parent_key.GetPubKey())); |
| 61 | + auto mtx_parent = CreateValidMempoolTransaction(/* input_transaction */ m_coinbase_txns[0], /* vout */ 0, |
| 62 | + /* input_height */ 0, /* input_signing_key */ coinbaseKey, |
| 63 | + /* output_destination */ parent_locking_script, |
| 64 | + /* output_amount */ CAmount(49 * COIN), /* submit */ false); |
| 65 | + CTransactionRef tx_parent = MakeTransactionRef(mtx_parent); |
| 66 | + |
| 67 | + CKey child_key; |
| 68 | + child_key.MakeNewKey(true); |
| 69 | + CScript child_locking_script = GetScriptForDestination(PKHash(child_key.GetPubKey())); |
| 70 | + auto mtx_child = CreateValidMempoolTransaction(/* input_transaction */ tx_parent, /* vout */ 0, |
| 71 | + /* input_height */ 101, /* input_signing_key */ parent_key, |
| 72 | + /* output_destination */ child_locking_script, |
| 73 | + /* output_amount */ CAmount(48 * COIN), /* submit */ false); |
| 74 | + CTransactionRef tx_child = MakeTransactionRef(mtx_child); |
| 75 | + const auto result_parent_child = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, {tx_parent, tx_child}, /* test_accept */ true); |
| 76 | + BOOST_CHECK_MESSAGE(result_parent_child.m_state.IsValid(), |
| 77 | + "Package validation unexpectedly failed: " << result_parent_child.m_state.GetRejectReason()); |
| 78 | + auto it_parent = result_parent_child.m_tx_results.find(tx_parent->GetWitnessHash()); |
| 79 | + auto it_child = result_parent_child.m_tx_results.find(tx_child->GetWitnessHash()); |
| 80 | + BOOST_CHECK(it_parent != result_parent_child.m_tx_results.end()); |
| 81 | + BOOST_CHECK_MESSAGE(it_parent->second.m_state.IsValid(), |
| 82 | + "Package validation unexpectedly failed: " << it_parent->second.m_state.GetRejectReason()); |
| 83 | + BOOST_CHECK(it_child != result_parent_child.m_tx_results.end()); |
| 84 | + BOOST_CHECK_MESSAGE(it_child->second.m_state.IsValid(), |
| 85 | + "Package validation unexpectedly failed: " << it_child->second.m_state.GetRejectReason()); |
| 86 | + |
| 87 | + // Check that mempool size hasn't changed. |
| 88 | + BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize); |
| 89 | +} |
50 | 90 | BOOST_AUTO_TEST_SUITE_END()
|
0 commit comments