12#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) {
94 BOOST_REQUIRE(prune_height.has_value());
101 const auto& chain = m_node.chainman->ActiveChain();
102 const auto& blockman = m_node.chainman->m_blockman;
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);
135 auto pindex = tip_to_invalidate->pprev;
139 pindex = pindex->pprev;
144 while (pindex && pindex != tip_to_invalidate) {
146 pindex = pindex->pprev;
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.
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)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
static void CheckGetPruneHeight(const node::BlockManager &blockman, const CChain &chain, int height) EXCLUSIVE_LOCKS_REQUIRED(
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_HAVE_DATA
full block available in blk*.dat
@ 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
int nHeight
height of the entry in the chain. The genesis block has height 0
An in-memory indexed chain of blocks.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
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()
BOOST_AUTO_TEST_CASE(ipc_tests)
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.
#define WITH_LOCK(cs, code)
#define AssertLockHeld(cs)
#define EXCLUSIVE_LOCKS_REQUIRED(...)