diff options
author | subtly <subtly@users.noreply.github.com> | 2015-01-06 01:07:06 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2015-01-06 01:07:06 +0800 |
commit | b4ca2a8b973435df1bc0d76052efbb63412838f3 (patch) | |
tree | 29c94744bc424c9005b0554271de5c83da2e8656 | |
parent | c0339860134a317b2be8354c38e54a6e645d7344 (diff) | |
parent | c92d79aea7de2bef42d835c7b1551d40273eedfc (diff) | |
download | dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.tar dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.tar.gz dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.tar.bz2 dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.tar.lz dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.tar.xz dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.tar.zst dexon-solidity-b4ca2a8b973435df1bc0d76052efbb63412838f3.zip |
Merge branch 'develop' into p2p-udp-nodetable
-rw-r--r-- | trie.cpp | 65 |
1 files changed, 64 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(); @@ -92,6 +92,69 @@ 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; + vector<string> keysToBeDeleted; + for (auto& i: o["in"].get_array()) + { + vector<string> values; + for (auto& s: i.get_array()) + { + if (s.type() == json_spirit::str_type) + values.push_back(s.get_str()); + else if (s.type() == json_spirit::null_type) + { + // mark entry for deletion + values.push_back(""); + if (!values[0].find("0x")) + values[0] = asString(fromHex(values[0].substr(2))); + keysToBeDeleted.push_back(values[0]); + } + else + BOOST_FAIL("Bad type (expected string)"); + } + + BOOST_REQUIRE(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) + { + if (find(keysToBeDeleted.begin(), keysToBeDeleted.end(), k.first) != keysToBeDeleted.end() && k.second.empty()) + t.remove(k.first); + else + 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); |