solidity/hexPrefix.cpp

62 lines
1.8 KiB
C++
Raw Normal View History

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
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.
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
*/
2014-12-14 13:20:59 +00:00
/** @file hexPrefix.cpp
2014-01-19 14:42:02 +00:00
* @author Gav Wood <i@gavwood.com>
* @date 2014
* Main test functions.
*/
2014-02-28 12:55:30 +00:00
#include <fstream>
#include "JsonSpiritHeaders.h"
#include <libdevcore/Log.h>
#include <libdevcore/CommonIO.h>
#include <libdevcrypto/TrieCommon.h>
#include <boost/test/unit_test.hpp>
#include "TestHelper.h"
2014-01-19 14:42:02 +00:00
using namespace std;
using namespace dev;
2014-02-28 12:55:30 +00:00
namespace js = json_spirit;
2014-01-19 14:42:02 +00:00
BOOST_AUTO_TEST_SUITE(BasicTests)
BOOST_AUTO_TEST_CASE(hexPrefix_test)
2014-01-19 14:42:02 +00:00
{
2014-10-27 16:04:18 +00:00
string testPath = test::getTestPath();
testPath += "/BasicTests";
2014-10-27 16:04:18 +00:00
cnote << "Testing Hex-Prefix-Encode...";
js::mValue v;
2014-10-27 16:04:18 +00:00
string s = asString(contents(testPath + "/hexencodetest.json"));
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content from 'hexencodetest.json' is empty. Have you cloned the 'tests' repo branch develop?");
js::read_string(s, v);
for (auto& i: v.get_obj())
2014-02-28 12:55:30 +00:00
{
js::mObject& o = i.second.get_obj();
cnote << i.first;
bytes v;
for (auto& i: o["seq"].get_array())
v.push_back((byte)i.get_int());
auto e = hexPrefixEncode(v, o["term"].get_bool());
BOOST_REQUIRE( ! o["out"].is_null() );
BOOST_CHECK( o["out"].get_str() == toHex(e) );
2014-02-28 12:55:30 +00:00
}
2014-01-19 14:42:02 +00:00
}
BOOST_AUTO_TEST_SUITE_END()