2019-04-11 09:53:04 -04:00
|
|
|
// Copyright (c) 2017-2019 The Bitcoin Core developers
|
2017-11-18 05:48:34 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <validation.h>
|
|
|
|
#include <consensus/validation.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
|
|
#include <script/script.h>
|
2019-11-05 17:18:59 -03:00
|
|
|
#include <test/util/setup_common.h>
|
2017-11-18 05:48:34 -03:00
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(txvalidation_tests)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that the mempool won't accept coinbase transactions.
|
|
|
|
*/
|
|
|
|
BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
|
|
|
|
{
|
|
|
|
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
|
|
|
CMutableTransaction coinbaseTx;
|
|
|
|
|
|
|
|
coinbaseTx.nVersion = 1;
|
|
|
|
coinbaseTx.vin.resize(1);
|
|
|
|
coinbaseTx.vout.resize(1);
|
|
|
|
coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL;
|
|
|
|
coinbaseTx.vout[0].nValue = 1 * CENT;
|
|
|
|
coinbaseTx.vout[0].scriptPubKey = scriptPubKey;
|
|
|
|
|
2018-06-26 11:19:31 -04:00
|
|
|
BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase());
|
2017-11-18 05:48:34 -03:00
|
|
|
|
2019-10-24 12:35:42 -03:00
|
|
|
TxValidationState state;
|
2017-11-18 05:48:34 -03:00
|
|
|
|
|
|
|
LOCK(cs_main);
|
|
|
|
|
2019-11-08 13:10:13 -03:00
|
|
|
unsigned int initialPoolSize = m_node.mempool->size();
|
2017-11-18 05:48:34 -03:00
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(
|
|
|
|
false,
|
2019-11-08 13:10:13 -03:00
|
|
|
AcceptToMemoryPool(*m_node.mempool, state, MakeTransactionRef(coinbaseTx),
|
2017-11-18 05:48:34 -03:00
|
|
|
nullptr /* plTxnReplaced */,
|
|
|
|
true /* bypass_limits */,
|
|
|
|
0 /* nAbsurdFee */));
|
|
|
|
|
|
|
|
// Check that the transaction hasn't been added to mempool.
|
2019-11-08 13:10:13 -03:00
|
|
|
BOOST_CHECK_EQUAL(m_node.mempool->size(), initialPoolSize);
|
2017-11-18 05:48:34 -03:00
|
|
|
|
2017-11-21 15:14:35 -03:00
|
|
|
// Check that the validation state reflects the unsuccessful attempt.
|
2017-11-18 05:48:34 -03:00
|
|
|
BOOST_CHECK(state.IsInvalid());
|
|
|
|
BOOST_CHECK_EQUAL(state.GetRejectReason(), "coinbase");
|
2019-10-24 12:35:42 -03:00
|
|
|
BOOST_CHECK(state.GetResult() == TxValidationResult::TX_CONSENSUS);
|
2017-11-18 05:48:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|