LCOV - code coverage report
Current view: top level - src/test - txvalidation_tests.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 19 19 100.0 %
Date: 2022-04-21 14:51:19 Functions: 1 1 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

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

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a