1 // Copyright (c) 2017 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.
5 #include <validation.h>
8 #include <consensus/validation.h>
9 #include <primitives/transaction.h>
10 #include <script/script.h>
11 #include <test/test_bitcoin.h>
13 #include <boost/test/unit_test.hpp>
16 BOOST_AUTO_TEST_SUITE(txvalidation_tests
)
19 * Ensure that the mempool won't accept coinbase transactions.
21 BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase
, TestChain100Setup
)
23 CScript scriptPubKey
= CScript() << ToByteVector(coinbaseKey
.GetPubKey()) << OP_CHECKSIG
;
24 CMutableTransaction coinbaseTx
;
26 coinbaseTx
.nVersion
= 1;
27 coinbaseTx
.vin
.resize(1);
28 coinbaseTx
.vout
.resize(1);
29 coinbaseTx
.vin
[0].scriptSig
= CScript() << OP_11
<< OP_EQUAL
;
30 coinbaseTx
.vout
[0].nValue
= 1 * CENT
;
31 coinbaseTx
.vout
[0].scriptPubKey
= scriptPubKey
;
33 assert(CTransaction(coinbaseTx
).IsCoinBase());
35 CValidationState state
;
39 unsigned int initialPoolSize
= mempool
.size();
43 AcceptToMemoryPool(mempool
, state
, MakeTransactionRef(coinbaseTx
),
44 nullptr /* pfMissingInputs */,
45 nullptr /* plTxnReplaced */,
46 true /* bypass_limits */,
49 // Check that the transaction hasn't been added to mempool.
50 BOOST_CHECK_EQUAL(mempool
.size(), initialPoolSize
);
52 // Check that the validation state reflects the unsuccessful attempt.
53 BOOST_CHECK(state
.IsInvalid());
54 BOOST_CHECK_EQUAL(state
.GetRejectReason(), "coinbase");
57 BOOST_CHECK_EQUAL(state
.IsInvalid(nDoS
), true);
58 BOOST_CHECK_EQUAL(nDoS
, 100);
61 BOOST_AUTO_TEST_SUITE_END()