Browse Source

Adding const attribute to ABI output

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
29261206b9
  1. 1
      libsolidity/InterfaceHandler.cpp
  2. 53
      test/SolidityABIJSON.cpp

1
libsolidity/InterfaceHandler.cpp

@ -56,6 +56,7 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
};
method["name"] = f->getName();
method["const"] = f->isDeclaredConst();
method["inputs"] = populateParameters(f->getParameters());
method["outputs"] = populateParameters(f->getReturnParameters());
methods.append(method);

53
test/SolidityABIJSON.cpp

@ -76,6 +76,7 @@ BOOST_AUTO_TEST_CASE(basic_test)
char const* interface = R"([
{
"name": "f",
"const": false,
"inputs": [
{
"name": "a",
@ -114,6 +115,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
char const* interface = R"([
{
"name": "f",
"const": false,
"inputs": [
{
"name": "a",
@ -129,6 +131,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
},
{
"name": "g",
"const": false,
"inputs": [
{
"name": "b",
@ -156,6 +159,7 @@ BOOST_AUTO_TEST_CASE(multiple_params)
char const* interface = R"([
{
"name": "f",
"const": false,
"inputs": [
{
"name": "a",
@ -189,6 +193,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
char const* interface = R"([
{
"name": "c",
"const": false,
"inputs": [
{
"name": "b",
@ -204,6 +209,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
},
{
"name": "f",
"const": false,
"inputs": [
{
"name": "a",
@ -222,6 +228,53 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
checkInterface(sourceCode, interface);
}
BOOST_AUTO_TEST_CASE(const_function)
{
char const* sourceCode = "contract test {\n"
" function foo(uint a, uint b) returns(uint d) { return a + b; }\n"
" function boo(uint32 a) const returns(uint b) { return a * 4; }\n"
"}\n";
char const* interface = R"([
{
"name": "boo",
"const": true,
"inputs": [{
"name": "a",
"type": "uint32"
}],
"outputs": [
{
"name": "b",
"type": "uint256"
}
]
},
{
"name": "foo",
"const": false,
"inputs": [
{
"name": "a",
"type": "uint256"
},
{
"name": "b",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
}
])";
checkInterface(sourceCode, interface);
}
BOOST_AUTO_TEST_SUITE_END()
}

Loading…
Cancel
Save