From bfa1e9b7b9e1564482baeb09e3b7385ec6139fe8 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 9 Apr 2015 21:30:00 +0300 Subject: AllFieldsHex: State Tests --- TestHelper.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 93c564e6..127bff5a 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -102,7 +102,6 @@ struct ValueTooLarge: virtual Exception {}; struct MissingFields : virtual Exception {}; bigint const c_max256plus1 = bigint(1) << 256; - ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_statePre(OverlayDB(), eth::BaseState::Empty, Address(_o["env"].get_obj()["currentCoinbase"].get_str())), m_statePost(OverlayDB(), eth::BaseState::Empty, Address(_o["env"].get_obj()["currentCoinbase"].get_str())), @@ -119,6 +118,27 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): } } +json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) +{ + for (json_spirit::mObject::iterator it = _o.begin(); it != _o.end(); it++) + { + string key = (*it).first; + if (key == "to") + continue; + + string str = (*it).second.get_str(); + _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))); + } + return _o; +} + void ImportTest::importEnv(json_spirit::mObject& _o) { assert(_o.count("previousHash") > 0); @@ -325,6 +345,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 +357,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)) -- cgit v1.2.3 From 10245ce4b3b3b5dcf50dac8a097b96cd1d5adaf9 Mon Sep 17 00:00:00 2001 From: winsvega Date: Fri, 10 Apr 2015 02:13:54 +0300 Subject: All Fields Hex: VMTests --- TestHelper.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 127bff5a..5b8e7fbc 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -126,15 +126,23 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) if (key == "to") continue; - string str = (*it).second.get_str(); + string str; + json_spirit::mValue value = (*it).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.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))); + 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))); } return _o; } -- cgit v1.2.3 From 92269d4df7b6d3b454ca44a8dde2ab0a3e113749 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 13 Apr 2015 16:33:42 +0300 Subject: All Fields Hex: block tests --- TestHelper.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 5b8e7fbc..c02e8b28 100644 --- a/TestHelper.cpp +++ b/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; } -- cgit v1.2.3 From 3e605abea486792ad749461f4d9e209b2ee6f07e Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 9 Apr 2015 21:30:00 +0300 Subject: AllFieldsHex: State Tests --- TestHelper.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index c02e8b28..2c7f9a48 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -102,6 +102,7 @@ struct ValueTooLarge: virtual Exception {}; struct MissingFields : virtual Exception {}; bigint const c_max256plus1 = bigint(1) << 256; + ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_statePre(OverlayDB(), eth::BaseState::Empty, Address(_o["env"].get_obj()["currentCoinbase"].get_str())), m_statePost(OverlayDB(), eth::BaseState::Empty, Address(_o["env"].get_obj()["currentCoinbase"].get_str())), -- cgit v1.2.3 From c867e185bf1bf2d813bc8123d904c6a9bd7bde90 Mon Sep 17 00:00:00 2001 From: winsvega Date: Fri, 10 Apr 2015 02:13:54 +0300 Subject: All Fields Hex: VMTests --- TestHelper.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 2c7f9a48..a689a40b 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -131,7 +131,11 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) if (std::find(std::begin(hashes), std::end(hashes), key) != std::end(hashes)) continue; +<<<<<<< HEAD std::string str; +======= + string str; +>>>>>>> All Fields Hex: VMTests json_spirit::mValue value = (*it).second; if (value.type() == json_spirit::int_type) @@ -140,7 +144,18 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; +<<<<<<< HEAD _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); +======= + _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))); +>>>>>>> All Fields Hex: VMTests } return _o; } -- cgit v1.2.3 From b040e23463041e40f98514a23a4eac7ce863fa08 Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 13 Apr 2015 16:33:42 +0300 Subject: All Fields Hex: block tests --- TestHelper.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index a689a40b..882bb5a9 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -131,11 +131,15 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) if (std::find(std::begin(hashes), std::end(hashes), key) != std::end(hashes)) continue; +<<<<<<< HEAD <<<<<<< HEAD std::string str; ======= string str; >>>>>>> All Fields Hex: VMTests +======= + std::string str; +>>>>>>> All Fields Hex: block tests json_spirit::mValue value = (*it).second; if (value.type() == json_spirit::int_type) @@ -144,6 +148,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; +<<<<<<< HEAD <<<<<<< HEAD _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); ======= @@ -156,6 +161,9 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str.find("f") != string::npos ) ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); >>>>>>> All Fields Hex: VMTests +======= + _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); +>>>>>>> All Fields Hex: block tests } return _o; } -- cgit v1.2.3 From 721ee6519572b13ea62660cd19f481f5a9bb052f Mon Sep 17 00:00:00 2001 From: winsvega Date: Mon, 13 Apr 2015 23:57:57 +0300 Subject: All Fields As Hex: Secret Key --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 882bb5a9..120a4e16 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -123,7 +123,7 @@ 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"}; + "previousHash", "to", "address", "caller", "origin", "secretKey"}; for (json_spirit::mObject::iterator it = _o.begin(); it != _o.end(); it++) { -- cgit v1.2.3 From d175996b3a6ffd5a16efb6a4ad83b5e88fa1bab7 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 14 Apr 2015 00:44:31 +0300 Subject: All Fields Hex rebase + merge error fix --- TestHelper.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 120a4e16..85e45500 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -131,15 +131,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) if (std::find(std::begin(hashes), std::end(hashes), key) != std::end(hashes)) continue; -<<<<<<< HEAD -<<<<<<< HEAD std::string str; -======= - string str; ->>>>>>> All Fields Hex: VMTests -======= - std::string str; ->>>>>>> All Fields Hex: block tests json_spirit::mValue value = (*it).second; if (value.type() == json_spirit::int_type) @@ -148,22 +140,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; -<<<<<<< HEAD -<<<<<<< HEAD - _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); -======= - _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))); ->>>>>>> All Fields Hex: VMTests -======= _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); ->>>>>>> All Fields Hex: block tests } return _o; } -- cgit v1.2.3 From 6e97308f27789b553a014adc9afd68c9fddc2e39 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 16 Apr 2015 02:03:26 +0300 Subject: All fields Hex: style --- TestHelper.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 85e45500..92a8258a 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -121,18 +121,18 @@ 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", "secretKey"}; + static const set hashes {"bloom" , "coinbase", "hash", "mixHash", "parentHash", "receiptTrie", + "stateRoot", "transactionsTrie", "uncleHash", "currentCoinbase", + "previousHash", "to", "address", "caller", "origin", "secretKey"}; - for (json_spirit::mObject::iterator it = _o.begin(); it != _o.end(); it++) + for (auto& i: _o) { - std::string key = (*it).first; - if (std::find(std::begin(hashes), std::end(hashes), key) != std::end(hashes)) + std::string key = i.first; + if (hashes.count(key)) continue; std::string str; - json_spirit::mValue value = (*it).second; + json_spirit::mValue value = i.second; if (value.type() == json_spirit::int_type) str = toString(value.get_int()); -- cgit v1.2.3 From 22d16c048bde69eb66d315990f2d407f7384cf4f Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 17 Apr 2015 18:41:27 +0200 Subject: 0x -> 0x0 for numbers --- TestHelper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 92a8258a..49c6bb02 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -123,7 +123,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) { static const set hashes {"bloom" , "coinbase", "hash", "mixHash", "parentHash", "receiptTrie", "stateRoot", "transactionsTrie", "uncleHash", "currentCoinbase", - "previousHash", "to", "address", "caller", "origin", "secretKey"}; + "previousHash", "to", "address", "caller", "origin", "secretKey", "data"}; for (auto& i: _o) { @@ -140,7 +140,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str))); + _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + (toHex(toCompactBigEndian(toInt(str))).empty() ? "0" : toHex(toCompactBigEndian(toInt(str)))); } return _o; } @@ -363,8 +363,8 @@ json_spirit::mObject fillJsonWithState(State _state) for (auto const& a: _state.addresses()) { json_spirit::mObject o; - o["balance"] = "0x" + toHex(toCompactBigEndian(_state.balance(a.first))); - o["nonce"] = "0x" + toHex(toCompactBigEndian(_state.transactionsFrom(a.first))); + o["balance"] = "0x" + (toHex(toCompactBigEndian(_state.balance(a.first))).empty() ? "0" : toHex(toCompactBigEndian(_state.balance(a.first)))); + o["nonce"] = "0x" + (toHex(toCompactBigEndian(_state.transactionsFrom(a.first))).empty() ? "0" : toHex(toCompactBigEndian(_state.transactionsFrom(a.first)))); { json_spirit::mObject store; for (auto const& s: _state.storage(a.first)) -- cgit v1.2.3 From d399f077eff87a2589188fe6353a42c7dd60597a Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 17 Apr 2015 22:44:26 +0200 Subject: simplification --- TestHelper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 49c6bb02..ed844e96 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -140,7 +140,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + (toHex(toCompactBigEndian(toInt(str))).empty() ? "0" : toHex(toCompactBigEndian(toInt(str)))); + _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str), 1)); } return _o; } @@ -363,8 +363,8 @@ json_spirit::mObject fillJsonWithState(State _state) for (auto const& a: _state.addresses()) { json_spirit::mObject o; - o["balance"] = "0x" + (toHex(toCompactBigEndian(_state.balance(a.first))).empty() ? "0" : toHex(toCompactBigEndian(_state.balance(a.first)))); - o["nonce"] = "0x" + (toHex(toCompactBigEndian(_state.transactionsFrom(a.first))).empty() ? "0" : toHex(toCompactBigEndian(_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)) -- cgit v1.2.3 From b2adcf3bf3a6326628b5413bddae2742073d8078 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 20 Apr 2015 22:48:53 +0200 Subject: Restructure test folders --- TestHelper.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index ed844e96..3d085682 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -23,9 +23,6 @@ #include #include - -#include - #include #include #include @@ -592,7 +589,7 @@ void userDefinedTest(string testTypeFlag, std::function doTests) +void executeTests(const string& _name, const string& _testPathAppendix, const boost::filesystem::path _pathToFiller, std::function doTests) { string testPath = getTestPath(); testPath += _testPathAppendix; @@ -605,11 +602,12 @@ void executeTests(const string& _name, const string& _testPathAppendix, std::fun try { cnote << "Populating tests..."; + cout << "boost::filesystem::current_path(): " << boost::filesystem::current_path().string() << endl; 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))); -- cgit v1.2.3 From 8f8eb359741efe6cba7d27c9f55212492987afac Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 20 Apr 2015 23:17:19 +0200 Subject: fixes --- TestHelper.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 3d085682..1419afde 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -602,10 +602,8 @@ void executeTests(const string& _name, const string& _testPathAppendix, const bo try { cnote << "Populating tests..."; - cout << "boost::filesystem::current_path(): " << boost::filesystem::current_path().string() << endl; json_spirit::mValue v; boost::filesystem::path p(__FILE__); - boost::filesystem::path dir = p.parent_path(); 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); -- cgit v1.2.3 From 332fcaebb96bef3a6e1c3239d9f3d7990668f400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 21 Apr 2015 10:37:47 +0200 Subject: testeth: Handle command line options for user defined tests --- TestHelper.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index ed844e96..92d38c00 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -542,6 +542,8 @@ void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _e void userDefinedTest(string testTypeFlag, std::function doTests) { + Options::get(); // parse command line options, e.g. to enable JIT + for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) { string arg = boost::unit_test::framework::master_test_suite().argv[i]; -- cgit v1.2.3 From bd08a2bbe23238edb3a25b0f345e8a38f3283e3a Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 21 Apr 2015 23:10:55 +0300 Subject: BlockWeight: tests refactoring --- TestHelper.cpp | 80 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 28 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 724bcaf6..8ea70ed1 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -137,7 +137,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x") ? str : "0x" + toHex(toCompactBigEndian(toInt(str), 1)); + _o[key] = (str.substr(0, 2) == "0x") ? str : jsonHex(toInt(str)); } return _o; } @@ -327,7 +327,7 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta void ImportTest::exportTest(bytes const& _output, State const& _statePost) { // export output - m_TestObject["out"] = "0x" + toHex(_output); + m_TestObject["out"] = jsonHex(_output); // export logs m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); @@ -344,7 +344,7 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) // export post state m_TestObject["post"] = fillJsonWithState(_statePost); - m_TestObject["postStateRoot"] = toHex(_statePost.rootHash().asBytes()); + m_TestObject["postStateRoot"] = jsonHex(_statePost.rootHash().asBytes()); // export pre state m_TestObject["pre"] = fillJsonWithState(m_statePre); @@ -352,29 +352,72 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) m_TestObject["transaction"] = makeAllFieldsHex(m_TestObject["transaction"].get_obj()); } +std::string jsonHash(h256 const& _value) { return toString(_value); } +std::string jsonHash(Nonce const& _value) { return toString(_value); } +std::string jsonHash(LogBloom const& _value) { return toString(_value); } +std::string jsonHash(Address const& _value) { return toString(_value); } +std::string jsonHex(bytesConstRef _code) { return "0x" + toHex(_code); } +std::string jsonHex(bytes const& _code) { return "0x" + toHex(_code); } +std::string jsonHex(u256 const& _value, bool _nonempty) +{ + return "0x" + toHex(toCompactBigEndian(_value, _nonempty ? 1 : 0)); +} + +json_spirit::mObject fillJsonWithTransaction(Transaction _txn) +{ + json_spirit::mObject txObject; + txObject["nonce"] = jsonHex(_txn.nonce()); + txObject["data"] = jsonHex(_txn.data()); + txObject["gasLimit"] = jsonHex(_txn.gas()); + txObject["gasPrice"] = jsonHex(_txn.gasPrice()); + txObject["r"] = jsonHex(_txn.signature().r); + txObject["s"] = jsonHex(_txn.signature().s); + txObject["v"] = jsonHex(_txn.signature().v + 27); + txObject["to"] = _txn.isCreation() ? "" : jsonHash(_txn.receiveAddress()); + txObject["value"] = jsonHex(_txn.value()); + return txObject; +} + json_spirit::mObject fillJsonWithState(State _state) { - // export pre state json_spirit::mObject oState; - for (auto const& a: _state.addresses()) { json_spirit::mObject o; - o["balance"] = "0x" + toHex(toCompactBigEndian(_state.balance(a.first), 1)); - o["nonce"] = "0x" + toHex(toCompactBigEndian(_state.transactionsFrom(a.first), 1)); + o["balance"] = jsonHex(_state.balance(a.first)); + o["nonce"] = jsonHex(_state.transactionsFrom(a.first)); { json_spirit::mObject store; for (auto const& s: _state.storage(a.first)) - store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second)); + store[jsonHex(s.first)] = jsonHex(s.second); o["storage"] = store; } - o["code"] = "0x" + toHex(_state.code(a.first)); + o["code"] = jsonHex(_state.code(a.first)); oState[toString(a.first)] = o; } return oState; } +json_spirit::mArray exportLog(eth::LogEntries _logs) +{ + json_spirit::mArray ret; + if (_logs.size() == 0) return ret; + for (LogEntry const& l: _logs) + { + json_spirit::mObject o; + o["address"] = jsonHash(l.address); + json_spirit::mArray topics; + for (auto const& t: l.topics) + topics.push_back(toString(t)); + o["topics"] = topics; + o["data"] = jsonHex(l.data); + o["bloom"] = jsonHash(l.bloom()); + ret.push_back(o); + } + return ret; +} + u256 toInt(json_spirit::mValue const& _v) { switch (_v.type()) @@ -455,25 +498,6 @@ LogEntries importLog(json_spirit::mArray& _a) return logEntries; } -json_spirit::mArray exportLog(eth::LogEntries _logs) -{ - json_spirit::mArray 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); - o["bloom"] = toString(l.bloom()); - ret.push_back(o); - } - return ret; -} - void checkOutput(bytes const& _output, json_spirit::mObject& _o) { int j = 0; -- cgit v1.2.3 From 5d35f71350b925fbd4da999f8db1c811b3f3757d Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 23 Apr 2015 02:43:35 +0300 Subject: BlockWeight: toCompactHex refactoring --- TestHelper.cpp | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 8ea70ed1..0aa508c2 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -137,7 +137,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x") ? str : jsonHex(toInt(str)); + _o[key] = (str.substr(0, 2) == "0x") ? str : toHex(toInt(str), HexPrefix::Add); } return _o; } @@ -327,7 +327,7 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta void ImportTest::exportTest(bytes const& _output, State const& _statePost) { // export output - m_TestObject["out"] = jsonHex(_output); + m_TestObject["out"] = "0x" + toString(_output); // export logs m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); @@ -344,7 +344,7 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) // export post state m_TestObject["post"] = fillJsonWithState(_statePost); - m_TestObject["postStateRoot"] = jsonHex(_statePost.rootHash().asBytes()); + m_TestObject["postStateRoot"] = toString(_statePost.rootHash().asBytes()); // export pre state m_TestObject["pre"] = fillJsonWithState(m_statePre); @@ -352,29 +352,18 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) m_TestObject["transaction"] = makeAllFieldsHex(m_TestObject["transaction"].get_obj()); } -std::string jsonHash(h256 const& _value) { return toString(_value); } -std::string jsonHash(Nonce const& _value) { return toString(_value); } -std::string jsonHash(LogBloom const& _value) { return toString(_value); } -std::string jsonHash(Address const& _value) { return toString(_value); } -std::string jsonHex(bytesConstRef _code) { return "0x" + toHex(_code); } -std::string jsonHex(bytes const& _code) { return "0x" + toHex(_code); } -std::string jsonHex(u256 const& _value, bool _nonempty) -{ - return "0x" + toHex(toCompactBigEndian(_value, _nonempty ? 1 : 0)); -} - json_spirit::mObject fillJsonWithTransaction(Transaction _txn) { json_spirit::mObject txObject; - txObject["nonce"] = jsonHex(_txn.nonce()); - txObject["data"] = jsonHex(_txn.data()); - txObject["gasLimit"] = jsonHex(_txn.gas()); - txObject["gasPrice"] = jsonHex(_txn.gasPrice()); - txObject["r"] = jsonHex(_txn.signature().r); - txObject["s"] = jsonHex(_txn.signature().s); - txObject["v"] = jsonHex(_txn.signature().v + 27); - txObject["to"] = _txn.isCreation() ? "" : jsonHash(_txn.receiveAddress()); - txObject["value"] = jsonHex(_txn.value()); + txObject["nonce"] = toCompactHex(_txn.nonce(), HexPrefix::Add); + txObject["data"] = "0x"+toString(_txn.data()); + txObject["gasLimit"] = toCompactHex(_txn.gas(), HexPrefix::Add); + txObject["gasPrice"] = toCompactHex(_txn.gasPrice(), HexPrefix::Add); + txObject["r"] = toCompactHex(_txn.signature().r, HexPrefix::Add); + txObject["s"] = toCompactHex(_txn.signature().s, HexPrefix::Add); + txObject["v"] = toCompactHex(_txn.signature().v + 27, HexPrefix::Add); + txObject["to"] = _txn.isCreation() ? "" : toString(_txn.receiveAddress()); + txObject["value"] = toCompactHex(_txn.value(), HexPrefix::Add); return txObject; } @@ -384,16 +373,15 @@ json_spirit::mObject fillJsonWithState(State _state) for (auto const& a: _state.addresses()) { json_spirit::mObject o; - o["balance"] = jsonHex(_state.balance(a.first)); - o["nonce"] = jsonHex(_state.transactionsFrom(a.first)); + o["balance"] = toCompactHex(_state.balance(a.first), HexPrefix::Add); + o["nonce"] = toCompactHex(_state.transactionsFrom(a.first), HexPrefix::Add); { json_spirit::mObject store; for (auto const& s: _state.storage(a.first)) - store[jsonHex(s.first)] = jsonHex(s.second); + store[toCompactHex(s.first, HexPrefix::Add)] = toCompactHex(s.second, HexPrefix::Add); o["storage"] = store; } - o["code"] = jsonHex(_state.code(a.first)); - + o["code"] = "0x" + toString(_state.code(a.first)); oState[toString(a.first)] = o; } return oState; @@ -406,13 +394,13 @@ json_spirit::mArray exportLog(eth::LogEntries _logs) for (LogEntry const& l: _logs) { json_spirit::mObject o; - o["address"] = jsonHash(l.address); + 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"] = jsonHex(l.data); - o["bloom"] = jsonHash(l.bloom()); + o["data"] = "0x" + toString(l.data); + o["bloom"] = toString(l.bloom()); ret.push_back(o); } return ret; -- cgit v1.2.3 From a5535ec86f9cd0f5db4b961936a1c3af7cf042b4 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 23 Apr 2015 03:42:45 +0300 Subject: BlockWeight: data fix refactoring --- TestHelper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 0aa508c2..69ad7dba 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -327,7 +327,7 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta void ImportTest::exportTest(bytes const& _output, State const& _statePost) { // export output - m_TestObject["out"] = "0x" + toString(_output); + m_TestObject["out"] = toHex(_output, 2, HexPrefix::Add); // export logs m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); @@ -356,7 +356,7 @@ json_spirit::mObject fillJsonWithTransaction(Transaction _txn) { json_spirit::mObject txObject; txObject["nonce"] = toCompactHex(_txn.nonce(), HexPrefix::Add); - txObject["data"] = "0x"+toString(_txn.data()); + txObject["data"] = toHex(_txn.data(), 2, HexPrefix::Add); txObject["gasLimit"] = toCompactHex(_txn.gas(), HexPrefix::Add); txObject["gasPrice"] = toCompactHex(_txn.gasPrice(), HexPrefix::Add); txObject["r"] = toCompactHex(_txn.signature().r, HexPrefix::Add); @@ -381,7 +381,7 @@ json_spirit::mObject fillJsonWithState(State _state) store[toCompactHex(s.first, HexPrefix::Add)] = toCompactHex(s.second, HexPrefix::Add); o["storage"] = store; } - o["code"] = "0x" + toString(_state.code(a.first)); + o["code"] = toHex(_state.code(a.first), 2, HexPrefix::Add); oState[toString(a.first)] = o; } return oState; @@ -399,7 +399,7 @@ json_spirit::mArray exportLog(eth::LogEntries _logs) for (auto const& t: l.topics) topics.push_back(toString(t)); o["topics"] = topics; - o["data"] = "0x" + toString(l.data); + o["data"] = toHex(l.data, 2, HexPrefix::Add); o["bloom"] = toString(l.bloom()); ret.push_back(o); } -- cgit v1.2.3 From d872539b1fd74452137309ac94fbb89e4faf6f43 Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 23 Apr 2015 13:09:23 +0300 Subject: blockweight: stateroot is hash --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 69ad7dba..b8e320e4 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -344,7 +344,7 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) // export post state m_TestObject["post"] = fillJsonWithState(_statePost); - m_TestObject["postStateRoot"] = toString(_statePost.rootHash().asBytes()); + m_TestObject["postStateRoot"] = toHex(_statePost.rootHash().asBytes()); // export pre state m_TestObject["pre"] = fillJsonWithState(m_statePre); -- cgit v1.2.3 From 1580c38d667b3bdf4a01c878aae20efceb58e27a Mon Sep 17 00:00:00 2001 From: winsvega Date: Thu, 23 Apr 2015 17:57:59 +0300 Subject: blockweight: allfields to compact Hex fix --- TestHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index b8e320e4..57ec0566 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -137,7 +137,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x") ? str : toHex(toInt(str), HexPrefix::Add); + _o[key] = (str.substr(0, 2) == "0x") ? str : toCompactHex(toInt(str), HexPrefix::Add); } return _o; } -- cgit v1.2.3 From 50644d2e1054c39f4abf5decf8a3cd8ad196fb06 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 27 Apr 2015 23:30:28 +0200 Subject: Tidy and conformalise the toHex API. --- TestHelper.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 57ec0566..eecf6f80 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -137,7 +137,7 @@ json_spirit::mObject& ImportTest::makeAllFieldsHex(json_spirit::mObject& _o) str = value.get_str(); else continue; - _o[key] = (str.substr(0, 2) == "0x") ? str : toCompactHex(toInt(str), HexPrefix::Add); + _o[key] = (str.substr(0, 2) == "0x") ? str : toCompactHex(toInt(str), HexPrefix::Add, 1); } return _o; } @@ -355,15 +355,15 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost) json_spirit::mObject fillJsonWithTransaction(Transaction _txn) { json_spirit::mObject txObject; - txObject["nonce"] = toCompactHex(_txn.nonce(), HexPrefix::Add); + txObject["nonce"] = toCompactHex(_txn.nonce(), HexPrefix::Add, 1); txObject["data"] = toHex(_txn.data(), 2, HexPrefix::Add); - txObject["gasLimit"] = toCompactHex(_txn.gas(), HexPrefix::Add); - txObject["gasPrice"] = toCompactHex(_txn.gasPrice(), HexPrefix::Add); - txObject["r"] = toCompactHex(_txn.signature().r, HexPrefix::Add); - txObject["s"] = toCompactHex(_txn.signature().s, HexPrefix::Add); - txObject["v"] = toCompactHex(_txn.signature().v + 27, HexPrefix::Add); + txObject["gasLimit"] = toCompactHex(_txn.gas(), HexPrefix::Add, 1); + txObject["gasPrice"] = toCompactHex(_txn.gasPrice(), HexPrefix::Add, 1); + txObject["r"] = toCompactHex(_txn.signature().r, HexPrefix::Add, 1); + txObject["s"] = toCompactHex(_txn.signature().s, HexPrefix::Add, 1); + txObject["v"] = toCompactHex(_txn.signature().v + 27, HexPrefix::Add, 1); txObject["to"] = _txn.isCreation() ? "" : toString(_txn.receiveAddress()); - txObject["value"] = toCompactHex(_txn.value(), HexPrefix::Add); + txObject["value"] = toCompactHex(_txn.value(), HexPrefix::Add, 1); return txObject; } @@ -373,12 +373,12 @@ json_spirit::mObject fillJsonWithState(State _state) for (auto const& a: _state.addresses()) { json_spirit::mObject o; - o["balance"] = toCompactHex(_state.balance(a.first), HexPrefix::Add); - o["nonce"] = toCompactHex(_state.transactionsFrom(a.first), HexPrefix::Add); + o["balance"] = toCompactHex(_state.balance(a.first), HexPrefix::Add, 1); + o["nonce"] = toCompactHex(_state.transactionsFrom(a.first), HexPrefix::Add, 1); { json_spirit::mObject store; for (auto const& s: _state.storage(a.first)) - store[toCompactHex(s.first, HexPrefix::Add)] = toCompactHex(s.second, HexPrefix::Add); + store[toCompactHex(s.first, HexPrefix::Add, 1)] = toCompactHex(s.second, HexPrefix::Add, 1); o["storage"] = store; } o["code"] = toHex(_state.code(a.first), 2, HexPrefix::Add); -- cgit v1.2.3 From d2457abb98cbb28037387cb31da8874834a59e4d Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 5 May 2015 16:46:01 +0300 Subject: Specifing concrete test when filling testsuite --- TestHelper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index eecf6f80..9e997c49 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -741,6 +741,12 @@ Options::Options() inputLimits = true; bigData = true; } + else if (arg.compare(0, 12, "--singletest") == 0) + { + singletest = true; + if (arg.size() > 12) + singletestName = arg.substr(13); // skip '=' char + } } } -- cgit v1.2.3 From ce40f285f301d70e125020b486b0e9ffdf82d349 Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 5 May 2015 18:15:26 +0300 Subject: Solidity: cryptographic ecrecover test --- TestHelper.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'TestHelper.cpp') diff --git a/TestHelper.cpp b/TestHelper.cpp index 9e997c49..144a1a28 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -715,11 +715,10 @@ Options::Options() vmtrace = true; else if (arg == "--filltests") fillTests = true; - else if (arg.compare(0, 7, "--stats") == 0) + else if (arg == "--stats" && i + 1 < argc) { stats = true; - if (arg.size() > 7) - statsOutFile = arg.substr(8); // skip '=' char + statsOutFile = argv[i + 1]; } else if (arg == "--performance") performance = true; @@ -741,11 +740,10 @@ Options::Options() inputLimits = true; bigData = true; } - else if (arg.compare(0, 12, "--singletest") == 0) + else if (arg == "--singletest" && i + 1 < argc) { - singletest = true; - if (arg.size() > 12) - singletestName = arg.substr(13); // skip '=' char + singleTest = true; + singleTestName = argv[i + 1]; } } } -- cgit v1.2.3