Bitcoin Core
26.1.0
P2P Digital Currency
src
test
txvalidation_tests.cpp
Go to the documentation of this file.
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
BOOST_AUTO_TEST_SUITE
(txvalidation_tests)
18
19
22
BOOST_FIXTURE_TEST_CASE
(tx_mempool_reject_coinbase,
TestChain100Setup
)
23
{
24
CScript
scriptPubKey =
CScript
() <<
ToByteVector
(coinbaseKey.GetPubKey()) <<
OP_CHECKSIG
;
25
CMutableTransaction
coinbaseTx;
26
27
coinbaseTx.
nVersion
= 1;
28
coinbaseTx.vin.resize(1);
29
coinbaseTx.vout.resize(1);
30
coinbaseTx.vin[0].scriptSig =
CScript
() <<
OP_11
<<
OP_EQUAL
;
31
coinbaseTx.vout[0].nValue = 1 *
CENT
;
32
coinbaseTx.vout[0].scriptPubKey = scriptPubKey;
33
34
BOOST_CHECK
(
CTransaction
(coinbaseTx).IsCoinBase());
35
36
LOCK
(
cs_main
);
37
38
unsigned
int
initialPoolSize =
m_node
.
mempool
->size();
39
const
MempoolAcceptResult
result =
m_node
.
chainman
->ProcessTransaction(
MakeTransactionRef
(coinbaseTx));
40
41
BOOST_CHECK
(result.
m_result_type
==
MempoolAcceptResult::ResultType::INVALID
);
42
43
// Check that the transaction hasn't been added to mempool.
44
BOOST_CHECK_EQUAL
(
m_node
.
mempool
->size(), initialPoolSize);
45
46
// Check that the validation state reflects the unsuccessful attempt.
47
BOOST_CHECK
(result.
m_state
.
IsInvalid
());
48
BOOST_CHECK_EQUAL
(result.
m_state
.
GetRejectReason
(),
"coinbase"
);
49
BOOST_CHECK
(result.
m_state
.
GetResult
() ==
TxValidationResult::TX_CONSENSUS
);
50
}
51
BOOST_AUTO_TEST_SUITE_END
()
packages.h
TxValidationResult::TX_CONSENSUS
invalid by consensus rules
transaction.h
m_node
node::NodeContext m_node
Definition:
bitcoin-gui.cpp:37
OP_CHECKSIG
Definition:
script.h:188
CMutableTransaction::nVersion
int32_t nVersion
Definition:
transaction.h:383
MempoolAcceptResult::m_state
const TxValidationState m_state
Contains information about why the transaction failed.
Definition:
validation.h:131
MempoolAcceptResult::m_result_type
const ResultType m_result_type
Result type.
Definition:
validation.h:128
OP_EQUAL
Definition:
script.h:144
node::NodeContext::mempool
std::unique_ptr< CTxMemPool > mempool
Definition:
context.h:55
OP_11
Definition:
script.h:92
key_io.h
LOCK
#define LOCK(cs)
Definition:
sync.h:258
script.h
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
setup_common.h
policy.h
validation.h
ValidationState::GetResult
Result GetResult() const
Definition:
validation.h:124
MempoolAcceptResult::ResultType::INVALID
Fully validated, valid.
TestChain100Setup
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition:
setup_common.h:98
MempoolAcceptResult
Validation result for a single transaction mempool acceptance.
Definition:
validation.h:119
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition:
transaction.h:422
BOOST_FIXTURE_TEST_CASE
BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
Ensure that the mempool won't accept coinbase transactions.
Definition:
txvalidation_tests.cpp:22
ToByteVector
std::vector< unsigned char > ToByteVector(const T &in)
Definition:
script.h:65
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition:
object.cpp:18
CScript
Serialized script, used inside transaction inputs and outputs.
Definition:
script.h:412
ValidationState::IsInvalid
bool IsInvalid() const
Definition:
validation.h:122
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
CMutableTransaction
A mutable version of CTransaction.
Definition:
transaction.h:379
CENT
static constexpr CAmount CENT
Definition:
setup_common.h:44
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition:
transaction.h:294
ValidationState::GetRejectReason
std::string GetRejectReason() const
Definition:
validation.h:125
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition:
cs_main.cpp:8
node::NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition:
context.h:59
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition:
object.cpp:17
Generated on Thu Mar 28 2024 12:00:00 for Bitcoin Core by
1.8.14