15#include <boost/test/unit_test.hpp>
29 coinbaseTx.
vin.resize(1);
30 coinbaseTx.
vout.resize(1);
32 coinbaseTx.
vout[0].nValue = 1 *
CENT;
33 coinbaseTx.
vout[0].scriptPubKey = scriptPubKey;
58 mtx.
vin.resize(num_inputs);
59 mtx.
vout.resize(num_outputs);
61 for (
size_t i{0}; i < num_inputs; ++i) {
63 mtx.
vin[i].prevout.n = 0;
64 mtx.
vin[i].scriptSig = random_script;
66 for (
size_t o{0}; o < num_outputs; ++o) {
68 mtx.
vout[o].scriptPubKey = random_script;
82 auto mtx_parent = CreateValidMempoolTransaction( m_coinbase_txns[0], 0,
84 parent_locking_script,
91 auto mtx_child = CreateValidMempoolTransaction( tx_parent, 0,
97 BOOST_CHECK_MESSAGE(result_parent_child.m_state.IsValid(),
98 "Package validation unexpectedly failed: " << result_parent_child.m_state.GetRejectReason());
99 auto it_parent = result_parent_child.m_tx_results.find(tx_parent->GetWitnessHash());
100 auto it_child = result_parent_child.m_tx_results.find(tx_child->GetWitnessHash());
101 BOOST_CHECK(it_parent != result_parent_child.m_tx_results.end());
102 BOOST_CHECK_MESSAGE(it_parent->second.m_state.IsValid(),
103 "Package validation unexpectedly failed: " << it_parent->second.m_state.GetRejectReason());
104 BOOST_CHECK(it_child != result_parent_child.m_tx_results.end());
105 BOOST_CHECK_MESSAGE(it_child->second.m_state.IsValid(),
106 "Package validation unexpectedly failed: " << it_child->second.m_state.GetRejectReason());
117 BOOST_CHECK_EQUAL(result_too_many.m_state.GetRejectReason(),
"package-too-many-transactions");
123 size_t total_size{0};
125 package_too_large.push_back(large_ptx);
126 total_size += size_large;
132 BOOST_CHECK_EQUAL(result_too_large.m_state.GetRejectReason(),
"package-too-large");
138 BOOST_CHECK(result_single_large.m_state.IsInvalid());
140 BOOST_CHECK_EQUAL(result_single_large.m_state.GetRejectReason(),
"transaction failed");
141 auto it_giant_tx = result_single_large.m_tx_results.find(giant_ptx->GetWitnessHash());
142 BOOST_CHECK(it_giant_tx != result_single_large.m_tx_results.end());
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
std::string GetRejectReason() const
@ TX_CONSENSUS
invalid by consensus rules
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
static constexpr uint32_t MAX_PACKAGE_SIZE
Default maximum total virtual size of transactions in a package in KvB.
@ PCKG_POLICY
The package itself is invalid (e.g. too many transactions).
@ PCKG_TX
At least one tx is invalid.
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
std::vector< unsigned char > ToByteVector(const T &in)
static constexpr CAmount CENT
static uint256 InsecureRand256()
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Validation result for a single transaction mempool acceptance.
const ResultType m_result_type
const TxValidationState m_state
@ INVALID
Fully validated, valid.
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< CTxMemPool > mempool
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
Ensure that the mempool won't accept coinbase transactions.
CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outputs)
PackageMempoolAcceptResult ProcessNewPackage(CChainState &active_chainstate, CTxMemPool &pool, const Package &package, bool test_accept)
Atomically test acceptance of a package.
MempoolAcceptResult AcceptToMemoryPool(CChainState &active_chainstate, CTxMemPool &pool, const CTransactionRef &tx, bool bypass_limits, bool test_accept)
(Try to) add a transaction to the memory pool.