LCOV - code coverage report
Current view: top level - src/test - txvalidation_tests.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 0 24 0.0 %
Date: 2023-10-05 12:38:51 Functions: 0 11 0.0 %
Branches: 0 0 -

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

Generated by: LCOV version 1.14