Browse Source

converted RLP test to a separate boost test case.

cl-refactor
Carl Allendorph 11 years ago
parent
commit
c7a1c2b0d2
  1. 1
      test/main.cpp
  2. 87
      test/rlp.cpp

1
test/main.cpp

@ -46,7 +46,6 @@ BOOST_AUTO_TEST_CASE(basic_tests)
int r = 0; int r = 0;
r += hexPrefixTest(); r += hexPrefixTest();
r += rlpTest();
r += trieTest(); r += trieTest();
r += vmTest(); r += vmTest();
r += cryptoTest(); // TODO: Put in tests repo. r += cryptoTest(); // TODO: Put in tests repo.

87
test/rlp.cpp

@ -24,66 +24,59 @@
#include "JsonSpiritHeaders.h" #include "JsonSpiritHeaders.h"
#include <Log.h> #include <Log.h>
#include <RLP.h> #include <RLP.h>
#include <boost/test/unit_test.hpp>
using namespace std; using namespace std;
using namespace eth; using namespace eth;
namespace js = json_spirit; namespace js = json_spirit;
namespace eth namespace eth
{
template <> class UnitTest<2>
{ {
public: namespace test
static void buildRLP(js::mValue& _v, RLPStream& _rlp)
{ {
if (_v.type() == js::array_type) static void buildRLP(js::mValue& _v, RLPStream& _rlp)
{ {
RLPStream s; if (_v.type() == js::array_type)
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()))
{ {
cwarn << "Test failed."; RLPStream s;
cwarn << "Test says:" << o["out"].get_str(); for (auto& i: _v.get_array())
cwarn << "Impl says:" << toHex(s.out()); buildRLP(i, s);
passed = false; _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..."; 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()) );
}
} }

Loading…
Cancel
Save