Fix doubled alerts in alert tests causing them to fail

This commit is contained in:
langerhans 2014-04-24 21:59:40 +02:00
parent 98d551ee55
commit bcce1e6b42
2 changed files with 82 additions and 79 deletions

View file

@ -28,103 +28,106 @@ how to create this data:
*/
#ifdef CREATE_ALERTS
void SignAndSave(CAlert alert, const std::string filename) {
//serialze alert message
CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
sMsg << (CUnsignedAlert)alert;
alert.vchMsg.reserve(sMsg.size());
for(size_t i=0; i<sMsg.size(); i++) {
alert.vchMsg.push_back(sMsg[i]);
struct CreateAlerts
{
void SignAndSave(CAlert alert, const std::string filename) {
//serialze alert message
CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION);
sMsg << (CUnsignedAlert)alert;
alert.vchMsg.reserve(sMsg.size());
for(size_t i=0; i<sMsg.size(); i++) {
alert.vchMsg.push_back(sMsg[i]);
}
//a dummy secret key with the public key
//0469204F0E1800E16C1F85176BDC27A245F09987DB71A1EF5C4BD48A42F9AFD1D74F21469488DB552B594AC29CE667AD60DAAD0FFBCE03FB0C2AC49FFB07B36DC5
//set to match the mainnet vAlertPubKey from chainparams.cpp
const std::vector<unsigned char> secretKey = ParseHex("1A4976EE6174D80B8B3FF5E9B9C6E638CABFA9A5975557FEA967BC089A5584EE");
CKey secret;
secret.Set(secretKey.begin(), secretKey.end(), false);
assert(secret.IsValid());
//sign alert
secret.Sign(alert.GetHash(), alert.vchSig);
assert(alert.CheckSignature());
//serialize alert
CDataStream ss(SER_DISK, CLIENT_VERSION);
ss << alert;
//write alert
std::ofstream fs;
fs.open(filename.c_str(), std::ios::out | std::ios::app | std::ios::binary);
fs.write((char*)&ss[0], ss.size());
fs.close();
}
//a dummy secret key with the public key
//0469204F0E1800E16C1F85176BDC27A245F09987DB71A1EF5C4BD48A42F9AFD1D74F21469488DB552B594AC29CE667AD60DAAD0FFBCE03FB0C2AC49FFB07B36DC5
//set to match the mainnet vAlertPubKey from chainparams.cpp
const std::vector<unsigned char> secretKey = ParseHex("1A4976EE6174D80B8B3FF5E9B9C6E638CABFA9A5975557FEA967BC089A5584EE");
CKey secret;
secret.Set(secretKey.begin(), secretKey.end(), false);
assert(secret.IsValid());
//sign alert
secret.Sign(alert.GetHash(), alert.vchSig);
assert(alert.CheckSignature());
//serialize alert
CDataStream ss(SER_DISK, CLIENT_VERSION);
ss << alert;
//write alert
std::ofstream fs;
fs.open(filename.c_str(), std::ios::out | std::ios::app | std::ios::binary);
fs.write((char*)&ss[0], ss.size());
fs.close();
}
//
// alertTests contains 7 alerts, generated with this code:
//
CreateAlerts()
{
std::string filename("src/test/alertTests.raw");
//
// alertTests contains 7 alerts, generated with this code:
//
void CreateAlerts()
{
std::string filename("src/test/alertTests.raw");
CAlert alert;
alert.nRelayUntil = 60;
alert.nExpiration = 24 * 60 * 60;
alert.nID = 1;
alert.nCancel = 0; // cancels previous messages up to this ID number
alert.nMinVer = 0; // These versions are protocol versions
alert.nMaxVer = 999001;
alert.nPriority = 1;
alert.strComment = "Alert comment";
alert.strStatusBar = "Alert 1";
CAlert alert;
alert.nRelayUntil = 60;
alert.nExpiration = 24 * 60 * 60;
alert.nID = 1;
alert.nCancel = 0; // cancels previous messages up to this ID number
alert.nMinVer = 0; // These versions are protocol versions
alert.nMaxVer = 999001;
alert.nPriority = 1;
alert.strComment = "Alert comment";
alert.strStatusBar = "Alert 1";
SignAndSave(alert, filename);
SignAndSave(alert, filename);
alert.setSubVer.insert(std::string("/Satoshi:0.1.0/"));
alert.strStatusBar = "Alert 1 for Satoshi 0.1.0";
SignAndSave(alert, filename);
alert.setSubVer.insert(std::string("/Satoshi:0.1.0/"));
alert.strStatusBar = "Alert 1 for Satoshi 0.1.0";
SignAndSave(alert, filename);
alert.setSubVer.insert(std::string("/Satoshi:0.2.0/"));
alert.strStatusBar = "Alert 1 for Satoshi 0.1.0, 0.2.0";
SignAndSave(alert, filename);
alert.setSubVer.insert(std::string("/Satoshi:0.2.0/"));
alert.strStatusBar = "Alert 1 for Satoshi 0.1.0, 0.2.0";
SignAndSave(alert, filename);
alert.setSubVer.clear();
++alert.nID;
alert.nCancel = 1;
alert.nPriority = 100;
alert.strStatusBar = "Alert 2, cancels 1";
SignAndSave(alert, filename);
alert.setSubVer.clear();
++alert.nID;
alert.nCancel = 1;
alert.nPriority = 100;
alert.strStatusBar = "Alert 2, cancels 1";
SignAndSave(alert, filename);
alert.nExpiration += 60;
++alert.nID;
SignAndSave(alert, filename);
alert.nExpiration += 60;
++alert.nID;
SignAndSave(alert, filename);
++alert.nID;
alert.nMinVer = 11;
alert.nMaxVer = 22;
SignAndSave(alert, filename);
++alert.nID;
alert.nMinVer = 11;
alert.nMaxVer = 22;
SignAndSave(alert, filename);
++alert.nID;
alert.strStatusBar = "Alert 2 for Satoshi 0.1.0";
alert.setSubVer.insert(std::string("/Satoshi:0.1.0/"));
SignAndSave(alert, filename);
++alert.nID;
alert.strStatusBar = "Alert 2 for Satoshi 0.1.0";
alert.setSubVer.insert(std::string("/Satoshi:0.1.0/"));
SignAndSave(alert, filename);
++alert.nID;
alert.nMinVer = 0;
alert.nMaxVer = 999999;
alert.strStatusBar = "Evil Alert'; /bin/ls; echo '";
alert.setSubVer.clear();
SignAndSave(alert, filename);
}
~CreateAlerts() { }
};
++alert.nID;
alert.nMinVer = 0;
alert.nMaxVer = 999999;
alert.strStatusBar = "Evil Alert'; /bin/ls; echo '";
alert.setSubVer.clear();
SignAndSave(alert, filename);
}
BOOST_GLOBAL_FIXTURE(CreateAlerts)
#endif
struct ReadAlerts
{
ReadAlerts()
{
#ifdef CREATE_ALERTS
CreateAlerts();
#endif
std::vector<unsigned char> vch(alert_tests::alertTests, alert_tests::alertTests + sizeof(alert_tests::alertTests));
CDataStream stream(vch, SER_DISK, CLIENT_VERSION);
try {

Binary file not shown.