Changeset View
Changeset View
Standalone View
Standalone View
src/test/interfaces_tests.cpp
Show All 11 Lines | |||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
using interfaces::FoundBlock; | using interfaces::FoundBlock; | ||||
BOOST_FIXTURE_TEST_SUITE(interfaces_tests, TestChain100Setup) | BOOST_FIXTURE_TEST_SUITE(interfaces_tests, TestChain100Setup) | ||||
BOOST_AUTO_TEST_CASE(findBlock) { | BOOST_AUTO_TEST_CASE(findBlock) { | ||||
auto chain = interfaces::MakeChain(m_node, Params()); | auto &chain = m_node.chain; | ||||
const CChain &active = Assert(m_node.chainman)->ActiveChain(); | const CChain &active = Assert(m_node.chainman)->ActiveChain(); | ||||
BlockHash hash; | BlockHash hash; | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
chain->findBlock(active[10]->GetBlockHash(), FoundBlock().hash(hash))); | chain->findBlock(active[10]->GetBlockHash(), FoundBlock().hash(hash))); | ||||
BOOST_CHECK_EQUAL(hash, active[10]->GetBlockHash()); | BOOST_CHECK_EQUAL(hash, active[10]->GetBlockHash()); | ||||
int height = -1; | int height = -1; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | BOOST_CHECK(chain->findBlock( | ||||
.nextBlock(FoundBlock().inActiveChain(next_active)))); | .nextBlock(FoundBlock().inActiveChain(next_active)))); | ||||
BOOST_CHECK(cur_active); | BOOST_CHECK(cur_active); | ||||
BOOST_CHECK(!next_active); | BOOST_CHECK(!next_active); | ||||
BOOST_CHECK(!chain->findBlock(BlockHash(), FoundBlock())); | BOOST_CHECK(!chain->findBlock(BlockHash(), FoundBlock())); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(findFirstBlockWithTimeAndHeight) { | BOOST_AUTO_TEST_CASE(findFirstBlockWithTimeAndHeight) { | ||||
auto chain = interfaces::MakeChain(m_node, Params()); | auto &chain = m_node.chain; | ||||
const CChain &active = Assert(m_node.chainman)->ActiveChain(); | const CChain &active = Assert(m_node.chainman)->ActiveChain(); | ||||
BlockHash hash; | BlockHash hash; | ||||
int height; | int height; | ||||
BOOST_CHECK(chain->findFirstBlockWithTimeAndHeight( | BOOST_CHECK(chain->findFirstBlockWithTimeAndHeight( | ||||
/* min_time= */ 0, /* min_height= */ 5, | /* min_time= */ 0, /* min_height= */ 5, | ||||
FoundBlock().hash(hash).height(height))); | FoundBlock().hash(hash).height(height))); | ||||
BOOST_CHECK_EQUAL(hash, active[5]->GetBlockHash()); | BOOST_CHECK_EQUAL(hash, active[5]->GetBlockHash()); | ||||
BOOST_CHECK_EQUAL(height, 5); | BOOST_CHECK_EQUAL(height, 5); | ||||
BOOST_CHECK(!chain->findFirstBlockWithTimeAndHeight( | BOOST_CHECK(!chain->findFirstBlockWithTimeAndHeight( | ||||
/* min_time= */ active.Tip()->GetBlockTimeMax() + 1, | /* min_time= */ active.Tip()->GetBlockTimeMax() + 1, | ||||
/* min_height= */ 0)); | /* min_height= */ 0)); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(findAncestorByHeight) { | BOOST_AUTO_TEST_CASE(findAncestorByHeight) { | ||||
auto chain = interfaces::MakeChain(m_node, Params()); | auto &chain = m_node.chain; | ||||
const CChain &active = Assert(m_node.chainman)->ActiveChain(); | const CChain &active = Assert(m_node.chainman)->ActiveChain(); | ||||
BlockHash hash; | BlockHash hash; | ||||
BOOST_CHECK(chain->findAncestorByHeight(active[20]->GetBlockHash(), 10, | BOOST_CHECK(chain->findAncestorByHeight(active[20]->GetBlockHash(), 10, | ||||
FoundBlock().hash(hash))); | FoundBlock().hash(hash))); | ||||
BOOST_CHECK_EQUAL(hash, active[10]->GetBlockHash()); | BOOST_CHECK_EQUAL(hash, active[10]->GetBlockHash()); | ||||
BOOST_CHECK(!chain->findAncestorByHeight(active[10]->GetBlockHash(), 20)); | BOOST_CHECK(!chain->findAncestorByHeight(active[10]->GetBlockHash(), 20)); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(findAncestorByHash) { | BOOST_AUTO_TEST_CASE(findAncestorByHash) { | ||||
auto chain = interfaces::MakeChain(m_node, Params()); | auto &chain = m_node.chain; | ||||
const CChain &active = Assert(m_node.chainman)->ActiveChain(); | const CChain &active = Assert(m_node.chainman)->ActiveChain(); | ||||
int height = -1; | int height = -1; | ||||
BOOST_CHECK(chain->findAncestorByHash(active[20]->GetBlockHash(), | BOOST_CHECK(chain->findAncestorByHash(active[20]->GetBlockHash(), | ||||
active[10]->GetBlockHash(), | active[10]->GetBlockHash(), | ||||
FoundBlock().height(height))); | FoundBlock().height(height))); | ||||
BOOST_CHECK_EQUAL(height, 10); | BOOST_CHECK_EQUAL(height, 10); | ||||
BOOST_CHECK(!chain->findAncestorByHash(active[10]->GetBlockHash(), | BOOST_CHECK(!chain->findAncestorByHash(active[10]->GetBlockHash(), | ||||
active[20]->GetBlockHash())); | active[20]->GetBlockHash())); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(findCommonAncestor) { | BOOST_AUTO_TEST_CASE(findCommonAncestor) { | ||||
auto chain = interfaces::MakeChain(m_node, Params()); | auto &chain = m_node.chain; | ||||
const CChain &active = Assert(m_node.chainman)->ActiveChain(); | const CChain &active = Assert(m_node.chainman)->ActiveChain(); | ||||
auto *orig_tip = active.Tip(); | auto *orig_tip = active.Tip(); | ||||
for (int i = 0; i < 10; ++i) { | for (int i = 0; i < 10; ++i) { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
ChainstateActive().InvalidateBlock(GetConfig(), state, active.Tip()); | ChainstateActive().InvalidateBlock(GetConfig(), state, active.Tip()); | ||||
} | } | ||||
BOOST_CHECK_EQUAL(active.Height(), orig_tip->nHeight - 10); | BOOST_CHECK_EQUAL(active.Height(), orig_tip->nHeight - 10); | ||||
coinbaseKey.MakeNewKey(true); | coinbaseKey.MakeNewKey(true); | ||||
Show All 20 Lines | BOOST_AUTO_TEST_CASE(findCommonAncestor) { | ||||
BOOST_CHECK(!chain->findCommonAncestor(BlockHash(), | BOOST_CHECK(!chain->findCommonAncestor(BlockHash(), | ||||
orig_tip->GetBlockHash(), {}, {}, | orig_tip->GetBlockHash(), {}, {}, | ||||
FoundBlock().hash(orig_hash))); | FoundBlock().hash(orig_hash))); | ||||
BOOST_CHECK_EQUAL(active_hash, active.Tip()->GetBlockHash()); | BOOST_CHECK_EQUAL(active_hash, active.Tip()->GetBlockHash()); | ||||
BOOST_CHECK_EQUAL(orig_hash, orig_tip->GetBlockHash()); | BOOST_CHECK_EQUAL(orig_hash, orig_tip->GetBlockHash()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(hasBlocks) { | BOOST_AUTO_TEST_CASE(hasBlocks) { | ||||
auto chain = interfaces::MakeChain(m_node, Params()); | auto &chain = m_node.chain; | ||||
const CChain &active = Assert(m_node.chainman)->ActiveChain(); | const CChain &active = Assert(m_node.chainman)->ActiveChain(); | ||||
// Test ranges | // Test ranges | ||||
BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 10, 90)); | BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 10, 90)); | ||||
BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 10, {})); | BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 10, {})); | ||||
BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 0, 90)); | BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 0, 90)); | ||||
BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 0, {})); | BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), 0, {})); | ||||
BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), -1000, 1000)); | BOOST_CHECK(chain->hasBlocks(active.Tip()->GetBlockHash(), -1000, 1000)); | ||||
Show All 26 Lines |