neobytes/src/test/governance_validators_tests.cpp

64 lines
2.0 KiB
C++
Raw Normal View History

// Copyright (c) 2014-2017 The Dash Core developers
#include "governance-validators.h"
#include "utilstrencodings.h"
#include "data/proposals_valid.json.h"
#include "data/proposals_invalid.json.h"
#include "test/test_dash.h"
#include <iostream>
#include <fstream>
#include <string>
#include <boost/test/unit_test.hpp>
#include <univalue.h>
extern UniValue read_json(const std::string& jsondata);
BOOST_FIXTURE_TEST_SUITE(governance_validators_tests, BasicTestingSetup)
std::string CreateEncodedProposalObject(const UniValue& objJSON)
{
UniValue innerArray(UniValue::VARR);
innerArray.push_back(UniValue("proposal"));
innerArray.push_back(objJSON);
UniValue outerArray(UniValue::VARR);
outerArray.push_back(innerArray);
std::string strData = outerArray.write();
std::string strHex = HexStr(strData);
return strHex;
}
BOOST_AUTO_TEST_CASE(valid_proposals_test)
{
UniValue tests = read_json(std::string(json_tests::proposals_valid, json_tests::proposals_valid + sizeof(json_tests::proposals_valid)));
BOOST_CHECK_MESSAGE(tests.size(), "Empty `tests`");
for(size_t i = 0; i < tests.size(); ++i) {
const UniValue& objProposal = tests[i];
std::string strHexData = CreateEncodedProposalObject(objProposal);
CProposalValidator validator(strHexData);
BOOST_CHECK_MESSAGE(validator.Validate(), validator.GetErrorMessages());
}
}
BOOST_AUTO_TEST_CASE(invalid_proposals_test)
{
UniValue tests = read_json(std::string(json_tests::proposals_invalid, json_tests::proposals_invalid + sizeof(json_tests::proposals_invalid)));
BOOST_CHECK_MESSAGE(tests.size(), "Empty `tests`");
for(size_t i = 0; i < tests.size(); ++i) {
const UniValue& objProposal = tests[i];
std::string strHexData = CreateEncodedProposalObject(objProposal);
CProposalValidator validator(strHexData);
BOOST_CHECK_MESSAGE(!validator.Validate(), validator.GetErrorMessages());
}
}
BOOST_AUTO_TEST_SUITE_END()