diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9ce8bbaed..0731693bd 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -53,7 +53,7 @@ public: //pchMessageStart[1] = 0xe4; //pchMessageStart[2] = 0xaa; //pchMessageStart[3] = 0xf1; - vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"); + vAlertPubKey = ParseHex("04a887418f021a52e33c345367ba4265890f4e295426894f4e1aece407f6441b14a036efa702d6abeb2c61883e11dd00ddc193f669c23a896981c632a73f1314ae"); nDefaultPort = 8333; nMinerThreads = 2; nPruneAfterHeight = 100000; diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp index 7239c76d3..a0d106402 100644 --- a/src/test/alert_tests.cpp +++ b/src/test/alert_tests.cpp @@ -17,6 +17,7 @@ #include "streams.h" #include "util.h" #include "utilstrencodings.h" +#include "key.h" #include "test/test_bitcoin.h" @@ -26,12 +27,79 @@ #include #include -#if 0 -// +bool SignAlert(CAlert &alert) +{ + CKey key; + std::vector vchkey = ParseHex("hex output of HexStr(CKey.GetPrivKey)"); + CPrivKey privKey(vchkey.begin(), vchkey.end()); + key.SetPrivKey(privKey, false); + + CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); + sMsg << *(CUnsignedAlert*)&alert; + alert.vchMsg = std::vector(sMsg.begin(), sMsg.end()); + + if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig)) + { + LogPrintf("Sign Alert() : key.Sign failed\n"); + return false; + } + return true; +} + +bool SignAndSave(CAlert &alert, CDataStream &buffer) +{ + if (!SignAlert(alert)) + { + LogPrintf("SignAndSave() : could not sign alert\n"); + return false; + } + buffer << alert; + return true; +} + +template +std::string HexStrArray(const T itbegin, const T itend) +{ + std::string rv; + static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + rv.reserve((itend-itbegin)*3); + int i = 0; + for(T it = itbegin; it < itend; ++it) + { + unsigned char val = (unsigned char)(*it); + if(it != itbegin) + { + if (i % 8 == 0) + rv.push_back('\n'); + else + rv.push_back(' '); + } + rv.push_back('0'); + rv.push_back('x'); + rv.push_back(hexmap[val>>4]); + rv.push_back(hexmap[val&15]); + rv.push_back(','); + i++; + } + + return rv; +} + +template +inline std::string HexStrArray(const T& vch) +{ + return HexStrArray(vch.begin(), vch.end()); +} + + // alertTests contains 7 alerts, generated with this code: // (SignAndSave code not shown, alert signing key is secret) // +void GenerateAlertTests() { + CDataStream sBuffer(SER_DISK, CLIENT_VERSION); + CAlert alert; alert.nRelayUntil = 60; alert.nExpiration = 24 * 60 * 60; @@ -43,45 +111,54 @@ alert.strComment = "Alert comment"; alert.strStatusBar = "Alert 1"; - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); alert.setSubVer.insert(std::string("/Satoshi:0.1.0/")); alert.strStatusBar = "Alert 1 for Satoshi 0.1.0"; - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); alert.setSubVer.insert(std::string("/Satoshi:0.2.0/")); alert.strStatusBar = "Alert 1 for Satoshi 0.1.0, 0.2.0"; - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); alert.setSubVer.clear(); ++alert.nID; alert.nCancel = 1; alert.nPriority = 100; alert.strStatusBar = "Alert 2, cancels 1"; - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); alert.nExpiration += 60; ++alert.nID; - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); ++alert.nID; alert.nMinVer = 11; alert.nMaxVer = 22; - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); ++alert.nID; alert.strStatusBar = "Alert 2 for Satoshi 0.1.0"; alert.setSubVer.insert(std::string("/Satoshi:0.1.0/")); - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); ++alert.nID; alert.nMinVer = 0; alert.nMaxVer = 999999; alert.strStatusBar = "Evil Alert'; /bin/ls; echo '"; alert.setSubVer.clear(); - SignAndSave(alert, "test/alertTests"); + SignAndSave(alert, sBuffer); + + std::vector vch = std::vector(sBuffer.begin(), sBuffer.end()); + + std::ofstream f; + f.open("alertTest.raw"); + for (std::vector::iterator itvch = vch.begin(); itvch != vch.end(); ++itvch) + { + f << *itvch; + } + f.close(); } -#endif struct ReadAlerts : public TestingSetup { diff --git a/src/test/data/alertTests.raw b/src/test/data/alertTests.raw index 01f50680b..1fa7acfbb 100644 Binary files a/src/test/data/alertTests.raw and b/src/test/data/alertTests.raw differ