aboutsummaryrefslogtreecommitdiff
path: root/src/test/alert_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/alert_tests.cpp')
-rw-r--r--src/test/alert_tests.cpp73
1 files changed, 7 insertions, 66 deletions
diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp
index 915326d4c..376567efb 100644
--- a/src/test/alert_tests.cpp
+++ b/src/test/alert_tests.cpp
@@ -1,23 +1,19 @@
-// Copyright (c) 2013 The Bitcoin Core developers
+// Copyright (c) 2013-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-//
// Unit tests for alert system
-//
#include "alert.h"
#include "chain.h"
#include "chainparams.h"
#include "clientversion.h"
#include "data/alertTests.raw.h"
-
-#include "main.h"
#include "serialize.h"
#include "streams.h"
-#include "util.h"
#include "utilstrencodings.h"
+#include "test/testutil.h"
#include "test/test_bitcoin.h"
#include <fstream>
@@ -26,6 +22,8 @@
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
+extern std::map<std::string, std::string> mapArgs;
+
#if 0
//
// alertTests contains 7 alerts, generated with this code:
@@ -87,7 +85,7 @@ struct ReadAlerts : public TestingSetup
{
ReadAlerts()
{
- std::vector<unsigned char> vch(alert_tests::alertTests, alert_tests::alertTests + sizeof(alert_tests::alertTests));
+ std::vector<unsigned char> vch(alertTests, alertTests + sizeof(alertTests));
CDataStream stream(vch, SER_DISK, CLIENT_VERSION);
try {
while (!stream.eof())
@@ -165,8 +163,8 @@ BOOST_AUTO_TEST_CASE(AlertNotify)
SetMockTime(11);
const std::vector<unsigned char>& alertKey = Params(CBaseChainParams::MAIN).AlertKey();
- boost::filesystem::path temp = GetTempPath() / "alertnotify.txt";
- boost::filesystem::remove(temp);
+ boost::filesystem::path temp = GetTempPath() /
+ boost::filesystem::unique_path("alertnotify-%%%%.txt");
mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string();
@@ -197,61 +195,4 @@ BOOST_AUTO_TEST_CASE(AlertNotify)
static bool falseFunc() { return false; }
-BOOST_AUTO_TEST_CASE(PartitionAlert)
-{
- // Test PartitionCheck
- CCriticalSection csDummy;
- CBlockIndex indexDummy[800];
- CChainParams& params = Params(CBaseChainParams::MAIN);
- int64_t nPowTargetSpacing = params.GetConsensus(0).nPowTargetSpacing;
-
- // Generate fake blockchain timestamps relative to
- // an arbitrary time:
- int64_t now = 1427379054;
- SetMockTime(now);
- for (int i = 0; i < 800; i++)
- {
- indexDummy[i].phashBlock = NULL;
- if (i == 0) indexDummy[i].pprev = NULL;
- else indexDummy[i].pprev = &indexDummy[i-1];
- indexDummy[i].nHeight = i;
- indexDummy[i].nTime = now - (800-i)*nPowTargetSpacing;
- // Other members don't matter, the partition check code doesn't
- // use them
- }
-
- // Test 1: chain with blocks every nPowTargetSpacing seconds,
- // as normal, no worries:
- PartitionCheck(falseFunc, csDummy, &indexDummy[799], nPowTargetSpacing);
- BOOST_CHECK(strMiscWarning.empty());
-
- // Test 2: go 3.5 hours without a block, expect a warning:
- now += 3*60*60+30*60;
- SetMockTime(now);
- PartitionCheck(falseFunc, csDummy, &indexDummy[799], nPowTargetSpacing);
- BOOST_CHECK(!strMiscWarning.empty());
- BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning);
- strMiscWarning = "";
-
- // Test 3: test the "partition alerts only go off once per day"
- // code:
- now += 60*10;
- SetMockTime(now);
- PartitionCheck(falseFunc, csDummy, &indexDummy[799], nPowTargetSpacing);
- BOOST_CHECK(strMiscWarning.empty());
-
- // Test 4: get 2.5 times as many blocks as expected:
- now += 60*60*24; // Pretend it is a day later
- SetMockTime(now);
- int64_t quickSpacing = nPowTargetSpacing*2/5;
- for (int i = 0; i < 800; i++) // Tweak chain timestamps:
- indexDummy[i].nTime = now - (800-i)*quickSpacing;
- PartitionCheck(falseFunc, csDummy, &indexDummy[799], nPowTargetSpacing);
- BOOST_CHECK(!strMiscWarning.empty());
- BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning);
- strMiscWarning = "";
-
- SetMockTime(0);
-}
-
BOOST_AUTO_TEST_SUITE_END()