mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Broke trie tests out as separate boost auto test case.
This commit is contained in:
parent
cd132eae5e
commit
b8ce26d9f9
1
main.cpp
1
main.cpp
@ -45,7 +45,6 @@ BOOST_AUTO_TEST_CASE(basic_tests)
|
|||||||
std::cout << sha3(s.out()) << std::endl;*/
|
std::cout << sha3(s.out()) << std::endl;*/
|
||||||
|
|
||||||
int r = 0;
|
int r = 0;
|
||||||
r += trieTest();
|
|
||||||
r += vmTest();
|
r += vmTest();
|
||||||
r += cryptoTest(); // TODO: Put in tests repo.
|
r += cryptoTest(); // TODO: Put in tests repo.
|
||||||
// r += daggerTest();
|
// r += daggerTest();
|
||||||
|
44
trie.cpp
44
trie.cpp
@ -26,6 +26,8 @@
|
|||||||
#include <TrieDB.h>
|
#include <TrieDB.h>
|
||||||
#include "TrieHash.h"
|
#include "TrieHash.h"
|
||||||
#include "MemTrie.h"
|
#include "MemTrie.h"
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace eth;
|
using namespace eth;
|
||||||
|
|
||||||
@ -33,18 +35,25 @@ namespace js = json_spirit;
|
|||||||
|
|
||||||
namespace eth
|
namespace eth
|
||||||
{
|
{
|
||||||
|
namespace test
|
||||||
unsigned fac(unsigned _i) { return _i > 2 ? _i * fac(_i - 1) : _i; }
|
|
||||||
|
|
||||||
template <> class UnitTest<4>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int operator()()
|
|
||||||
{
|
{
|
||||||
|
static unsigned fac(unsigned _i)
|
||||||
|
{
|
||||||
|
return _i > 2 ? _i * fac(_i - 1) : _i;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(trie_tests)
|
||||||
|
{
|
||||||
|
cnote << "Testing Trie...";
|
||||||
|
|
||||||
js::mValue v;
|
js::mValue v;
|
||||||
string s = asString(contents("../../tests/trietest.json"));
|
string s = asString(contents("../../tests/trietest.json"));
|
||||||
|
BOOST_REQUIRE_MESSAGE( s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
js::read_string(s, v);
|
js::read_string(s, v);
|
||||||
bool passed = true;
|
|
||||||
for (auto& i: v.get_obj())
|
for (auto& i: v.get_obj())
|
||||||
{
|
{
|
||||||
js::mObject& o = i.second.get_obj();
|
js::mObject& o = i.second.get_obj();
|
||||||
@ -52,7 +61,7 @@ public:
|
|||||||
vector<pair<string, string>> ss;
|
vector<pair<string, string>> ss;
|
||||||
for (auto& i: o["in"].get_obj())
|
for (auto& i: o["in"].get_obj())
|
||||||
ss.push_back(make_pair(i.first, i.second.get_str()));
|
ss.push_back(make_pair(i.first, i.second.get_str()));
|
||||||
for (unsigned j = 0; j < fac((unsigned)ss.size()); ++j)
|
for (unsigned j = 0; j < eth::test::fac((unsigned)ss.size()); ++j)
|
||||||
{
|
{
|
||||||
next_permutation(ss.begin(), ss.end());
|
next_permutation(ss.begin(), ss.end());
|
||||||
BasicMap m;
|
BasicMap m;
|
||||||
@ -60,22 +69,13 @@ public:
|
|||||||
t.init();
|
t.init();
|
||||||
for (auto const& k: ss)
|
for (auto const& k: ss)
|
||||||
t.insert(k.first, k.second);
|
t.insert(k.first, k.second);
|
||||||
if (!o["root"].is_null() && o["root"].get_str() != toHex(t.root().asArray()))
|
BOOST_REQUIRE(!o["root"].is_null());
|
||||||
{
|
BOOST_CHECK(o["root"].get_str() == toHex(t.root().asArray()) );
|
||||||
cwarn << "Test failed on permutation " << j;
|
|
||||||
cwarn << "Test says:" << o["root"].get_str();
|
|
||||||
cwarn << "Impl says:" << toHex(t.root().asArray());
|
|
||||||
passed = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return passed ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline h256 stringMapHash256(StringMap const& _s)
|
inline h256 stringMapHash256(StringMap const& _s)
|
||||||
{
|
{
|
||||||
return hash256(_s);
|
return hash256(_s);
|
||||||
@ -83,8 +83,6 @@ inline h256 stringMapHash256(StringMap const& _s)
|
|||||||
|
|
||||||
int trieTest()
|
int trieTest()
|
||||||
{
|
{
|
||||||
cnote << "Testing Trie...";
|
|
||||||
return UnitTest<4>()();
|
|
||||||
|
|
||||||
// More tests...
|
// More tests...
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user