5#include <boost/test/unit_test.hpp>
23 return std::abs(a - b) < epsilon;
30 block_index->
nTime = 1269211443;
31 block_index->
nBits = nbits;
38 "Difficulty was " +
ToString(difficulty)
39 +
" but was expected to be " +
ToString(expected_difficulty));
89 for (
CBlockIndex* it{chain[height]}; it !=
nullptr && it->
nHeight > 0; it = it->pprev) {
90 it->nStatus &= ~BLOCK_HAVE_DATA;
94 BOOST_REQUIRE(prune_height.has_value());
117 BOOST_CHECK_EQUAL(block_index.m_chain_tx_count, std::numeric_limits<uint64_t>::max());
126 auto* orig_tip = active.Tip();
127 int height_to_invalidate = orig_tip->nHeight - 10;
128 auto* tip_to_invalidate = active[height_to_invalidate];
129 m_node.
chainman->ActiveChainstate().InvalidateBlock(state, tip_to_invalidate);
136 auto pindex = tip_to_invalidate->pprev;
140 pindex = pindex->pprev;
145 while (pindex && pindex != tip_to_invalidate) {
148 pindex = pindex->pprev;
152 m_node.
chainman->ActiveChainstate().InvalidateBlock(state, orig_tip);
double GetDifficulty(const CBlockIndex &blockindex)
Get the difficulty of the net wrt to the given block index.
std::optional< int > GetPruneHeight(const BlockManager &blockman, const CChain &chain)
Return height of highest block that has been pruned, or std::nullopt if no blocks have been pruned.
static void CheckGetPruneHeight(node::BlockManager &blockman, CChain &chain, int height) EXCLUSIVE_LOCKS_REQUIRED(
Prune chain from height down to genesis block and check that GetPruneHeight returns the correct value...
BOOST_FIXTURE_TEST_CASE(get_prune_height, TestChain100Setup)
static bool DoubleEquals(double a, double b, double epsilon)
static CBlockIndex * CreateBlockIndexWithNbits(uint32_t nbits)
static void TestDifficulty(uint32_t nbits, double expected_difficulty)
BOOST_AUTO_TEST_CASE(get_difficulty_for_very_low_target)
static void RejectDifficultyMismatch(double difficulty, double expected_difficulty)
@ BLOCK_VALID_TRANSACTIONS
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid,...
@ BLOCK_FAILED_CHILD
descends from failed block
@ BLOCK_FAILED_VALID
stage after last reached validness failed
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint64_t m_chain_tx_count
(memory only) Number of transactions in the chain up to and including this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
An in-memory indexed chain of blocks.
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
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()
std::string ToString(const T &t)
Locale-independent version of std::to_string.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define EXCLUSIVE_LOCKS_REQUIRED(...)