Changeset View
Changeset View
Standalone View
Standalone View
src/test/work_comparator_tests.cpp
Show All 10 Lines | |||||
BOOST_AUTO_TEST_CASE(work_comparator) { | BOOST_AUTO_TEST_CASE(work_comparator) { | ||||
CBlockIndex indexA, indexB; | CBlockIndex indexA, indexB; | ||||
// Differing chain work | // Differing chain work | ||||
indexA.nChainWork = 0; | indexA.nChainWork = 0; | ||||
indexB.nChainWork = 1; | indexB.nChainWork = 1; | ||||
for (int sequenceIdA = 1; sequenceIdA < 1024; sequenceIdA *= 2) { | for (int sequenceIdA = 1; sequenceIdA < 1024; sequenceIdA *= 2) { | ||||
for (int sequenceIdB = 1; sequenceIdB < 1024; sequenceIdB *= 2) { | for (int sequenceIdB = 1; sequenceIdB < 1024; sequenceIdB *= 2) { | ||||
for (int timeReceivedA = 1; timeReceivedA < 1024; | |||||
timeReceivedA *= 2) { | |||||
for (int timeReceivedB = 1; timeReceivedB < 1024; | |||||
timeReceivedB *= 2) { | |||||
// Differing sequenceId doesn't affect chain work | // Differing sequenceId doesn't affect chain work | ||||
indexA.nSequenceId = sequenceIdA; | indexA.nSequenceId = sequenceIdA; | ||||
indexB.nSequenceId = sequenceIdB; | indexB.nSequenceId = sequenceIdB; | ||||
// Differing received time doesn't affect chain work | |||||
indexA.nTimeReceived = timeReceivedA; | |||||
indexB.nTimeReceived = timeReceivedB; | |||||
BOOST_CHECK(CBlockIndexWorkComparator()(&indexA, &indexB)); | BOOST_CHECK(CBlockIndexWorkComparator()(&indexA, &indexB)); | ||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
// Same chain work, but differing received time | |||||
indexA = CBlockIndex(); | |||||
indexB = CBlockIndex(); | |||||
for (int sequenceIdA = 1; sequenceIdA < 1024; sequenceIdA *= 2) { | |||||
for (int sequenceIdB = 1; sequenceIdB < 1024; sequenceIdB *= 2) { | |||||
for (int timeReceivedA = 1; timeReceivedA < 1024; | |||||
timeReceivedA *= 2) { | |||||
for (int timeReceivedB = 1; timeReceivedB < 1024; | |||||
timeReceivedB *= 2) { | |||||
if (timeReceivedA == timeReceivedB) { | |||||
continue; | |||||
} | |||||
indexA.nTimeReceived = timeReceivedA; | |||||
indexB.nTimeReceived = timeReceivedB; | |||||
// Differing sequenceId doesn't affect chain work | |||||
indexA.nSequenceId = sequenceIdA; | |||||
indexB.nSequenceId = sequenceIdB; | |||||
if (timeReceivedA > timeReceivedB) { | |||||
BOOST_CHECK( | |||||
CBlockIndexWorkComparator()(&indexA, &indexB)); | |||||
} else { | |||||
BOOST_CHECK( | |||||
CBlockIndexWorkComparator()(&indexB, &indexA)); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// Same chain work, but differing sequenceId | // Same chain work and received time, but differing sequenceId | ||||
indexA = CBlockIndex(); | indexA = CBlockIndex(); | ||||
indexB = CBlockIndex(); | indexB = CBlockIndex(); | ||||
for (int sequenceIdA = 1; sequenceIdA < 1024; sequenceIdA *= 2) { | for (int sequenceIdA = 1; sequenceIdA < 1024; sequenceIdA *= 2) { | ||||
for (int sequenceIdB = 1; sequenceIdB < 1024; sequenceIdB *= 2) { | for (int sequenceIdB = 1; sequenceIdB < 1024; sequenceIdB *= 2) { | ||||
if (sequenceIdA == sequenceIdB) { | if (sequenceIdA == sequenceIdB) { | ||||
continue; | continue; | ||||
} | } | ||||
Show All 17 Lines |