forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#11714: [tests] Test that mempool rejects coinbase trans…
…actions 65e91f5 [tests] Test that mempool rejects coinbase transactions (James O'Beirne) Pull request description:  Neither the unit nor functional tests appear to cover rejecting a transaction from acceptance to the mempool on the basis of it being a coinbase. Seems like a decent thing to have a test for. Tree-SHA512: 53af53c975cad5d7a21c443d71a1c0ced5c70a7799b75bb44d9b7dd6ab2afbcdcaab14571540efeb848f3a1daee5e1dd856530d8f2b50582595219a1c17555ff
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2017 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <validation.h> | ||
#include <txmempool.h> | ||
#include <amount.h> | ||
#include <consensus/validation.h> | ||
#include <primitives/transaction.h> | ||
#include <script/script.h> | ||
#include <test/test_bitcoin.h> | ||
|
||
#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; | ||
|
||
assert(CTransaction(coinbaseTx).IsCoinBase()); | ||
|
||
CValidationState state; | ||
|
||
LOCK(cs_main); | ||
|
||
unsigned int initialPoolSize = mempool.size(); | ||
|
||
BOOST_CHECK_EQUAL( | ||
false, | ||
AcceptToMemoryPool(mempool, state, MakeTransactionRef(coinbaseTx), | ||
nullptr /* pfMissingInputs */, | ||
nullptr /* plTxnReplaced */, | ||
true /* bypass_limits */, | ||
0 /* nAbsurdFee */)); | ||
|
||
// Check that the transaction hasn't been added to mempool. | ||
BOOST_CHECK_EQUAL(mempool.size(), initialPoolSize); | ||
|
||
// Check that the validation state reflects the unsuccesful attempt. | ||
BOOST_CHECK(state.IsInvalid()); | ||
BOOST_CHECK_EQUAL(state.GetRejectReason(), "coinbase"); | ||
|
||
int nDoS; | ||
BOOST_CHECK_EQUAL(state.IsInvalid(nDoS), true); | ||
BOOST_CHECK_EQUAL(nDoS, 100); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |