33 #include <boost/filesystem.hpp> 59 cnote <<
" " << i.first;
60 testname =
"(" + i.first +
") ";
62 BOOST_REQUIRE_MESSAGE(o.count(
"out") > 0, testname +
"out not set!");
63 BOOST_REQUIRE_MESSAGE(!o[
"out"].is_null(), testname +
"out is set to null!");
70 RLP payload(payloadToDecode);
71 ostringstream() << payload;
76 cnote <<
"Exception: " << diagnostic_information(_e);
79 catch (std::exception
const& _e)
81 cnote <<
"rlp exception: " << _e.what();
88 BOOST_REQUIRE_MESSAGE(o.count(
"in") > 0, testname +
"in not set!");
89 RlpType rlpType = RlpType::Test;
92 if (o[
"in"].
get_str() ==
"INVALID")
93 rlpType = RlpType::Invalid;
94 else if (o[
"in"].
get_str() ==
"VALID")
95 rlpType = RlpType::Valid;
98 if (rlpType == RlpType::Test)
102 string computedText =
toHex(s.
out());
104 string expectedText(o[
"out"].
get_str());
105 transform(expectedText.begin(), expectedText.end(), expectedText.begin(), ::tolower );
108 msg <<
"Encoding Failed: expected: " << expectedText << std::endl;
109 msg <<
" But Computed: " << computedText;
110 BOOST_CHECK_MESSAGE(expectedText == computedText, testname + msg.str());
118 bool was_exception =
false;
123 RLP payload(payloadToDecode);
126 ostringstream() << payload;
128 if (rlpType == RlpType::Test)
133 cnote <<
"Exception: " << diagnostic_information(_e);
134 was_exception =
true;
136 catch (exception
const& _e)
138 cnote <<
"rlp exception: " << _e.what();
139 was_exception =
true;
143 was_exception =
true;
147 if (rlpType == RlpType::Invalid && was_exception)
151 if (rlpType == RlpType::Invalid && !was_exception)
152 BOOST_ERROR(testname +
"Expected RLP Exception as rlp should be invalid!");
156 BOOST_ERROR(testname +
"Unexpected RLP Exception!");
175 if (s.size() && s[0] ==
'#')
186 const string& expectedText = v.
get_str();
187 if ( !expectedText.empty() && expectedText.front() ==
'#' )
190 string bigIntStr = expectedText.substr(1,expectedText.length()-1);
191 stringstream bintStream(bigIntStr);
209 const int expectedValue = v.
get_int();
223 for( i = 0; i < arr.size(); i++ )
231 BOOST_ERROR(
"Invalid Javascript object!");
244 cnote <<
"TEST " << _name <<
":";
247 BOOST_REQUIRE_MESSAGE(s.length() > 0,
"Contents of " + testPath +
"/" + _name +
".json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
254 BOOST_ERROR(
"Failed test with Exception: " << diagnostic_information(_e));
256 catch (std::exception
const& _e)
258 BOOST_ERROR(
"Failed test with Exception: " << _e.what());
271 RLP payload(payloadToDecode);
272 ostringstream() << payload;
274 payloadToDecode =
fromHex(
"с0");
275 RLP payload2(payloadToDecode);
276 ostringstream() << payload2;
280 BOOST_ERROR(
"(EmptyArrayList) Failed test with Exception: " << _e.
what());
282 catch (exception
const& _e)
284 BOOST_ERROR(
"(EmptyArrayList) Failed test with Exception: " << _e.
what());
301 testPath +=
"/RLPTests/RandomRLPTests";
303 vector<boost::filesystem::path> testFiles;
304 boost::filesystem::directory_iterator iterator(testPath);
305 for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
306 if (boost::filesystem::is_regular_file(iterator->path()) && iterator->path().extension() ==
".json")
307 testFiles.push_back(iterator->path());
309 for (
auto& path: testFiles)
313 cnote <<
"Testing ..." << path.filename();
316 BOOST_REQUIRE_MESSAGE(s.length() > 0,
"Content of " + path.string() +
" is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
324 BOOST_ERROR(path.filename().string() +
"Failed test with Exception: " << diagnostic_information(_e));
326 catch (std::exception
const& _e)
328 BOOST_ERROR(path.filename().string() +
"Failed test with Exception: " << _e.what());
const Object & get_obj() const
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void runRlpTest(string _name, string _path)
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
bool isNull() const
No value.
bool isInt() const
Integer value. Must not have a leading zero.
bool isList() const
List value.
void doRlpTests(json_spirit::mValue &v, bool _fillin)
RLPStream & append(unsigned _s)
Append given datum to the byte stream.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
bytes const & out() const
Read the byte stream.
const char * what() const noexceptoverride
boost::uint64_t get_uint64() const
std::hash for asio::adress
Test mode – output information needed for test verification and benchmarking.
bool isData() const
String value.
void buildRLP(js::mValue &_v, RLPStream &_rlp)
void checkRLPAgainstJson(js::mValue &v, RLP &u)
const Array & get_array() const
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
bool read_string(const String_type &s, Value_type &value)
Base class for all exceptions.
mConfig::Array_type mArray
std::vector< byte > bytes
std::string getTestPath()
RLPStream & appendList(size_t _items)
Appends a list.
const String_type & get_str() const
mConfig::Object_type mObject
#define BOOST_FIXTURE_TEST_SUITE(a, b)
PlatformStyle::TableColorType type
#define BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(EmptyArrayList)
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Class for writing to an RLP bytestream.
bytes contents(std::string const &_file)
Retrieve and returns the contents of the given file.
Class for interpreting Recursive Linear-Prefix Data.
std::string asString(bytes const &_b)
Converts byte array to a string containing the same (binary) data.
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)