Notify users about auto-senescence via -alertnotify

Closes #2829.
This commit is contained in:
Jack Grigg
2018-01-23 00:29:08 +00:00
parent 01c31ec57f
commit 7b4d0c7762
3 changed files with 55 additions and 6 deletions

View File

@@ -1,12 +1,15 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "chainparams.h"
#include "clientversion.h"
#include "deprecation.h"
#include "init.h"
#include "ui_interface.h"
#include "util.h"
#include "chainparams.h"
#include <boost/filesystem/operations.hpp>
#include <fstream>
using ::testing::StrictMock;
@@ -43,6 +46,18 @@ protected:
}
StrictMock<MockUIInterface> mock_;
static std::vector<std::string> read_lines(boost::filesystem::path filepath) {
std::vector<std::string> result;
std::ifstream f(filepath.string().c_str());
std::string line;
while (std::getline(f,line)) {
result.push_back(line);
}
return result;
}
};
TEST_F(DeprecationTest, NonDeprecatedNodeKeepsRunning) {
@@ -119,4 +134,32 @@ TEST_F(DeprecationTest, DeprecatedNodeIgnoredOnTestnet) {
EXPECT_FALSE(ShutdownRequested());
EnforceNodeDeprecation(DEPRECATION_HEIGHT+1);
EXPECT_FALSE(ShutdownRequested());
}
}
TEST_F(DeprecationTest, AlertNotify) {
boost::filesystem::path temp = GetTempPath() /
boost::filesystem::unique_path("alertnotify-%%%%.txt");
mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string();
EXPECT_CALL(mock_, ThreadSafeMessageBox(::testing::_, "", CClientUIInterface::MSG_WARNING));
EnforceNodeDeprecation(DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT, false, false);
std::vector<std::string> r = read_lines(temp);
EXPECT_EQ(r.size(), 1u);
// -alertnotify restricts the message to safe characters.
auto expectedMsg = strprintf(
"This version will be deprecated at block height %d, and will automatically shut down. You should upgrade to the latest version of Zcash. To disable deprecation for this version, set disabledeprecation%s.",
DEPRECATION_HEIGHT,
CLIENT_VERSION_STR);
// Windows built-in echo semantics are different than posixy shells. Quotes and
// whitespace are printed literally.
#ifndef WIN32
EXPECT_EQ(r[0], expectedMsg);
#else
EXPECT_EQ(r[0], strprintf("'%s' ", expectedMsg));
#endif
boost::filesystem::remove(temp);
}