2014-01-19 14:42:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of cpp-ethereum.
|
|
|
|
|
|
|
|
cpp-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2014-02-06 18:53:46 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
2014-01-19 14:42:02 +00:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2014-02-16 10:20:55 +00:00
|
|
|
cpp-ethereum is distributed in the hope that it will be useful,
|
2014-01-19 14:42:02 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2014-02-16 10:41:15 +00:00
|
|
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-19 14:42:02 +00:00
|
|
|
*/
|
|
|
|
/** @file main.cpp
|
|
|
|
* @author Gav Wood <i@gavwood.com>
|
|
|
|
* @date 2014
|
|
|
|
* Main test functions.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 12:55:30 +00:00
|
|
|
#include <fstream>
|
2014-03-05 16:32:37 +00:00
|
|
|
#include "JsonSpiritHeaders.h"
|
2014-01-19 14:42:02 +00:00
|
|
|
#include "TrieCommon.h"
|
2014-03-04 17:46:26 +00:00
|
|
|
#include "Log.h"
|
2014-01-19 14:42:02 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace eth;
|
2014-02-28 12:55:30 +00:00
|
|
|
namespace js = json_spirit;
|
2014-01-19 14:42:02 +00:00
|
|
|
|
2014-02-28 12:55:30 +00:00
|
|
|
namespace eth
|
|
|
|
{
|
|
|
|
|
|
|
|
template <> class UnitTest<3>
|
2014-01-19 14:42:02 +00:00
|
|
|
{
|
2014-02-28 12:55:30 +00:00
|
|
|
public:
|
|
|
|
int operator()()
|
|
|
|
{
|
|
|
|
js::mValue v;
|
|
|
|
string s = asString(contents("../../tests/hexencodetest.json"));
|
|
|
|
js::read_string(s, v);
|
|
|
|
bool passed = true;
|
|
|
|
for (auto& i: v.get_obj())
|
|
|
|
{
|
|
|
|
js::mObject& o = i.second.get_obj();
|
|
|
|
cnote << i.first;
|
|
|
|
bytes v;
|
|
|
|
for (auto& i: o["seq"].get_array())
|
2014-03-01 16:54:35 +00:00
|
|
|
v.push_back((byte)i.get_int());
|
2014-02-28 12:55:30 +00:00
|
|
|
auto e = hexPrefixEncode(v, o["term"].get_bool());
|
2014-03-04 17:46:26 +00:00
|
|
|
if (!o["out"].is_null() && o["out"].get_str() != toHex(e))
|
2014-02-28 12:55:30 +00:00
|
|
|
{
|
|
|
|
cwarn << "Test failed.";
|
|
|
|
cwarn << "Test says:" << o["out"].get_str();
|
2014-03-04 17:46:26 +00:00
|
|
|
cwarn << "Impl says:" << toHex(e);
|
2014-02-28 12:55:30 +00:00
|
|
|
passed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return passed ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-01-19 14:42:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 12:55:30 +00:00
|
|
|
int hexPrefixTest()
|
|
|
|
{
|
|
|
|
cnote << "Testing Hex-Prefix-Encode...";
|
|
|
|
return UnitTest<3>()();
|
|
|
|
}
|