From f2f0aec91c6b66a8cd5fdc2dae78debd1f4b097a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 2 Apr 2015 15:10:35 +0200 Subject: [PATCH 1/6] Allowing abstract contracts constructor to have no args - If a constructor is part of an abstract contract we can omit its arguments - IF a contract is abstract make sure to not create and/or request Assembly code about it since it's not compiled --- SolidityNameAndTypeResolution.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index ffa78ed9e..caca8b04e 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -407,6 +407,20 @@ BOOST_AUTO_TEST_CASE(create_abstract_contract) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_optional) +{ + ASTPointer sourceUnit; + char const* text = R"( + contract BaseBase { function BaseBase(uint j); } + contract base is BaseBase { function foo(); } + contract derived is base { + function derived(uint i) BaseBase(i){} + function foo() {} + } + )"; + ETH_TEST_REQUIRE_NO_THROW(parseTextAndResolveNames(text), "Parsing and name resolving failed"); +} + BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract) { ASTPointer sourceUnit; @@ -665,7 +679,7 @@ BOOST_AUTO_TEST_CASE(missing_base_constructor_arguments) contract A { function A(uint a) { } } contract B is A { } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(base_constructor_arguments_override) @@ -674,7 +688,7 @@ BOOST_AUTO_TEST_CASE(base_constructor_arguments_override) contract A { function A(uint a) { } } contract B is A { } )"; - BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); + ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(text), "Parsing and Name Resolving Failed"); } BOOST_AUTO_TEST_CASE(implicit_derived_to_base_conversion) From a063e1c5a128cdd986c9a2f9000f4dc063f956dd Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 2 Apr 2015 16:56:12 +0200 Subject: [PATCH 2/6] Check all constructors in inheritance chain get args - Also add a missing override in a function of EnumValue --- SolidityNameAndTypeResolution.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/SolidityNameAndTypeResolution.cpp b/SolidityNameAndTypeResolution.cpp index caca8b04e..c1a274b0c 100644 --- a/SolidityNameAndTypeResolution.cpp +++ b/SolidityNameAndTypeResolution.cpp @@ -421,6 +421,25 @@ BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_optional) ETH_TEST_REQUIRE_NO_THROW(parseTextAndResolveNames(text), "Parsing and name resolving failed"); } +BOOST_AUTO_TEST_CASE(abstract_contract_constructor_args_not_provided) +{ + ASTPointer sourceUnit; + char const* text = R"( + contract BaseBase { function BaseBase(uint j); } + contract base is BaseBase { function foo(); } + contract derived is base { + function derived(uint i) {} + function foo() {} + } + )"; + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name resolving failed"); + std::vector> nodes = sourceUnit->getNodes(); + BOOST_CHECK_EQUAL(nodes.size(), 3); + ContractDefinition* derived = dynamic_cast(nodes[2].get()); + BOOST_CHECK(derived); + BOOST_CHECK(!derived->isFullyImplemented()); +} + BOOST_AUTO_TEST_CASE(redeclare_implemented_abstract_function_as_abstract) { ASTPointer sourceUnit; From 22d16c048bde69eb66d315990f2d407f7384cf4f Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 17 Apr 2015 18:41:27 +0200 Subject: [PATCH 3/6] 0x -> 0x0 for numbers --- TestHelper.cpp | 8 ++++---- blockchain.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 92a8258ac..49c6bb023 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)) diff --git a/blockchain.cpp b/blockchain.cpp index b144abe62..502182074 100644 --- a/blockchain.cpp +++ b/blockchain.cpp @@ -625,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"] = "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["difficulty"] = "0x" + (toHex(toCompactBigEndian(_bi.difficulty)).empty() ? "0" : toHex(toCompactBigEndian(_bi.difficulty))); + _o["number"] = "0x" + (toHex(toCompactBigEndian(_bi.number)).empty() ? "0" : toHex(toCompactBigEndian(_bi.number))); + _o["gasLimit"] = "0x" + (toHex(toCompactBigEndian(_bi.gasLimit)).empty() ? "0" : toHex(toCompactBigEndian(_bi.gasLimit))); + _o["gasUsed"] = "0x" + (toHex(toCompactBigEndian(_bi.gasUsed)).empty() ? "0" : toHex(toCompactBigEndian(_bi.gasUsed))); + _o["timestamp"] = "0x" + (toHex(toCompactBigEndian(_bi.timestamp)).empty() ? "0" : toHex(toCompactBigEndian(_bi.timestamp))); _o["extraData"] ="0x" + toHex(_bi.extraData); _o["mixHash"] = toString(_bi.mixHash); _o["nonce"] = toString(_bi.nonce); From d399f077eff87a2589188fe6353a42c7dd60597a Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Fri, 17 Apr 2015 22:44:26 +0200 Subject: [PATCH 4/6] simplification --- TestHelper.cpp | 6 +++--- blockchain.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index 49c6bb023..ed844e961 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)) diff --git a/blockchain.cpp b/blockchain.cpp index 502182074..ec8fb7539 100644 --- a/blockchain.cpp +++ b/blockchain.cpp @@ -625,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"] = "0x" + (toHex(toCompactBigEndian(_bi.difficulty)).empty() ? "0" : toHex(toCompactBigEndian(_bi.difficulty))); - _o["number"] = "0x" + (toHex(toCompactBigEndian(_bi.number)).empty() ? "0" : toHex(toCompactBigEndian(_bi.number))); - _o["gasLimit"] = "0x" + (toHex(toCompactBigEndian(_bi.gasLimit)).empty() ? "0" : toHex(toCompactBigEndian(_bi.gasLimit))); - _o["gasUsed"] = "0x" + (toHex(toCompactBigEndian(_bi.gasUsed)).empty() ? "0" : toHex(toCompactBigEndian(_bi.gasUsed))); - _o["timestamp"] = "0x" + (toHex(toCompactBigEndian(_bi.timestamp)).empty() ? "0" : toHex(toCompactBigEndian(_bi.timestamp))); + _o["difficulty"] = "0x" + toHex(toCompactBigEndian(_bi.difficulty), 1); + _o["number"] = "0x" + toHex(toCompactBigEndian(_bi.number), 1); + _o["gasLimit"] = "0x" + toHex(toCompactBigEndian(_bi.gasLimit), 1); + _o["gasUsed"] = "0x" + toHex(toCompactBigEndian(_bi.gasUsed), 1); + _o["timestamp"] = "0x" + toHex(toCompactBigEndian(_bi.timestamp), 1); _o["extraData"] ="0x" + toHex(_bi.extraData); _o["mixHash"] = toString(_bi.mixHash); _o["nonce"] = toString(_bi.nonce); From b6ff4451143db1f3cb5086d833d0022fc4f8c6b4 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 19 Apr 2015 17:31:56 +0200 Subject: [PATCH 5/6] Minor fix for integration tests. --- stateOriginal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stateOriginal.cpp b/stateOriginal.cpp index e1a3c7c4a..7f3371484 100644 --- a/stateOriginal.cpp +++ b/stateOriginal.cpp @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(Complex) CanonBlockChain bc; cout << bc; - State s(stateDB, BaseState::Empty, myMiner.address()); + State s(stateDB, BaseState::CanonGenesis, myMiner.address()); cout << s; // Sync up - this won't do much until we use the last state. @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(Complex) cout << s; // Inject a transaction to transfer funds from miner to me. - Transaction t(1000, 10000, 10000, me.address(), bytes(), s.transactionsFrom(myMiner.address()), myMiner.secret()); + Transaction t(1000, 10000, 100000, me.address(), bytes(), s.transactionsFrom(myMiner.address()), myMiner.secret()); assert(t.sender() == myMiner.address()); s.execute(bc.lastHashes(), t); From 71012a83e86dac3a899780219a78f18acd1708c5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 19 Apr 2015 22:59:57 +0200 Subject: [PATCH 6/6] Remote miner fixes. --- webthreestubclient.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webthreestubclient.h b/webthreestubclient.h index c1fdc3411..fd71bfb5d 100644 --- a/webthreestubclient.h +++ b/webthreestubclient.h @@ -434,11 +434,12 @@ class WebThreeStubClient : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_submitWork(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); + p.append(param3); Json::Value result = this->CallMethod("eth_submitWork",p); if (result.isBool()) return result.asBool();