diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-12-04 08:26:10 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2014-12-04 08:26:10 +0800 |
commit | dc31f34c54f517ce9589d30087f8381d1ea2a420 (patch) | |
tree | ab5b1cd5ac5ca265100a1809b9297b53d62fe0a8 /TestHelper.cpp | |
parent | 82dbdce5ee90acd189653d367a6e3bdae1e93d33 (diff) | |
parent | 3c8a45cec4a36ebd4560d7f4ee718b60680b3010 (diff) | |
download | dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.tar dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.tar.gz dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.tar.bz2 dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.tar.lz dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.tar.xz dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.tar.zst dexon-solidity-dc31f34c54f517ce9589d30087f8381d1ea2a420.zip |
Merge branch 'develop' into build_enhancement
Conflicts:
eth/main.cpp
neth/main.cpp
Diffstat (limited to 'TestHelper.cpp')
-rw-r--r-- | TestHelper.cpp | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp index 114399a4..e6426474 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()); } } @@ -148,6 +149,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 +259,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.push_back(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; @@ -287,6 +329,18 @@ void checkStorage(map<u256, u256> _expectedStore, map<u256, u256> _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_EQUAL(_resultLogs[i].address, _expectedLogs[i].address); + BOOST_CHECK_EQUAL(_resultLogs[i].topics, _expectedLogs[i].topics); + BOOST_CHECK(_resultLogs[i].data == _expectedLogs[i].data); + } +} + std::string getTestPath() { string testPath; @@ -310,12 +364,13 @@ void userDefinedTest(string testTypeFlag, std::function<void(json_spirit::mValue string arg = boost::unit_test::framework::master_test_suite().argv[i]; if (arg == testTypeFlag) { - if (i + 1 >= 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 << " <filename>\n"; + cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " <filename> <testname>\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 +380,19 @@ void userDefinedTest(string testTypeFlag, std::function<void(json_spirit::mValue string s = asString(contents(filename)); BOOST_REQUIRE_MESSAGE(s.length() > 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) { |