diff options
author | Gav Wood <g@ethdev.com> | 2015-04-17 17:45:26 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-04-17 17:45:26 +0800 |
commit | 3c353e2d0ed66117793864977c3de84a371f8d28 (patch) | |
tree | d31b5d5ac3b48f9aa870e01122299a82f2ebdeb2 /TestHelper.cpp | |
parent | c38641374a4e45ba84a99a3a34431010c9d6059d (diff) | |
parent | e1e5f2f0481121c016e0f7317c0d9b1f0df3dd7e (diff) | |
download | dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.tar dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.tar.gz dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.tar.bz2 dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.tar.lz dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.tar.xz dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.tar.zst dexon-solidity-3c353e2d0ed66117793864977c3de84a371f8d28.zip |
Merge pull request #1569 from winsvega/allfieldshex
All Test Fields As Hex
Diffstat (limited to 'TestHelper.cpp')
-rw-r--r-- | TestHelper.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp index 93c564e6..92a8258a 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -119,6 +119,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"}; + + 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))); + } + return _o; +} + void ImportTest::importEnv(json_spirit::mObject& _o) { assert(_o.count("previousHash") > 0); @@ -325,6 +351,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 +363,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))); + o["nonce"] = "0x" + toHex(toCompactBigEndian(_state.transactionsFrom(a.first))); { json_spirit::mObject store; for (auto const& s: _state.storage(a.first)) |