aboutsummaryrefslogtreecommitdiffstats
path: root/rlp.cpp
diff options
context:
space:
mode:
authorCarl Allendorph <callendorph@gmail.com>2014-04-20 00:30:44 +0800
committerCarl Allendorph <callendorph@gmail.com>2014-04-20 00:30:44 +0800
commit84fd6bd28ff4b4f0c19f8d7c75b384f0e5728aea (patch)
tree79a47dc2e503e2b009534eb8dcee6c5e58f1def9 /rlp.cpp
parent3b3ef766291d50033eb7aa03b10c9e646e0dc3aa (diff)
downloaddexon-solidity-84fd6bd28ff4b4f0c19f8d7c75b384f0e5728aea.tar.gz
dexon-solidity-84fd6bd28ff4b4f0c19f8d7c75b384f0e5728aea.tar.zst
dexon-solidity-84fd6bd28ff4b4f0c19f8d7c75b384f0e5728aea.zip
converted RLP test to a separate boost test case.
Diffstat (limited to 'rlp.cpp')
-rw-r--r--rlp.cpp87
1 files changed, 40 insertions, 47 deletions
diff --git a/rlp.cpp b/rlp.cpp
index f6c24442..e13965da 100644
--- a/rlp.cpp
+++ b/rlp.cpp
@@ -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()) );
+ }
+
}
+
+
+
+