From 7df5ec34c778414079b879a5bd1ce3ec83cffa85 Mon Sep 17 00:00:00 2001 From: Paweł Bylica Date: Wed, 19 Nov 2014 13:13:19 +0100 Subject: In VM tests, check only if an exception occurred if an exception expected (no post state and output checking) --- TestHelper.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 1b13f9e8..114399a4 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -374,6 +374,7 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun { BOOST_ERROR("Failed test with Exception: " << _e.what()); } + break; } } -- cgit From b1e26e28e3996abb2c45edf481681a491a357f32 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Wed, 19 Nov 2014 14:30:42 +0100 Subject: Add Log tests --- TestHelper.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 1b13f9e8..a0e2d572 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -287,6 +287,18 @@ void checkStorage(map _expectedStore, map _resultStore, } } +void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) +{ + BOOST_REQUIRE_EQUAL(_resultLogs.size(), _expectedLogs.size()); + + for (size_t i = 0; i < _resultLogs.size(); ++i) + { + BOOST_CHECK(_resultLogs[i].address == _expectedLogs[i].address); + BOOST_CHECK(_resultLogs[i].topics == _expectedLogs[i].topics); + BOOST_CHECK(_resultLogs[i].data == _expectedLogs[i].data); + } +} + std::string getTestPath() { string testPath; -- cgit From 16be7563e1a5e0b2b16859b46058a88adc76c203 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Thu, 20 Nov 2014 20:41:35 +0100 Subject: Specify user defined test --- TestHelper.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 114399a4..4ce17589 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -310,12 +310,13 @@ void userDefinedTest(string testTypeFlag, std::function= boost::unit_test::framework::master_test_suite().argc) + if (i + 2 >= boost::unit_test::framework::master_test_suite().argc) { - cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " \n"; + cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " \n"; return; } string filename = boost::unit_test::framework::master_test_suite().argv[i + 1]; + string testname = boost::unit_test::framework::master_test_suite().argv[i + 2]; int currentVerbosity = g_logVerbosity; g_logVerbosity = 12; try @@ -325,7 +326,19 @@ void userDefinedTest(string testTypeFlag, std::function 0, "Contents of " + filename + " is empty. "); json_spirit::read_string(s, v); - doTests(v, false); + json_spirit::mObject oSingleTest; + + json_spirit::mObject::const_iterator pos = v.get_obj().find(testname); + if (pos == v.get_obj().end()) + { + cnote << "Could not find test: " << testname << " in " << filename << "\n"; + return; + } + else + oSingleTest[pos->first] = pos->second; + + json_spirit::mValue v_singleTest(oSingleTest); + doTests(v_singleTest, false); } catch (Exception const& _e) { -- cgit From e450bde11357bf4d138b8008c5c201d9ee91ce3e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Thu, 20 Nov 2014 22:21:08 +0100 Subject: style --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 4ce17589..d724eb39 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -310,7 +310,7 @@ void userDefinedTest(string testTypeFlag, std::function= boost::unit_test::framework::master_test_suite().argc) + if (boost::unit_test::framework::master_test_suite().argc <= i + 2) { cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " \n"; return; -- cgit From 70a1f73047d884f83cf2b706179f0bbc801e34f6 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 21 Nov 2014 07:42:41 +0100 Subject: style --- TestHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 66370ca3..c4128932 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -293,8 +293,8 @@ void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) for (size_t i = 0; i < _resultLogs.size(); ++i) { - BOOST_CHECK(_resultLogs[i].address == _expectedLogs[i].address); - BOOST_CHECK(_resultLogs[i].topics == _expectedLogs[i].topics); + BOOST_CHECK_EQUAL(_resultLogs[i].address, _expectedLogs[i].address); + BOOST_CHECK_EQUAL(_resultLogs[i].topics, _expectedLogs[i].topics); BOOST_CHECK(_resultLogs[i].data == _expectedLogs[i].data); } } -- cgit From d952833c1b86ce45c6da826ce2a9877ffa795d9e Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Dec 2014 22:04:09 +0100 Subject: added logs to state tests --- TestHelper.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index b3d1bbe8..b9575ad2 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -72,6 +72,7 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o if (!isFiller) { importState(_o["post"].get_obj(), m_statePost); + m_environment.sub.logs = importLog(_o["logs"].get_obj()); } } @@ -95,6 +96,7 @@ void ImportTest::importEnv(json_spirit::mObject& _o) m_statePre.m_currentBlock = m_environment.currentBlock; } + void ImportTest::importState(json_spirit::mObject& _o, State& _state) { for (auto& i: _o) @@ -148,6 +150,9 @@ void ImportTest::exportTest(bytes _output, State& _statePost) // export output m_TestObject["out"] = "0x" + toHex(_output); + // export logs + m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); + // export post state json_spirit::mObject postState; @@ -255,6 +260,44 @@ bytes importCode(json_spirit::mObject& _o) return code; } +LogEntries importLog(json_spirit::mObject& _o) +{ + LogEntries logEntries; + for (auto const& l: _o) + { + json_spirit::mObject o = l.second.get_obj(); + // cant use BOOST_REQUIRE, because this function is used outside boost test (createRandomTest) + assert(o.count("address") > 0); + assert(o.count("topics") > 0); + assert(o.count("data") > 0); + LogEntry log; + log.address = Address(o["address"].get_str()); + for (auto const& t: o["topics"].get_array()) + log.topics.insert(h256(t.get_str())); + log.data = importData(o); + logEntries.push_back(log); + } + return logEntries; +} + +json_spirit::mObject exportLog(eth::LogEntries _logs) +{ + json_spirit::mObject ret; + if (_logs.size() == 0) return ret; + for (LogEntry const& l: _logs) + { + json_spirit::mObject o; + o["address"] = toString(l.address); + json_spirit::mArray topics; + for (auto const& t: l.topics) + topics.push_back(toString(t)); + o["topics"] = topics; + o["data"] = "0x" + toHex(l.data); + ret[toString(l.bloom())] = o; + } + return ret; +} + void checkOutput(bytes const& _output, json_spirit::mObject& _o) { int j = 0; -- cgit From fb7c3bb302e5d309b500e2929a565b427de23a8b Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 1 Dec 2014 22:44:31 +0100 Subject: style Conflicts: libevm/VM.h --- TestHelper.cpp | 67 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index b9575ad2..bfdd393d 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -72,7 +72,7 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o if (!isFiller) { importState(_o["post"].get_obj(), m_statePost); - m_environment.sub.logs = importLog(_o["logs"].get_obj()); + m_environment.sub.logs = importLog(_o["logs"].get_obj()); } } @@ -96,7 +96,6 @@ void ImportTest::importEnv(json_spirit::mObject& _o) m_statePre.m_currentBlock = m_environment.currentBlock; } - void ImportTest::importState(json_spirit::mObject& _o, State& _state) { for (auto& i: _o) @@ -150,8 +149,8 @@ void ImportTest::exportTest(bytes _output, State& _statePost) // export output m_TestObject["out"] = "0x" + toHex(_output); - // export logs - m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); + // export logs + m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); // export post state json_spirit::mObject postState; @@ -262,40 +261,40 @@ bytes importCode(json_spirit::mObject& _o) LogEntries importLog(json_spirit::mObject& _o) { - LogEntries logEntries; - for (auto const& l: _o) - { - json_spirit::mObject o = l.second.get_obj(); - // cant use BOOST_REQUIRE, because this function is used outside boost test (createRandomTest) - assert(o.count("address") > 0); - assert(o.count("topics") > 0); - assert(o.count("data") > 0); - LogEntry log; - log.address = Address(o["address"].get_str()); - for (auto const& t: o["topics"].get_array()) - log.topics.insert(h256(t.get_str())); - log.data = importData(o); - logEntries.push_back(log); - } - return logEntries; + LogEntries logEntries; + for (auto const& l: _o) + { + json_spirit::mObject o = l.second.get_obj(); + // cant use BOOST_REQUIRE, because this function is used outside boost test (createRandomTest) + assert(o.count("address") > 0); + assert(o.count("topics") > 0); + assert(o.count("data") > 0); + LogEntry log; + log.address = Address(o["address"].get_str()); + for (auto const& t: o["topics"].get_array()) + log.topics.insert(h256(t.get_str())); + log.data = importData(o); + logEntries.push_back(log); + } + return logEntries; } json_spirit::mObject exportLog(eth::LogEntries _logs) { - json_spirit::mObject ret; - if (_logs.size() == 0) return ret; - for (LogEntry const& l: _logs) - { - json_spirit::mObject o; - o["address"] = toString(l.address); - json_spirit::mArray topics; - for (auto const& t: l.topics) - topics.push_back(toString(t)); - o["topics"] = topics; - o["data"] = "0x" + toHex(l.data); - ret[toString(l.bloom())] = o; - } - return ret; + json_spirit::mObject ret; + if (_logs.size() == 0) return ret; + for (LogEntry const& l: _logs) + { + json_spirit::mObject o; + o["address"] = toString(l.address); + json_spirit::mArray topics; + for (auto const& t: l.topics) + topics.push_back(toString(t)); + o["topics"] = topics; + o["data"] = "0x" + toHex(l.data); + ret[toString(l.bloom())] = o; + } + return ret; } void checkOutput(bytes const& _output, json_spirit::mObject& _o) -- cgit From 9101b7073ab188e71a4ab26298ffacc529cdf97b Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 5 Dec 2014 19:26:32 +0100 Subject: state log tests --- TestHelper.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index e6426474..ea0bf341 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -72,7 +72,7 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o if (!isFiller) { importState(_o["post"].get_obj(), m_statePost); - m_environment.sub.logs = importLog(_o["logs"].get_obj()); + m_environment.sub.logs = importLog(_o["logs"].get_array()); } } @@ -259,16 +259,17 @@ bytes importCode(json_spirit::mObject& _o) return code; } -LogEntries importLog(json_spirit::mObject& _o) +LogEntries importLog(json_spirit::mArray& _a) { LogEntries logEntries; - for (auto const& l: _o) + for (auto const& l: _a) { - json_spirit::mObject o = l.second.get_obj(); + json_spirit::mObject o = l.get_obj(); // cant use BOOST_REQUIRE, because this function is used outside boost test (createRandomTest) assert(o.count("address") > 0); assert(o.count("topics") > 0); assert(o.count("data") > 0); + assert(o.count("bloom") > 0); LogEntry log; log.address = Address(o["address"].get_str()); for (auto const& t: o["topics"].get_array()) @@ -279,9 +280,9 @@ LogEntries importLog(json_spirit::mObject& _o) return logEntries; } -json_spirit::mObject exportLog(eth::LogEntries _logs) +json_spirit::mArray exportLog(eth::LogEntries _logs) { - json_spirit::mObject ret; + json_spirit::mArray ret; if (_logs.size() == 0) return ret; for (LogEntry const& l: _logs) { @@ -292,7 +293,8 @@ json_spirit::mObject exportLog(eth::LogEntries _logs) topics.push_back(toString(t)); o["topics"] = topics; o["data"] = "0x" + toHex(l.data); - ret[toString(l.bloom())] = o; + o["bloom"] = toString(l.bloom()); + ret.push_back(o); } return ret; } -- cgit From 5d22ebe4474824aa769eeea570808ada310e2516 Mon Sep 17 00:00:00 2001 From: Paweł Bylica Date: Fri, 14 Nov 2014 11:44:51 +0100 Subject: Test unexpected storage entries --- TestHelper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index ea0bf341..b0935d0b 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -329,6 +329,12 @@ void checkStorage(map _expectedStore, map _resultStore, BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue); } } + + for (auto&& resultStorePair : _resultStore) + { + if (!_expectedStore.count(resultStorePair.first)) + BOOST_ERROR("unexpected result store key " << resultStorePair.first); + } } void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) -- cgit From c044e1d1e99ebfc6f899e7d46cfb662d57dd6377 Mon Sep 17 00:00:00 2001 From: Paweł Bylica Date: Thu, 11 Dec 2014 19:33:49 +0100 Subject: Report wrong account address in case of unexpected storege key --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index b0935d0b..566c3c53 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -333,7 +333,7 @@ void checkStorage(map _expectedStore, map _resultStore, for (auto&& resultStorePair : _resultStore) { if (!_expectedStore.count(resultStorePair.first)) - BOOST_ERROR("unexpected result store key " << resultStorePair.first); + BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); } } -- cgit From 8ada6f3cb936266f2988bc09e84728933c3e39ba Mon Sep 17 00:00:00 2001 From: Paweł Bylica Date: Thu, 11 Dec 2014 20:46:05 +0100 Subject: Replace spaces with tabs --- TestHelper.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 566c3c53..1201cfee 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -330,11 +330,11 @@ void checkStorage(map _expectedStore, map _resultStore, } } - for (auto&& resultStorePair : _resultStore) - { - if (!_expectedStore.count(resultStorePair.first)) - BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); - } + for (auto&& resultStorePair : _resultStore) + { + if (!_expectedStore.count(resultStorePair.first)) + BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); + } } void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) -- cgit From fe21a5c67e77771ed43cb7ef58de1d3b9a9ce8cb Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 20:49:28 +0100 Subject: Style fix. --- TestHelper.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 1201cfee..ff8a0d40 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -331,10 +331,8 @@ void checkStorage(map _expectedStore, map _resultStore, } for (auto&& resultStorePair : _resultStore) - { if (!_expectedStore.count(resultStorePair.first)) BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); - } } void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) -- cgit From 7f9f847c276083203fbb3e0884f53870260b6e59 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 12 Dec 2014 21:21:18 +0100 Subject: Fix import state for state tests Conflicts: test/TestHelper.cpp --- TestHelper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index ff8a0d40..e8940cc7 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -109,9 +109,6 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) Address address = Address(i.first); - for (auto const& j: o["storage"].get_obj()) - _state.setStorage(address, toInt(j.first), toInt(j.second)); - bytes code = importCode(o); if (code.size()) @@ -122,6 +119,9 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) else _state.m_cache[address] = Account(toInt(o["balance"]), Account::NormalCreation); + for (auto const& j: o["storage"].get_obj()) + _state.setStorage(address, toInt(j.first), toInt(j.second)); + for(int i=0; i _expectedStore, map _resultStore, BOOST_CHECK_MESSAGE(expectedStoreValue == resultStoreValue, _expectedAddr << ": store[" << expectedStoreKey << "] = " << resultStoreValue << ", expected " << expectedStoreValue); } } - + BOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size()); for (auto&& resultStorePair : _resultStore) if (!_expectedStore.count(resultStorePair.first)) BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); -- cgit From 25faab7009d851eb3afca57c9891cd7c151be36e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 13 Dec 2014 21:24:13 +0100 Subject: Another Windows fix? --- TestHelper.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index e8940cc7..0c1ee290 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -330,9 +330,11 @@ void checkStorage(map _expectedStore, map _resultStore, } } BOOST_CHECK_EQUAL(_resultStore.size(), _expectedStore.size()); +#ifndef __WIN32__ for (auto&& resultStorePair : _resultStore) if (!_expectedStore.count(resultStorePair.first)) BOOST_ERROR(_expectedAddr << ": unexpected store key " << resultStorePair.first); +#endif } void checkLog(LogEntries _resultLogs, LogEntries _expectedLogs) -- cgit