diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-04-21 14:16:12 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-04-21 14:16:12 +0800 |
commit | 6bf24491b8022379cbb2c661d2e1dfa1333a9112 (patch) | |
tree | 1ce162a7485347eb3e097157fcb4c58ac1891987 /TestHelper.cpp | |
parent | 6c146899e04041c90bf61aed325780b474f2224d (diff) | |
parent | e375612a7ecbab9ad33a6a40df1c722a82e07630 (diff) | |
download | dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.tar dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.tar.gz dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.tar.bz2 dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.tar.lz dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.tar.xz dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.tar.zst dexon-solidity-6bf24491b8022379cbb2c661d2e1dfa1333a9112.zip |
Merge branch 'develop' into cmake3.2.1
Conflicts:
test/CMakeLists.txt
Diffstat (limited to 'TestHelper.cpp')
-rw-r--r-- | TestHelper.cpp | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp index 93c564e6..1419afde 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -23,9 +23,6 @@ #include <thread> #include <chrono> - -#include <boost/filesystem/path.hpp> - #include <libethereum/Client.h> #include <liblll/Compiler.h> #include <libevm/VMFactory.h> @@ -119,6 +116,32 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): } } +json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) +{ + static const set<string> hashes {"bloom" , "coinbase", "hash", "mixHash", "parentHash", "receiptTrie", + "stateRoot", "transactionsTrie", "uncleHash", "currentCoinbase", + "previousHash", "to", "address", "caller", "origin", "secretKey", "data"}; + + for (auto& i: _o) + { + std::string key = i.first; + if (hashes.count(key)) + continue; + + std::string str; + json_spirit::mValue value = i.second; + + if (value.type() == json_spirit::int_type) + str = toString(value.get_int()); + else if (value.type() == json_spirit::str_type) + str = value.get_str(); + else continue; + + _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str), 1)); + } + return _o; +} + void ImportTest::importEnv(json_spirit::mObject& _o) { assert(_o.count("previousHash") > 0); @@ -325,6 +348,8 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) // export pre state m_TestObject["pre"] = fillJsonWithState(m_statePre); + m_TestObject["env"] = makeAllFieldsHex(m_TestObject["env"].get_obj()); + m_TestObject["transaction"] = makeAllFieldsHex(m_TestObject["transaction"].get_obj()); } json_spirit::mObject fillJsonWithState(State _state) @@ -335,8 +360,8 @@ json_spirit::mObject fillJsonWithState(State _state) for (auto const& a: _state.addresses()) { json_spirit::mObject o; - o["balance"] = toString(_state.balance(a.first)); - o["nonce"] = toString(_state.transactionsFrom(a.first)); + o["balance"] = "0x" + toHex(toCompactBigEndian(_state.balance(a.first), 1)); + o["nonce"] = "0x" + toHex(toCompactBigEndian(_state.transactionsFrom(a.first), 1)); { json_spirit::mObject store; for (auto const& s: _state.storage(a.first)) @@ -564,7 +589,7 @@ void userDefinedTest(string testTypeFlag, std::function<void(json_spirit::mValue } } -void executeTests(const string& _name, const string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests) +void executeTests(const string& _name, const string& _testPathAppendix, const boost::filesystem::path _pathToFiller, std::function<void(json_spirit::mValue&, bool)> doTests) { string testPath = getTestPath(); testPath += _testPathAppendix; @@ -579,9 +604,8 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun cnote << "Populating tests..."; json_spirit::mValue v; boost::filesystem::path p(__FILE__); - boost::filesystem::path dir = p.parent_path(); - string s = asString(dev::contents(dir.string() + "/" + _name + "Filler.json")); - BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + dir.string() + "/" + _name + "Filler.json is empty."); + string s = asString(dev::contents(_pathToFiller.string() + "/" + _name + "Filler.json")); + BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + _pathToFiller.string() + "/" + _name + "Filler.json is empty."); json_spirit::read_string(s, v); doTests(v, true); writeFile(testPath + "/" + _name + ".json", asBytes(json_spirit::write_string(v, true))); |