Changeset View
Changeset View
Standalone View
Standalone View
src/test/skiplist_tests.cpp
Show All 34 Lines | BOOST_AUTO_TEST_CASE(skiplist_test) { | ||||
for (int i = 0; i < 1000; i++) { | for (int i = 0; i < 1000; i++) { | ||||
int from = InsecureRandRange(SKIPLIST_LENGTH - 1); | int from = InsecureRandRange(SKIPLIST_LENGTH - 1); | ||||
int to = InsecureRandRange(from + 1); | int to = InsecureRandRange(from + 1); | ||||
BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == | BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == | ||||
&vIndex[from]); | &vIndex[from]); | ||||
BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]); | BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]); | ||||
BOOST_CHECK(vIndex[from].GetAncestor(0) == &vIndex[0]); | BOOST_CHECK(vIndex[from].GetAncestor(0) == vIndex.data()); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(getlocator_test) { | BOOST_AUTO_TEST_CASE(getlocator_test) { | ||||
// Build a main chain 100000 blocks long. | // Build a main chain 100000 blocks long. | ||||
std::vector<uint256> vHashMain(100000); | std::vector<uint256> vHashMain(100000); | ||||
std::vector<CBlockIndex> vBlocksMain(100000); | std::vector<CBlockIndex> vBlocksMain(100000); | ||||
for (unsigned int i = 0; i < vBlocksMain.size(); i++) { | for (unsigned int i = 0; i < vBlocksMain.size(); i++) { | ||||
Show All 14 Lines | BOOST_AUTO_TEST_CASE(getlocator_test) { | ||||
// Build a branch that splits off at block 49999, 50000 blocks long. | // Build a branch that splits off at block 49999, 50000 blocks long. | ||||
std::vector<uint256> vHashSide(50000); | std::vector<uint256> vHashSide(50000); | ||||
std::vector<CBlockIndex> vBlocksSide(50000); | std::vector<CBlockIndex> vBlocksSide(50000); | ||||
for (unsigned int i = 0; i < vBlocksSide.size(); i++) { | for (unsigned int i = 0; i < vBlocksSide.size(); i++) { | ||||
// Add 1<<128 to the hashes, so GetLow64() still returns the height. | // Add 1<<128 to the hashes, so GetLow64() still returns the height. | ||||
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); | vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); | ||||
vBlocksSide[i].nHeight = i + 50000; | vBlocksSide[i].nHeight = i + 50000; | ||||
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999]; | vBlocksSide[i].pprev = | ||||
i ? &vBlocksSide[i - 1] : (vBlocksMain.data() + 49999); | |||||
vBlocksSide[i].phashBlock = &vHashSide[i]; | vBlocksSide[i].phashBlock = &vHashSide[i]; | ||||
vBlocksSide[i].BuildSkip(); | vBlocksSide[i].BuildSkip(); | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
(int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), | (int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), | ||||
vBlocksSide[i].nHeight); | vBlocksSide[i].nHeight); | ||||
BOOST_CHECK(vBlocksSide[i].pprev == nullptr || | BOOST_CHECK(vBlocksSide[i].pprev == nullptr || | ||||
vBlocksSide[i].nHeight == | vBlocksSide[i].nHeight == | ||||
vBlocksSide[i].pprev->nHeight + 1); | vBlocksSide[i].pprev->nHeight + 1); | ||||
▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines |