From ef6c1588059900fb536948ff6a8276610e7b39b3 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 13:47:21 +0200 Subject: [PATCH 1/3] bug in abi. fixed external type for return parameters --- libsolidity/InterfaceHandler.cpp | 10 ++-- test/libsolidity/SolidityABIJSON.cpp | 48 ++++++++++++++++++- .../SolidityNameAndTypeResolution.cpp | 22 +++++++++ 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index d4958475b..e266f8d61 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -55,15 +55,15 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio for (auto it: _contractDef.getInterfaceFunctions()) { - + auto externalFunctionType = it.second->externalFunctionType(); Json::Value method; method["type"] = "function"; method["name"] = it.second->getDeclaration().getName(); method["constant"] = it.second->isConstant(); - method["inputs"] = populateParameters(it.second->getParameterNames(), - it.second->getParameterTypeNames()); - method["outputs"] = populateParameters(it.second->getReturnParameterNames(), - it.second->getReturnParameterTypeNames()); + method["inputs"] = populateParameters(externalFunctionType->getParameterNames(), + externalFunctionType->getParameterTypeNames()); + method["outputs"] = populateParameters(externalFunctionType->getReturnParameterNames(), + externalFunctionType->getReturnParameterTypeNames()); abi.append(method); } if (_contractDef.getConstructor()) diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 26d0110b8..6c1025d6a 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -499,7 +499,8 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { char const* sourceCode = R"( contract test { - function test(uint param1, test param2, bool param3) {} + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function test(uint param1, test param2, bool param3, ActionChoices param4) {} } )"; @@ -517,6 +518,51 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { "name": "param3", "type": "bool" + }, + { + "name": "param4", + "type": "uint8" + } + ], + "type": "constructor" + } + ])"; + checkInterface(sourceCode, interface); +} + + +BOOST_AUTO_TEST_CASE(return_param_in_abi) +{ + // bug #1801 + char const* sourceCode = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function test(ActionChoices param) {} + function ret() returns(ActionChoices){ + ActionChoices action = ActionChoices.GoLeft; + return action; + } + } + )"; + + char const* interface = R"([ + { + "constant" : false, + "inputs" : [], + "name" : "ret", + "outputs" : [ + { + "name" : "", + "type" : "uint8" + } + ], + "type" : "function" + }, + { + "inputs": [ + { + "name": "param", + "type": "uint8" } ], "type": "constructor" diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index c317dad97..c59c1f56f 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -508,6 +508,28 @@ BOOST_AUTO_TEST_CASE(function_external_types) } } +BOOST_AUTO_TEST_CASE(enum_external_type) +{ + // bug #1801 + ASTPointer sourceUnit; + char const* text = R"( + contract Test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function boo(ActionChoices enumArg) external returns (uint ret) { + ret = 5; + } + })"; + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed"); + for (ASTPointer const& node: sourceUnit->getNodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + auto functions = contract->getDefinedFunctions(); + if (functions.empty()) + continue; + BOOST_CHECK_EQUAL("boo(uint8)", functions[0]->externalSignature()); + } +} + BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion) { char const* text = R"( From 6cc7bb915a217d359c2091fb8875880071371a37 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 16:24:04 +0200 Subject: [PATCH 2/3] updated unit test --- libsolidity/InterfaceHandler.cpp | 12 ++-- test/libsolidity/SolidityABIJSON.cpp | 55 +++++++++---------- .../SolidityNameAndTypeResolution.cpp | 2 +- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index e266f8d61..a49c4dc3f 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -60,10 +60,14 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio method["type"] = "function"; method["name"] = it.second->getDeclaration().getName(); method["constant"] = it.second->isConstant(); - method["inputs"] = populateParameters(externalFunctionType->getParameterNames(), - externalFunctionType->getParameterTypeNames()); - method["outputs"] = populateParameters(externalFunctionType->getReturnParameterNames(), - externalFunctionType->getReturnParameterTypeNames()); + method["inputs"] = populateParameters( + externalFunctionType->getParameterNames(), + externalFunctionType->getParameterTypeNames() + ); + method["outputs"] = populateParameters( + externalFunctionType->getReturnParameterNames(), + externalFunctionType->getReturnParameterTypeNames() + ); abi.append(method); } if (_contractDef.getConstructor()) diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 6c1025d6a..fe8b791c5 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -499,8 +499,7 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { char const* sourceCode = R"( contract test { - enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } - function test(uint param1, test param2, bool param3, ActionChoices param4) {} + function test(uint param1, test param2, bool param3) {} } )"; @@ -518,10 +517,6 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { "name": "param3", "type": "bool" - }, - { - "name": "param4", - "type": "uint8" } ], "type": "constructor" @@ -545,29 +540,31 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi) } )"; - char const* interface = R"([ - { - "constant" : false, - "inputs" : [], - "name" : "ret", - "outputs" : [ - { - "name" : "", - "type" : "uint8" - } - ], - "type" : "function" - }, - { - "inputs": [ - { - "name": "param", - "type": "uint8" - } - ], - "type": "constructor" - } - ])"; + char const* interface = R"( + [ + { + "constant" : false, + "inputs" : [], + "name" : "ret", + "outputs" : [ + { + "name" : "", + "type" : "uint8" + } + ], + "type" : "function" + }, + { + "inputs": [ + { + "name": "param", + "type": "uint8" + } + ], + "type": "constructor" + } + ] + )"; checkInterface(sourceCode, interface); } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index c59c1f56f..4ec7b8bda 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -516,7 +516,7 @@ BOOST_AUTO_TEST_CASE(enum_external_type) contract Test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } function boo(ActionChoices enumArg) external returns (uint ret) { - ret = 5; + ret = 5; } })"; ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseTextAndResolveNames(text), "Parsing and name Resolving failed"); From d3e0b74f0c605a940ebb3bdc5542f9558c090850 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 17:17:50 +0200 Subject: [PATCH 3/3] Update SolidityABIJSON.cpp --- test/libsolidity/SolidityABIJSON.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index fe8b791c5..f9bf78d0a 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -546,7 +546,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi) "constant" : false, "inputs" : [], "name" : "ret", - "outputs" : [ + "outputs" : [ { "name" : "", "type" : "uint8"