6#include <chainparams.h>
28#include <boost/test/unit_test.hpp>
45 std::shared_ptr<CBlock>
FinalizeBlock(std::shared_ptr<CBlock> pblock);
67 m_expected_tip = block->GetHash();
75 m_expected_tip = block->hashPrevBlock;
79std::shared_ptr<CBlock> MinerTestingSetup::Block(
const uint256& prev_hash)
90 pblock->hashPrevBlock = prev_hash;
91 pblock->nTime = ++time;
111std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock> pblock)
131std::shared_ptr<const CBlock> MinerTestingSetup::GoodBlock(
const uint256& prev_hash)
133 return FinalizeBlock(Block(prev_hash));
137std::shared_ptr<const CBlock> MinerTestingSetup::BadBlock(
const uint256& prev_hash)
139 auto pblock = Block(prev_hash);
146 pblock->vtx.push_back(tx);
148 auto ret = FinalizeBlock(pblock);
153void MinerTestingSetup::BuildChain(
const uint256& root,
int height,
const unsigned int invalid_rate,
const unsigned int branch_rate,
const unsigned int max_size, std::vector<std::shared_ptr<const CBlock>>&
blocks)
155 if (height <= 0 ||
blocks.size() >= max_size)
return;
160 const std::shared_ptr<const CBlock> pblock =
gen_invalid ? BadBlock(root) : GoodBlock(root);
167 blocks.push_back(GoodBlock(root));
175 std::vector<std::shared_ptr<const CBlock>>
blocks;
176 while (
blocks.size() < 50) {
192 auto sub = std::make_shared<TestSubscriber>(
initial_tip->GetBlockHash());
198 std::vector<std::thread>
threads;
200 for (
int i = 0; i < 10; i++) {
204 for (
int i = 0; i < 1000; i++) {
210 for (
const auto& block :
blocks) {
211 if (block->vtx.size() == 1) {
250 auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) ->
bool {
268 std::vector<CTransactionRef>
txs;
274 mtx.vout[0].nValue -= 1000;
290 std::vector<std::shared_ptr<const CBlock>>
reorg;
301 for (
const auto& tx :
txs) {
338 for (
const auto& b :
reorg) {
356 .coinbase_output_script =
pubKey,
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint256 GetBlockHash() const
const CBlock & GenesisBlock() const
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
An output of a transaction.
Implement this to subscribe to events generated in validation and mempool.
void resize(size_type new_size)
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
constexpr size_t MINIMUM_WITNESS_COMMITMENT
Minimum size of a witness commitment structure.
int GetWitnessCommitmentIndex(const CBlock &block)
Compute at which vout of the block's coinbase transaction the witness commitment occurs,...
constexpr int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
A mutable version of CTransaction.
Validation result for a transaction evaluated by MemPoolAccept (single or package).
const ResultType m_result_type
Result type.
Identical to TestingSetup, but chain set to regtest.
void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
Notifies listeners of a block being disconnected Provides the block that was disconnected.
TestSubscriber(uint256 tip)
void BlockConnected(const ChainstateRole &role, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex) override
Notifies listeners of a block being connected.
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
Notifies listeners when the block chain tip advances.
Information about chainstate that notifications are sent from.
std::unique_ptr< ValidationSignals > validation_signals
Issues calls about blocks and transactions.
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< BlockTemplateManager > block_template_manager
Must be destroyed before its dependencies (holds references to them).
std::unique_ptr< ChainstateManager > chainman
std::shared_ptr< const CBlock > BadBlock(const uint256 &prev_hash)
std::shared_ptr< CBlock > Block(const uint256 &prev_hash)
void BuildChain(const uint256 &root, int height, unsigned int invalid_rate, unsigned int branch_rate, unsigned int max_size, std::vector< std::shared_ptr< const CBlock > > &blocks)
std::shared_ptr< const CBlock > GoodBlock(const uint256 &prev_hash)
std::shared_ptr< CBlock > FinalizeBlock(std::shared_ptr< CBlock > pblock)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
COutPoint ProcessBlock(const NodeContext &node, const std::shared_ptr< CBlock > &block)
Returns the generated coin (or Null if the block was invalid).
bool BuildChain(const NodeContext &node, const CBlockIndex *pindex, const CScript &coinbase_script_pub_key, size_t length, std::vector< std::shared_ptr< CBlock > > &chain)
Build a chain of length coinbase-only blocks on top of pindex (which need not be the active tip,...
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
static const CScript P2WSH_OP_TRUE
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)