From 99a0ef91a0f1beb0207e57a107304b0129660114 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 13 Apr 2015 16:33:42 +0300 Subject: [PATCH] All Fields Hex: block tests --- test/TestHelper.cpp | 19 ++++++++----------- test/blockchain.cpp | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index 5b8e7fbcf..c02e8b280 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -120,13 +120,17 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) { + static const std::string hashes[] = {"bloom" , "coinbase", "hash", "mixHash", "parentHash", "receiptTrie", + "stateRoot", "transactionsTrie", "uncleHash", "currentCoinbase", + "previousHash", "to", "address", "caller", "origin"}; + for (json_spirit::mObject::iterator it = _o.begin(); it != _o.end(); it++) { - string key = (*it).first; - if (key == "to") + std::string key = (*it).first; + if (std::find(std::begin(hashes), std::end(hashes), key) != std::end(hashes)) continue; - string str; + std::string str; json_spirit::mValue value = (*it).second; if (value.type() == json_spirit::int_type) @@ -135,14 +139,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x" || - str.find("a") != string::npos || - str.find("b") != string::npos || - str.find("c") != string::npos || - str.find("d") != string::npos || - str.find("e") != string::npos || - str.find("f") != string::npos - ) ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); + _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); } return _o; } diff --git a/test/blockchain.cpp b/test/blockchain.cpp index 4aa70c63a..b144abe62 100644 --- a/test/blockchain.cpp +++ b/test/blockchain.cpp @@ -90,7 +90,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) for (auto const& bl: o["blocks"].get_array()) { mObject blObj = bl.get_obj(); - stateTemp = state; + // get txs TransactionQueue txs; ZeroGasPricer gp; @@ -222,6 +222,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) txObject["v"] = to_string(txi.second.signature().v + 27); txObject["to"] = txi.second.isCreation() ? "" : toString(txi.second.receiveAddress()); txObject["value"] = toString(txi.second.value()); + txObject = ImportTest::makeAllFieldsHex(txObject); txArray.push_back(txObject); } @@ -301,6 +302,11 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin) o["blocks"] = blArray; o["postState"] = fillJsonWithState(state); + + //make all values hex + State prestate(OverlayDB(), BaseState::Empty, biGenesisBlock.coinbaseAddress); + importer.importState(o["pre"].get_obj(), prestate); + o["pre"] = fillJsonWithState(prestate); }//_fillin else @@ -619,11 +625,11 @@ void writeBlockHeaderToJson(mObject& _o, BlockInfo const& _bi) _o["transactionsTrie"] = toString(_bi.transactionsRoot); _o["receiptTrie"] = toString(_bi.receiptsRoot); _o["bloom"] = toString(_bi.logBloom); - _o["difficulty"] = toString(_bi.difficulty); - _o["number"] = toString(_bi.number); - _o["gasLimit"] = toString(_bi.gasLimit); - _o["gasUsed"] = toString(_bi.gasUsed); - _o["timestamp"] = toString(_bi.timestamp); + _o["difficulty"] = "0x" + toHex(toCompactBigEndian(_bi.difficulty)); + _o["number"] = "0x" + toHex(toCompactBigEndian(_bi.number)); + _o["gasLimit"] = "0x" + toHex(toCompactBigEndian(_bi.gasLimit)); + _o["gasUsed"] = "0x" + toHex(toCompactBigEndian(_bi.gasUsed)); + _o["timestamp"] = "0x" + toHex(toCompactBigEndian(_bi.timestamp)); _o["extraData"] ="0x" + toHex(_bi.extraData); _o["mixHash"] = toString(_bi.mixHash); _o["nonce"] = toString(_bi.nonce);