mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
add trie_tests_ordered
This commit is contained in:
parent
a4cdb78a5f
commit
0c980d85a5
23
trie.cpp
23
trie.cpp
@ -103,16 +103,31 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered)
|
||||
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())
|
||||
values.push_back(s.get_str());
|
||||
{
|
||||
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
|
||||
cwarn << "Bad type (expected string): " << s.type();
|
||||
}
|
||||
|
||||
assert(values.size() == 2);
|
||||
ss.push_back(make_pair(values[0], values[1]));
|
||||
@ -128,9 +143,13 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered)
|
||||
BOOST_REQUIRE(t.check(true));
|
||||
for (auto const& k: ss)
|
||||
{
|
||||
t.insert(k.first, k.second);
|
||||
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()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user