Line data Source code
1 : // Copyright (c) 2017-2021 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 <key_io.h> 7 : #include <policy/packages.h> 8 : #include <policy/policy.h> 9 : #include <primitives/transaction.h> 10 : #include <script/script.h> 11 : #include <script/standard.h> 12 : #include <test/util/setup_common.h> 13 : #include <validation.h> 14 : 15 : #include <boost/test/unit_test.hpp> 16 : 17 : 18 : struct TestChain100NoDIP0001Setup : public TestChain100Setup { 19 : TestChain100NoDIP0001Setup() 20 : : TestChain100Setup{CBaseChainParams::REGTEST, {"-testactivationheight=dip0001@2000"}} {} 21 : }; 22 : 23 : 24 146 : BOOST_AUTO_TEST_SUITE(txvalidation_tests) 25 : 26 : /** 27 : * Ensure that the mempool won't accept coinbase transactions. 28 : */ 29 149 : BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) 30 : { 31 1 : CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; 32 1 : CMutableTransaction coinbaseTx; 33 : 34 1 : coinbaseTx.nVersion = 1; 35 1 : coinbaseTx.vin.resize(1); 36 1 : coinbaseTx.vout.resize(1); 37 1 : coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL; 38 1 : coinbaseTx.vout[0].nValue = 1 * CENT; 39 1 : coinbaseTx.vout[0].scriptPubKey = scriptPubKey; 40 : 41 1 : BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase()); 42 : 43 1 : LOCK(cs_main); 44 : 45 1 : unsigned int initialPoolSize = m_node.mempool->size(); 46 1 : const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(coinbaseTx)); 47 : 48 1 : BOOST_CHECK(result.m_result_type == MempoolAcceptResult::ResultType::INVALID); 49 : 50 : // Check that the transaction hasn't been added to mempool. 51 1 : BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize); 52 : 53 : // Check that the validation state reflects the unsuccessful attempt. 54 1 : BOOST_CHECK(result.m_state.IsInvalid()); 55 1 : BOOST_CHECK_EQUAL(result.m_state.GetRejectReason(), "coinbase"); 56 1 : BOOST_CHECK(result.m_state.GetResult() == TxValidationResult::TX_CONSENSUS); 57 1 : } 58 146 : BOOST_AUTO_TEST_SUITE_END()