Browse Source

bug in abi. fixed external type for return parameters

cl-refactor
Liana Husikyan 10 years ago
parent
commit
ef6c158805
  1. 10
      libsolidity/InterfaceHandler.cpp
  2. 48
      test/libsolidity/SolidityABIJSON.cpp
  3. 22
      test/libsolidity/SolidityNameAndTypeResolution.cpp

10
libsolidity/InterfaceHandler.cpp

@ -55,15 +55,15 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
for (auto it: _contractDef.getInterfaceFunctions()) for (auto it: _contractDef.getInterfaceFunctions())
{ {
auto externalFunctionType = it.second->externalFunctionType();
Json::Value method; Json::Value method;
method["type"] = "function"; method["type"] = "function";
method["name"] = it.second->getDeclaration().getName(); method["name"] = it.second->getDeclaration().getName();
method["constant"] = it.second->isConstant(); method["constant"] = it.second->isConstant();
method["inputs"] = populateParameters(it.second->getParameterNames(), method["inputs"] = populateParameters(externalFunctionType->getParameterNames(),
it.second->getParameterTypeNames()); externalFunctionType->getParameterTypeNames());
method["outputs"] = populateParameters(it.second->getReturnParameterNames(), method["outputs"] = populateParameters(externalFunctionType->getReturnParameterNames(),
it.second->getReturnParameterTypeNames()); externalFunctionType->getReturnParameterTypeNames());
abi.append(method); abi.append(method);
} }
if (_contractDef.getConstructor()) if (_contractDef.getConstructor())

48
test/libsolidity/SolidityABIJSON.cpp

@ -499,7 +499,8 @@ BOOST_AUTO_TEST_CASE(constructor_abi)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract test { 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", "name": "param3",
"type": "bool" "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" "type": "constructor"

22
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> 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<ASTNode> const& node: sourceUnit->getNodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(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) BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion)
{ {
char const* text = R"( char const* text = R"(

Loading…
Cancel
Save