|
|
@ -18,62 +18,62 @@ BOOST_FIXTURE_TEST_SUITE(Alert_tests, TestingSetup) |
|
|
|
static bool falseFunc() { return false; } |
|
|
|
static bool falseFunc() { return false; } |
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(PartitionAlert) |
|
|
|
BOOST_AUTO_TEST_CASE(PartitionAlert) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Test PartitionCheck
|
|
|
|
// Test PartitionCheck
|
|
|
|
CCriticalSection csDummy; |
|
|
|
CCriticalSection csDummy; |
|
|
|
CBlockIndex indexDummy[100]; |
|
|
|
CBlockIndex indexDummy[100]; |
|
|
|
CChainParams& params = Params(CBaseChainParams::MAIN); |
|
|
|
CChainParams& params = Params(CBaseChainParams::MAIN); |
|
|
|
int64_t nPowTargetSpacing = params.GetConsensus().nPowTargetSpacing; |
|
|
|
int64_t nPowTargetSpacing = params.GetConsensus().nPowTargetSpacing; |
|
|
|
|
|
|
|
|
|
|
|
// Generate fake blockchain timestamps relative to
|
|
|
|
// Generate fake blockchain timestamps relative to
|
|
|
|
// an arbitrary time:
|
|
|
|
// an arbitrary time:
|
|
|
|
int64_t now = 1427379054; |
|
|
|
int64_t now = 1427379054; |
|
|
|
SetMockTime(now); |
|
|
|
SetMockTime(now); |
|
|
|
for (int i = 0; i < 100; i++) |
|
|
|
for (int i = 0; i < 100; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
indexDummy[i].phashBlock = NULL; |
|
|
|
indexDummy[i].phashBlock = NULL; |
|
|
|
if (i == 0) indexDummy[i].pprev = NULL; |
|
|
|
if (i == 0) indexDummy[i].pprev = NULL; |
|
|
|
else indexDummy[i].pprev = &indexDummy[i-1]; |
|
|
|
else indexDummy[i].pprev = &indexDummy[i-1]; |
|
|
|
indexDummy[i].nHeight = i; |
|
|
|
indexDummy[i].nHeight = i; |
|
|
|
indexDummy[i].nTime = now - (100-i)*nPowTargetSpacing; |
|
|
|
indexDummy[i].nTime = now - (100-i)*nPowTargetSpacing; |
|
|
|
// Other members don't matter, the partition check code doesn't
|
|
|
|
// Other members don't matter, the partition check code doesn't
|
|
|
|
// use them
|
|
|
|
// use them
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
strMiscWarning = ""; |
|
|
|
strMiscWarning = ""; |
|
|
|
|
|
|
|
|
|
|
|
// Test 1: chain with blocks every nPowTargetSpacing seconds,
|
|
|
|
// Test 1: chain with blocks every nPowTargetSpacing seconds,
|
|
|
|
// as normal, no worries:
|
|
|
|
// as normal, no worries:
|
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
BOOST_CHECK_MESSAGE(strMiscWarning.empty(), strMiscWarning); |
|
|
|
BOOST_CHECK_MESSAGE(strMiscWarning.empty(), strMiscWarning); |
|
|
|
|
|
|
|
|
|
|
|
// Test 2: go 3.5 hours without a block, expect a warning:
|
|
|
|
// Test 2: go 3.5 hours without a block, expect a warning:
|
|
|
|
now += 3*60*60+30*60; |
|
|
|
now += 3*60*60+30*60; |
|
|
|
SetMockTime(now); |
|
|
|
SetMockTime(now); |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
BOOST_CHECK(!strMiscWarning.empty()); |
|
|
|
BOOST_CHECK(!strMiscWarning.empty()); |
|
|
|
BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); |
|
|
|
BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); |
|
|
|
strMiscWarning = ""; |
|
|
|
strMiscWarning = ""; |
|
|
|
|
|
|
|
|
|
|
|
// Test 3: test the "partition alerts only go off once per day"
|
|
|
|
// Test 3: test the "partition alerts only go off once per day"
|
|
|
|
// code:
|
|
|
|
// code:
|
|
|
|
now += 60*10; |
|
|
|
now += 60*10; |
|
|
|
SetMockTime(now); |
|
|
|
SetMockTime(now); |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
BOOST_CHECK(strMiscWarning.empty()); |
|
|
|
BOOST_CHECK(strMiscWarning.empty()); |
|
|
|
|
|
|
|
|
|
|
|
// Test 4: get 2.5 times as many blocks as expected:
|
|
|
|
// Test 4: get 2.5 times as many blocks as expected:
|
|
|
|
now += 60*60*24; // Pretend it is a day later
|
|
|
|
now += 60*60*24; // Pretend it is a day later
|
|
|
|
SetMockTime(now); |
|
|
|
SetMockTime(now); |
|
|
|
int64_t quickSpacing = nPowTargetSpacing*2/5; |
|
|
|
int64_t quickSpacing = nPowTargetSpacing*2/5; |
|
|
|
for (int i = 0; i < 100; i++) // Tweak chain timestamps:
|
|
|
|
for (int i = 0; i < 100; i++) // Tweak chain timestamps:
|
|
|
|
indexDummy[i].nTime = now - (100-i)*quickSpacing; |
|
|
|
indexDummy[i].nTime = now - (100-i)*quickSpacing; |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
PartitionCheck(falseFunc, csDummy, &indexDummy[99], nPowTargetSpacing); |
|
|
|
BOOST_CHECK(!strMiscWarning.empty()); |
|
|
|
BOOST_CHECK(!strMiscWarning.empty()); |
|
|
|
BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); |
|
|
|
BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); |
|
|
|
strMiscWarning = ""; |
|
|
|
strMiscWarning = ""; |
|
|
|
|
|
|
|
|
|
|
|
SetMockTime(0); |
|
|
|
SetMockTime(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END() |
|
|
|
BOOST_AUTO_TEST_SUITE_END() |