mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Revert "Fix for unless/when."
This reverts commit b12d91e726ae5d1742e6d828c2cb5b694ffdf8a3.
This commit is contained in:
parent
a620c7f6d3
commit
3aa823b55e
54
main.cpp
54
main.cpp
@ -45,12 +45,11 @@ BOOST_AUTO_TEST_CASE(basic_tests)
|
|||||||
cdebug << "Stress-testing Trie...";
|
cdebug << "Stress-testing Trie...";
|
||||||
{
|
{
|
||||||
BasicMap m;
|
BasicMap m;
|
||||||
BasicMap dm;
|
EnforceRefs e(m, true);
|
||||||
EnforceRefs e(dm, true);
|
GenericTrieDB<BasicMap> d(&m);
|
||||||
GenericTrieDB<BasicMap> d(&dm);
|
|
||||||
d.init(); // initialise as empty tree.
|
d.init(); // initialise as empty tree.
|
||||||
MemTrie t;
|
MemTrie t;
|
||||||
BOOST_REQUIRE(d.check());
|
assert(d.check().empty());
|
||||||
for (int a = 0; a < 100; ++a)
|
for (int a = 0; a < 100; ++a)
|
||||||
{
|
{
|
||||||
StringMap m;
|
StringMap m;
|
||||||
@ -58,55 +57,22 @@ BOOST_AUTO_TEST_CASE(basic_tests)
|
|||||||
{
|
{
|
||||||
auto k = randomWord();
|
auto k = randomWord();
|
||||||
auto v = toString(i);
|
auto v = toString(i);
|
||||||
cdebug << k << v;
|
m.insert(make_pair(k, v));
|
||||||
m[k] = v;
|
|
||||||
t.insert(k, v);
|
t.insert(k, v);
|
||||||
d.insert(k, v);
|
d.insert(k, v);
|
||||||
BOOST_REQUIRE_EQUAL(hash256(m), t.hash256());
|
assert(hash256(m) == t.hash256());
|
||||||
BOOST_REQUIRE_EQUAL(hash256(m), d.root());
|
assert(hash256(m) == d.root());
|
||||||
BOOST_REQUIRE(d.check());
|
assert(d.check().empty());
|
||||||
}
|
}
|
||||||
while (!m.empty())
|
while (!m.empty())
|
||||||
{
|
{
|
||||||
auto k = m.begin()->first;
|
auto k = m.begin()->first;
|
||||||
auto v = m.begin()->second;
|
|
||||||
cdebug << k << m.size();
|
|
||||||
d.remove(k);
|
d.remove(k);
|
||||||
t.remove(k);
|
t.remove(k);
|
||||||
m.erase(k);
|
m.erase(k);
|
||||||
if (!d.check())
|
assert(hash256(m) == t.hash256());
|
||||||
{
|
assert(hash256(m) == d.root());
|
||||||
cwarn << m;
|
assert(d.check().empty());
|
||||||
for (auto i: d)
|
|
||||||
cwarn << i.first.toString() << i.second.toString();
|
|
||||||
|
|
||||||
BasicMap dm2;
|
|
||||||
EnforceRefs e2(dm2, true);
|
|
||||||
GenericTrieDB<BasicMap> d2(&dm2);
|
|
||||||
d2.init(); // initialise as empty tree.
|
|
||||||
for (auto i: d)
|
|
||||||
d2.insert(i.first, i.second);
|
|
||||||
|
|
||||||
cwarn << "Good:" << d2.root();
|
|
||||||
for (auto i: dm2.get())
|
|
||||||
cwarn << i.first.abridged() << ": " << RLP(i.second);
|
|
||||||
cwarn << "Broken:" << d.root(); // Leaves an extension -> extension (3c1... -> 742...)
|
|
||||||
for (auto i: dm.get())
|
|
||||||
cwarn << i.first.abridged() << ": " << RLP(i.second);
|
|
||||||
|
|
||||||
d2.insert(k, v);
|
|
||||||
cwarn << "Pres:" << d2.root();
|
|
||||||
for (auto i: dm2.get())
|
|
||||||
cwarn << i.first.abridged() << ": " << RLP(i.second);
|
|
||||||
g_logVerbosity = 99;
|
|
||||||
d2.remove(k);
|
|
||||||
g_logVerbosity = 4;
|
|
||||||
|
|
||||||
cwarn << "Good?" << d2.root();
|
|
||||||
}
|
|
||||||
BOOST_REQUIRE(d.check());
|
|
||||||
BOOST_REQUIRE_EQUAL(hash256(m), t.hash256());
|
|
||||||
BOOST_REQUIRE_EQUAL(hash256(m), d.root());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
75
trie.cpp
75
trie.cpp
@ -49,6 +49,7 @@ namespace eth
|
|||||||
BOOST_AUTO_TEST_CASE(trie_tests)
|
BOOST_AUTO_TEST_CASE(trie_tests)
|
||||||
{
|
{
|
||||||
cnote << "Testing Trie...";
|
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?");
|
BOOST_REQUIRE_MESSAGE( s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
@ -56,7 +57,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
|||||||
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();
|
||||||
// cnote << i.first;
|
cnote << i.first;
|
||||||
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()));
|
||||||
@ -66,14 +67,9 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
|||||||
BasicMap m;
|
BasicMap m;
|
||||||
GenericTrieDB<BasicMap> t(&m);
|
GenericTrieDB<BasicMap> t(&m);
|
||||||
t.init();
|
t.init();
|
||||||
BOOST_REQUIRE(t.check());
|
|
||||||
for (auto const& k: ss)
|
for (auto const& k: ss)
|
||||||
{
|
|
||||||
// cdebug << k.first << k.second;
|
|
||||||
t.insert(k.first, k.second);
|
t.insert(k.first, k.second);
|
||||||
BOOST_REQUIRE(t.check());
|
BOOST_REQUIRE(!o["root"].is_null());
|
||||||
}
|
|
||||||
BOOST_REQUIRE(!o["root"].is_null());
|
|
||||||
BOOST_CHECK(o["root"].get_str() == toHex(t.root().asArray()) );
|
BOOST_CHECK(o["root"].get_str() == toHex(t.root().asArray()) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,9 +81,8 @@ inline h256 stringMapHash256(StringMap const& _s)
|
|||||||
return hash256(_s);
|
return hash256(_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(moreTrieTests)
|
int trieTest()
|
||||||
{
|
{
|
||||||
cnote << "Testing Trie more...";
|
|
||||||
#if 0
|
#if 0
|
||||||
// More tests...
|
// More tests...
|
||||||
{
|
{
|
||||||
@ -158,7 +153,6 @@ BOOST_AUTO_TEST_CASE(moreTrieTests)
|
|||||||
cout << RLP(t.rlp()) << endl;
|
cout << RLP(t.rlp()) << endl;
|
||||||
cout << toHex(t.rlp()) << endl;
|
cout << toHex(t.rlp()) << endl;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
BasicMap m;
|
BasicMap m;
|
||||||
GenericTrieDB<BasicMap> d(&m);
|
GenericTrieDB<BasicMap> d(&m);
|
||||||
@ -172,21 +166,20 @@ BOOST_AUTO_TEST_CASE(moreTrieTests)
|
|||||||
t.insert(a, b);
|
t.insert(a, b);
|
||||||
s[a] = b;
|
s[a] = b;
|
||||||
|
|
||||||
/*cout << endl << "-------------------------------" << endl;
|
cout << endl << "-------------------------------" << endl;
|
||||||
cout << a << " -> " << b << endl;
|
cout << a << " -> " << b << endl;
|
||||||
cout << d;
|
cout << d;
|
||||||
cout << m;
|
cout << m;
|
||||||
cout << d.root() << endl;
|
cout << d.root() << endl;
|
||||||
cout << hash256(s) << endl;*/
|
cout << hash256(s) << endl;
|
||||||
|
|
||||||
BOOST_REQUIRE(d.check());
|
assert(t.hash256() == hash256(s));
|
||||||
BOOST_REQUIRE_EQUAL(t.hash256(), hash256(s));
|
assert(d.root() == hash256(s));
|
||||||
BOOST_REQUIRE_EQUAL(d.root(), hash256(s));
|
|
||||||
for (auto const& i: s)
|
for (auto const& i: s)
|
||||||
{
|
{
|
||||||
(void)i;
|
(void)i;
|
||||||
BOOST_REQUIRE_EQUAL(t.at(i.first), i.second);
|
assert(t.at(i.first) == i.second);
|
||||||
BOOST_REQUIRE_EQUAL(d.at(i.first), i.second);
|
assert(d.at(i.first) == i.second);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -196,23 +189,22 @@ BOOST_AUTO_TEST_CASE(moreTrieTests)
|
|||||||
t.remove(a);
|
t.remove(a);
|
||||||
d.remove(string(a));
|
d.remove(string(a));
|
||||||
|
|
||||||
/*cout << endl << "-------------------------------" << endl;
|
cout << endl << "-------------------------------" << endl;
|
||||||
cout << "X " << a << endl;
|
cout << "X " << a << endl;
|
||||||
cout << d;
|
cout << d;
|
||||||
cout << m;
|
cout << m;
|
||||||
cout << d.root() << endl;
|
cout << d.root() << endl;
|
||||||
cout << hash256(s) << endl;*/
|
cout << hash256(s) << endl;
|
||||||
|
|
||||||
BOOST_REQUIRE(d.check());
|
assert(t.at(a).empty());
|
||||||
BOOST_REQUIRE(t.at(a).empty());
|
assert(d.at(string(a)).empty());
|
||||||
BOOST_REQUIRE(d.at(string(a)).empty());
|
assert(t.hash256() == hash256(s));
|
||||||
BOOST_REQUIRE_EQUAL(t.hash256(), hash256(s));
|
assert(d.root() == hash256(s));
|
||||||
BOOST_REQUIRE_EQUAL(d.root(), hash256(s));
|
|
||||||
for (auto const& i: s)
|
for (auto const& i: s)
|
||||||
{
|
{
|
||||||
(void)i;
|
(void)i;
|
||||||
BOOST_REQUIRE_EQUAL(t.at(i.first), i.second);
|
assert(t.at(i.first) == i.second);
|
||||||
BOOST_REQUIRE_EQUAL(d.at(i.first), i.second);
|
assert(d.at(i.first) == i.second);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -227,5 +219,36 @@ BOOST_AUTO_TEST_CASE(moreTrieTests)
|
|||||||
remove("doge");
|
remove("doge");
|
||||||
remove("doe");
|
remove("doe");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
BasicMap m;
|
||||||
|
GenericTrieDB<BasicMap> d(&m);
|
||||||
|
d.init(); // initialise as empty tree.
|
||||||
|
MemTrie t;
|
||||||
|
for (int a = 0; a < 20; ++a)
|
||||||
|
{
|
||||||
|
StringMap m;
|
||||||
|
for (int i = 0; i < 20; ++i)
|
||||||
|
{
|
||||||
|
auto k = randomWord();
|
||||||
|
auto v = toString(i);
|
||||||
|
m.insert(make_pair(k, v));
|
||||||
|
t.insert(k, v);
|
||||||
|
d.insert(k, v);
|
||||||
|
assert(hash256(m) == t.hash256());
|
||||||
|
assert(hash256(m) == d.root());
|
||||||
|
}
|
||||||
|
while (!m.empty())
|
||||||
|
{
|
||||||
|
auto k = m.begin()->first;
|
||||||
|
d.remove(k);
|
||||||
|
t.remove(k);
|
||||||
|
m.erase(k);
|
||||||
|
assert(hash256(m) == t.hash256());
|
||||||
|
assert(hash256(m) == d.root());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user