diff options
-rw-r--r-- | main.cpp | 1 | ||||
-rw-r--r-- | rlp.cpp | 87 |
2 files changed, 40 insertions, 48 deletions
@@ -46,7 +46,6 @@ BOOST_AUTO_TEST_CASE(basic_tests) int r = 0; r += hexPrefixTest(); - r += rlpTest(); r += trieTest(); r += vmTest(); r += cryptoTest(); // TODO: Put in tests repo. @@ -24,66 +24,59 @@ #include "JsonSpiritHeaders.h" #include <Log.h> #include <RLP.h> +#include <boost/test/unit_test.hpp> + using namespace std; using namespace eth; namespace js = json_spirit; -namespace eth -{ - -template <> class UnitTest<2> +namespace eth { -public: - static void buildRLP(js::mValue& _v, RLPStream& _rlp) + namespace test { - if (_v.type() == js::array_type) + static void buildRLP(js::mValue& _v, RLPStream& _rlp) { - RLPStream s; - for (auto& i: _v.get_array()) - buildRLP(i, s); - _rlp.appendList(s.out()); - } - else if (_v.type() == js::int_type) - _rlp.append(_v.get_uint64()); - else if (_v.type() == js::str_type) - { - auto s = _v.get_str(); - if (s.size() && s[0] == '#') - _rlp.append(bigint(s.substr(1))); - else - _rlp.append(s); - } - } - - int operator()() - { - js::mValue v; - string s = asString(contents("../../tests/rlptest.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; - RLPStream s; - buildRLP(o["in"], s); - if (!o["out"].is_null() && o["out"].get_str() != toHex(s.out())) + if (_v.type() == js::array_type) { - cwarn << "Test failed."; - cwarn << "Test says:" << o["out"].get_str(); - cwarn << "Impl says:" << toHex(s.out()); - passed = false; + RLPStream s; + for (auto& i: _v.get_array()) + buildRLP(i, s); + _rlp.appendList(s.out()); + } + else if (_v.type() == js::int_type) + _rlp.append(_v.get_uint64()); + else if (_v.type() == js::str_type) + { + auto s = _v.get_str(); + if (s.size() && s[0] == '#') + _rlp.append(bigint(s.substr(1))); + else + _rlp.append(s); } } - return passed ? 0 : 1; } +} -}; - -} -int rlpTest() +BOOST_AUTO_TEST_CASE(rlp_test) { cnote << "Testing RLP..."; - return UnitTest<2>()(); + js::mValue v; + string s = asString(contents("../../tests/rlptest.json")); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'rlptest.json' is empty. Have you cloned the 'tests' repo branch develop?"); + js::read_string(s, v); + for (auto& i: v.get_obj()) + { + js::mObject& o = i.second.get_obj(); + cnote << i.first; + RLPStream s; + eth::test::buildRLP(o["in"], s); + BOOST_REQUIRE(!o["out"].is_null()); + BOOST_CHECK(o["out"].get_str() == toHex(s.out()) ); + } + } + + + + |