diff options
author | CJentzsch <jentzsch.software@gmail.com> | 2014-12-13 04:09:23 +0800 |
---|---|---|
committer | CJentzsch <jentzsch.software@gmail.com> | 2014-12-13 04:09:23 +0800 |
commit | 3a9837f7f25af435f77762be1d24690132ffe8d6 (patch) | |
tree | aa10c1287d1243dfd7789930378df6b35b3f3a97 /trie.cpp | |
parent | 6c819747bc6502325006f0a8780443e43ffece61 (diff) | |
download | dexon-solidity-3a9837f7f25af435f77762be1d24690132ffe8d6.tar.gz dexon-solidity-3a9837f7f25af435f77762be1d24690132ffe8d6.tar.zst dexon-solidity-3a9837f7f25af435f77762be1d24690132ffe8d6.zip |
include original trie test
Diffstat (limited to 'trie.cpp')
-rw-r--r-- | trie.cpp | 46 |
1 files changed, 45 insertions, 1 deletions
@@ -50,7 +50,7 @@ static unsigned fac(unsigned _i) BOOST_AUTO_TEST_SUITE(TrieTests) -BOOST_AUTO_TEST_CASE(trie_tests) +BOOST_AUTO_TEST_CASE(trie_test_anyorder) { string testPath = test::getTestPath(); @@ -93,6 +93,50 @@ BOOST_AUTO_TEST_CASE(trie_tests) } } +BOOST_AUTO_TEST_CASE(trie_tests_ordered) +{ + string testPath = test::getTestPath(); + + testPath += "/TrieTests"; + + cnote << "Testing Trie..."; + js::mValue v; + string s = asString(contents(testPath + "/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); + for (auto& i: v.get_obj()) + { + cnote << i.first; + js::mObject& o = i.second.get_obj(); + vector<pair<string, string>> ss; + for (auto& i: o["in"].get_array()) + { + vector<string> values; + for (auto& s: i.get_array()) + values.push_back(s.get_str()); + + assert(values.size() == 2); + ss.push_back(make_pair(values[0], values[1])); + if (!ss.back().first.find("0x")) + ss.back().first = asString(fromHex(ss.back().first.substr(2))); + if (!ss.back().second.find("0x")) + ss.back().second = asString(fromHex(ss.back().second.substr(2))); + } + + MemoryDB m; + GenericTrieDB<MemoryDB> t(&m); + t.init(); + BOOST_REQUIRE(t.check(true)); + for (auto const& k: ss) + { + t.insert(k.first, k.second); + BOOST_REQUIRE(t.check(true)); + } + BOOST_REQUIRE(!o["root"].is_null()); + BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray())); + } +} + inline h256 stringMapHash256(StringMap const& _s) { return hash256(_s); |