Line data Source code
1 : // Copyright (c) 2017-2020 The Bitcoin Core developers 2 : // Distributed under the MIT software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #include <consensus/validation.h> 6 : #include <primitives/transaction.h> 7 : #include <script/script.h> 8 : #include <test/util/setup_common.h> 9 : #include <validation.h> 10 : 11 : #include <boost/test/unit_test.hpp> 12 : 13 : 14 89 : BOOST_AUTO_TEST_SUITE(txvalidation_tests) 15 : 16 : /** 17 : * Ensure that the mempool won't accept coinbase transactions. 18 : */ 19 95 : BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) 20 : { 21 1 : CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; 22 1 : CMutableTransaction coinbaseTx; 23 : 24 1 : coinbaseTx.nVersion = 1; 25 1 : coinbaseTx.vin.resize(1); 26 1 : coinbaseTx.vout.resize(1); 27 1 : coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL; 28 1 : coinbaseTx.vout[0].nValue = 1 * CENT; 29 1 : coinbaseTx.vout[0].scriptPubKey = scriptPubKey; 30 : 31 1 : BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase()); 32 : 33 1 : TxValidationState state; 34 : 35 1 : LOCK(cs_main); 36 : 37 1 : unsigned int initialPoolSize = m_node.mempool->size(); 38 : 39 1 : BOOST_CHECK_EQUAL( 40 : false, 41 : AcceptToMemoryPool(*m_node.mempool, state, MakeTransactionRef(coinbaseTx), 42 : nullptr /* plTxnReplaced */, 43 : true /* bypass_limits */, 44 : 0 /* nAbsurdFee */)); 45 : 46 : // Check that the transaction hasn't been added to mempool. 47 1 : BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize); 48 : 49 : // Check that the validation state reflects the unsuccessful attempt. 50 1 : BOOST_CHECK(state.IsInvalid()); 51 1 : BOOST_CHECK_EQUAL(state.GetRejectReason(), "coinbase"); 52 1 : BOOST_CHECK(state.GetResult() == TxValidationResult::TX_CONSENSUS); 53 1 : } 54 : 55 89 : BOOST_AUTO_TEST_SUITE_END()