From ccc3d56542d76ce19ce994716e8d7afc339e7472 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 11 May 2015 13:47:21 +0200 Subject: bug in abi. fixed external type for return parameters --- libsolidity/SolidityABIJSON.cpp | 48 ++++++++++++++++++++++++++- libsolidity/SolidityNameAndTypeResolution.cpp | 22 ++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) (limited to 'libsolidity') diff --git a/libsolidity/SolidityABIJSON.cpp b/libsolidity/SolidityABIJSON.cpp index 26d0110b..6c1025d6 100644 --- a/libsolidity/SolidityABIJSON.cpp +++ b/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/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index c317dad9..c59c1f56 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/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"( -- cgit