2014-11-12 10:39:42 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2014-11-12 10:39:42 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2014-11-12 10:39:42 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2014-11-12 10:39:42 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2016-11-18 23:13:20 +00:00
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-12 10:39:42 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Marek Kotewicz <marek@ethdev.com>
|
|
|
|
* @date 2014
|
|
|
|
* Unit tests for the solidity compiler JSON Interface output.
|
|
|
|
*/
|
|
|
|
|
2015-04-20 20:48:53 +00:00
|
|
|
#include "../TestHelper.h"
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/interface/CompilerStack.h>
|
2016-11-24 09:55:32 +00:00
|
|
|
|
2014-12-02 09:41:18 +00:00
|
|
|
#include <libdevcore/Exceptions.h>
|
2016-11-24 09:55:32 +00:00
|
|
|
#include <libdevcore/SwarmHash.h>
|
|
|
|
|
|
|
|
#include <json/json.h>
|
2014-11-12 10:39:42 +00:00
|
|
|
|
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
|
|
|
namespace test
|
|
|
|
{
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
class JSONInterfaceChecker
|
2014-11-12 12:00:11 +00:00
|
|
|
{
|
2014-11-12 10:39:42 +00:00
|
|
|
public:
|
2016-08-15 14:58:01 +00:00
|
|
|
JSONInterfaceChecker(): m_compilerStack() {}
|
2015-01-28 12:39:04 +00:00
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
|
2014-11-12 10:39:42 +00:00
|
|
|
{
|
2017-07-18 13:34:22 +00:00
|
|
|
m_compilerStack.reset(false);
|
|
|
|
m_compilerStack.addSource("", "pragma solidity >=0.0;\n" + _code);
|
|
|
|
ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parseAndAnalyze(), "Parsing contract failed");
|
2016-11-15 17:37:18 +00:00
|
|
|
|
2017-05-06 17:02:56 +00:00
|
|
|
Json::Value generatedInterface = m_compilerStack.contractABI("");
|
2014-11-12 10:39:42 +00:00
|
|
|
Json::Value expectedInterface;
|
|
|
|
m_reader.parse(_expectedInterfaceString, expectedInterface);
|
2015-10-14 18:37:41 +00:00
|
|
|
BOOST_CHECK_MESSAGE(
|
|
|
|
expectedInterface == generatedInterface,
|
2016-11-15 17:37:18 +00:00
|
|
|
"Expected:\n" << expectedInterface.toStyledString() <<
|
|
|
|
"\n but got:\n" << generatedInterface.toStyledString()
|
2015-10-14 18:37:41 +00:00
|
|
|
);
|
2014-11-12 10:39:42 +00:00
|
|
|
}
|
2014-12-01 17:01:42 +00:00
|
|
|
|
2016-11-24 09:55:32 +00:00
|
|
|
protected:
|
2014-11-12 10:39:42 +00:00
|
|
|
CompilerStack m_compilerStack;
|
|
|
|
Json::Reader m_reader;
|
|
|
|
};
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(SolidityABIJSON, JSONInterfaceChecker)
|
2014-11-12 10:39:42 +00:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(basic_test)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f(uint a) returns(uint d) { return a * 7; }
|
|
|
|
}
|
|
|
|
)";
|
2014-11-12 10:39:42 +00:00
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "f",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-11-12 10:39:42 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])";
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2014-11-12 10:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(empty_contract)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test { }
|
|
|
|
)";
|
2014-11-12 10:39:42 +00:00
|
|
|
char const* interface = "[]";
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2014-11-12 10:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multiple_methods)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f(uint a) returns(uint d) { return a * 7; }
|
|
|
|
function g(uint b) returns(uint e) { return b * 8; }
|
|
|
|
}
|
|
|
|
)";
|
2014-12-01 17:01:42 +00:00
|
|
|
|
2014-11-12 10:39:42 +00:00
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "f",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-11-12 10:39:42 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "g",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-11-12 10:39:42 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "b",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "e",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])";
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2014-11-12 10:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multiple_params)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f(uint a, uint b) returns(uint d) { return a + b; }
|
|
|
|
}
|
|
|
|
)";
|
2014-11-12 10:39:42 +00:00
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "f",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-11-12 10:39:42 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "b",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])";
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2014-11-12 10:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
|
|
|
{
|
|
|
|
// methods are expected to be in alpabetical order
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f(uint a) returns(uint d) { return a * 7; }
|
|
|
|
function c(uint b) returns(uint e) { return b * 8; }
|
|
|
|
}
|
|
|
|
)";
|
2014-12-01 17:01:42 +00:00
|
|
|
|
2014-11-12 10:39:42 +00:00
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "c",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-11-12 10:39:42 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "b",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "e",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "f",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-11-12 10:39:42 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])";
|
2014-12-01 17:01:42 +00:00
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2014-11-12 10:39:42 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 09:48:59 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(const_function)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function foo(uint a, uint b) returns(uint d) { return a + b; }
|
|
|
|
function boo(uint32 a) constant returns(uint b) { return a * 4; }
|
|
|
|
}
|
|
|
|
)";
|
2014-12-19 09:48:59 +00:00
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "foo",
|
2014-12-21 15:28:46 +00:00
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2014-12-19 09:48:59 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "b",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
2015-01-09 08:29:19 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "boo",
|
|
|
|
"constant": true,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "view",
|
2015-01-31 00:28:43 +00:00
|
|
|
"type": "function",
|
2015-01-09 08:29:19 +00:00
|
|
|
"inputs": [{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint32"
|
|
|
|
}],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "b",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
2014-12-19 09:48:59 +00:00
|
|
|
}
|
|
|
|
])";
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2014-12-19 09:48:59 +00:00
|
|
|
}
|
|
|
|
|
2015-01-31 13:41:11 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(events)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f(uint a) returns(uint d) { return a * 7; }
|
|
|
|
event e1(uint b, address indexed c);
|
|
|
|
event e2();
|
|
|
|
}
|
|
|
|
)";
|
2015-01-31 13:41:11 +00:00
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "f",
|
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 13:41:11 +00:00
|
|
|
"type": "function",
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "a",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "d",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "e1",
|
|
|
|
"type": "event",
|
2015-03-17 10:34:56 +00:00
|
|
|
"anonymous": false,
|
2015-01-31 13:41:11 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"indexed": false,
|
|
|
|
"name": "b",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"indexed": true,
|
|
|
|
"name": "c",
|
|
|
|
"type": "address"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "e2",
|
|
|
|
"type": "event",
|
2015-03-17 10:34:56 +00:00
|
|
|
"anonymous": false,
|
2015-01-31 13:41:11 +00:00
|
|
|
"inputs": []
|
|
|
|
}
|
|
|
|
|
|
|
|
])";
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2015-01-31 13:41:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 10:34:56 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(events_anonymous)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
event e() anonymous;
|
|
|
|
}
|
|
|
|
)";
|
2015-03-17 10:34:56 +00:00
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "e",
|
|
|
|
"type": "event",
|
|
|
|
"anonymous": true,
|
|
|
|
"inputs": []
|
|
|
|
}
|
|
|
|
|
|
|
|
])";
|
|
|
|
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
2015-01-31 13:41:11 +00:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(inherited)
|
|
|
|
{
|
2016-12-03 20:52:51 +00:00
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract Base {
|
|
|
|
function baseFunction(uint p) returns (uint i) { return p; }
|
|
|
|
event baseEvent(bytes32 indexed evtArgBase);
|
|
|
|
}
|
|
|
|
contract Derived is Base {
|
|
|
|
function derivedFunction(bytes32 p) returns (bytes32 i) { return p; }
|
|
|
|
event derivedEvent(uint indexed evtArgDerived);
|
|
|
|
}
|
|
|
|
)";
|
2015-01-31 13:41:11 +00:00
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "baseFunction",
|
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 13:41:11 +00:00
|
|
|
"type": "function",
|
|
|
|
"inputs":
|
|
|
|
[{
|
|
|
|
"name": "p",
|
|
|
|
"type": "uint256"
|
|
|
|
}],
|
|
|
|
"outputs":
|
|
|
|
[{
|
|
|
|
"name": "i",
|
|
|
|
"type": "uint256"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "derivedFunction",
|
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-01-31 13:41:11 +00:00
|
|
|
"type": "function",
|
|
|
|
"inputs":
|
|
|
|
[{
|
|
|
|
"name": "p",
|
2015-03-11 10:38:11 +00:00
|
|
|
"type": "bytes32"
|
2015-01-31 13:41:11 +00:00
|
|
|
}],
|
|
|
|
"outputs":
|
|
|
|
[{
|
|
|
|
"name": "i",
|
2015-03-11 10:38:11 +00:00
|
|
|
"type": "bytes32"
|
2015-01-31 13:41:11 +00:00
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "derivedEvent",
|
|
|
|
"type": "event",
|
2015-03-17 10:34:56 +00:00
|
|
|
"anonymous": false,
|
2015-01-31 13:41:11 +00:00
|
|
|
"inputs":
|
|
|
|
[{
|
|
|
|
"indexed": true,
|
|
|
|
"name": "evtArgDerived",
|
|
|
|
"type": "uint256"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "baseEvent",
|
|
|
|
"type": "event",
|
2015-03-17 10:34:56 +00:00
|
|
|
"anonymous": false,
|
2015-01-31 13:41:11 +00:00
|
|
|
"inputs":
|
|
|
|
[{
|
|
|
|
"indexed": true,
|
|
|
|
"name": "evtArgBase",
|
2015-03-11 10:38:11 +00:00
|
|
|
"type": "bytes32"
|
2015-01-31 13:41:11 +00:00
|
|
|
}]
|
|
|
|
}])";
|
|
|
|
|
|
|
|
|
2015-01-31 23:46:38 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
2015-01-29 21:50:20 +00:00
|
|
|
}
|
2015-02-09 01:06:30 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
2016-12-03 20:52:51 +00:00
|
|
|
contract test {
|
|
|
|
function f(uint, uint k) returns(uint ret_k, uint ret_g) {
|
|
|
|
uint g = 8;
|
|
|
|
ret_k = k;
|
|
|
|
ret_g = g;
|
|
|
|
}
|
2015-02-09 01:06:30 +00:00
|
|
|
}
|
2016-12-03 20:52:51 +00:00
|
|
|
)";
|
2015-02-09 01:06:30 +00:00
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "f",
|
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-02-09 01:06:30 +00:00
|
|
|
"type": "function",
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "k",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "ret_k",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "ret_g",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])";
|
2015-01-29 21:50:20 +00:00
|
|
|
|
2015-02-09 01:06:30 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
2016-12-03 20:52:51 +00:00
|
|
|
function f(uint k) returns(uint) {
|
|
|
|
return k;
|
|
|
|
}
|
2015-02-09 01:06:30 +00:00
|
|
|
}
|
2016-12-03 20:52:51 +00:00
|
|
|
)";
|
2015-02-09 01:06:30 +00:00
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"name": "f",
|
|
|
|
"constant": false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-02-09 01:06:30 +00:00
|
|
|
"type": "function",
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "k",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "",
|
|
|
|
"type": "uint256"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
])";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
2015-01-31 13:41:11 +00:00
|
|
|
|
2015-04-16 13:19:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(constructor_abi)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
2015-05-11 14:24:04 +00:00
|
|
|
function test(uint param1, test param2, bool param3) {}
|
2015-04-16 13:19:25 +00:00
|
|
|
}
|
2015-04-22 16:53:58 +00:00
|
|
|
)";
|
2015-04-16 13:19:25 +00:00
|
|
|
|
2015-04-17 13:26:12 +00:00
|
|
|
char const* interface = R"([
|
|
|
|
{
|
2015-04-22 16:53:58 +00:00
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "param1",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "param2",
|
|
|
|
"type": "address"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "param3",
|
|
|
|
"type": "bool"
|
2015-05-11 11:47:21 +00:00
|
|
|
}
|
|
|
|
],
|
2016-11-15 18:41:54 +00:00
|
|
|
"payable": false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-05-11 11:47:21 +00:00
|
|
|
"type": "constructor"
|
|
|
|
}
|
|
|
|
])";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2017-08-15 00:40:53 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(payable_constructor_abi)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function test(uint param1, test param2, bool param3) payable {}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"([
|
|
|
|
{
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "param1",
|
|
|
|
"type": "uint256"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "param2",
|
|
|
|
"type": "address"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "param3",
|
|
|
|
"type": "bool"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"payable": true,
|
|
|
|
"statemutability": "payable",
|
|
|
|
"type": "constructor"
|
|
|
|
}
|
|
|
|
])";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
2015-05-11 11:47:21 +00:00
|
|
|
|
|
|
|
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) {}
|
2016-12-03 20:52:51 +00:00
|
|
|
function ret() returns(ActionChoices) {
|
2015-05-11 11:47:21 +00:00
|
|
|
ActionChoices action = ActionChoices.GoLeft;
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2015-05-11 14:24:04 +00:00
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"constant" : false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-05-11 14:24:04 +00:00
|
|
|
"inputs" : [],
|
|
|
|
"name" : "ret",
|
2015-05-11 15:17:50 +00:00
|
|
|
"outputs" : [
|
2015-05-11 14:24:04 +00:00
|
|
|
{
|
|
|
|
"name" : "",
|
|
|
|
"type" : "uint8"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"type" : "function"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"inputs": [
|
|
|
|
{
|
|
|
|
"name": "param",
|
|
|
|
"type": "uint8"
|
|
|
|
}
|
|
|
|
],
|
2016-11-15 18:41:54 +00:00
|
|
|
"payable": false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-05-11 14:24:04 +00:00
|
|
|
"type": "constructor"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
2015-04-16 13:19:25 +00:00
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2015-05-28 14:20:50 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(strings_and_arrays)
|
|
|
|
{
|
|
|
|
// bug #1801
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f(string a, bytes b, uint[] c) external {}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"constant" : false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-05-28 14:20:50 +00:00
|
|
|
"name": "f",
|
|
|
|
"inputs": [
|
|
|
|
{ "name": "a", "type": "string" },
|
|
|
|
{ "name": "b", "type": "bytes" },
|
|
|
|
{ "name": "c", "type": "uint256[]" }
|
|
|
|
],
|
|
|
|
"outputs": [],
|
|
|
|
"type" : "function"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2015-10-05 15:19:23 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(library_function)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
library test {
|
|
|
|
struct StructType { uint a; }
|
2016-12-03 20:52:51 +00:00
|
|
|
function f(StructType storage b, uint[] storage c, test d) returns (uint[] e, StructType storage f) {}
|
2015-10-05 15:19:23 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"constant" : false,
|
2016-08-02 19:22:26 +00:00
|
|
|
"payable" : false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2015-10-05 15:19:23 +00:00
|
|
|
"name": "f",
|
|
|
|
"inputs": [
|
|
|
|
{ "name": "b", "type": "test.StructType storage" },
|
|
|
|
{ "name": "c", "type": "uint256[] storage" },
|
|
|
|
{ "name": "d", "type": "test" }
|
|
|
|
],
|
|
|
|
"outputs": [
|
|
|
|
{ "name": "e", "type": "uint256[]" },
|
|
|
|
{ "name": "f", "type": "test.StructType storage" }
|
|
|
|
],
|
|
|
|
"type" : "function"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2016-07-25 10:09:07 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(include_fallback_function)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function() {}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
2016-09-06 08:59:13 +00:00
|
|
|
"payable": false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2016-07-25 10:09:07 +00:00
|
|
|
"type" : "fallback"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2016-08-02 19:22:26 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(payable_function)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function f() {}
|
|
|
|
function g() payable {}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"constant" : false,
|
|
|
|
"payable": false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2016-08-02 19:22:26 +00:00
|
|
|
"inputs": [],
|
|
|
|
"name": "f",
|
|
|
|
"outputs": [],
|
|
|
|
"type" : "function"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"constant" : false,
|
|
|
|
"payable": true,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "payable",
|
2016-08-02 19:22:26 +00:00
|
|
|
"inputs": [],
|
|
|
|
"name": "g",
|
|
|
|
"outputs": [],
|
|
|
|
"type" : "function"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:51:48 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(payable_fallback_function)
|
2016-09-06 08:59:13 +00:00
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
|
|
|
function () payable {}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"payable": true,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "payable",
|
2016-09-06 08:59:13 +00:00
|
|
|
"type" : "fallback"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
2016-08-02 19:22:26 +00:00
|
|
|
|
2016-11-14 22:37:19 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(function_type)
|
|
|
|
{
|
|
|
|
char const* sourceCode = R"(
|
|
|
|
contract test {
|
2016-11-14 22:52:07 +00:00
|
|
|
function g(function(uint) external returns (uint) x) {}
|
2016-11-14 22:37:19 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
char const* interface = R"(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"constant" : false,
|
2016-11-14 22:52:07 +00:00
|
|
|
"payable": false,
|
2017-07-17 09:38:29 +00:00
|
|
|
"statemutability": "nonpayable",
|
2016-11-14 22:52:07 +00:00
|
|
|
"inputs": [{
|
|
|
|
"name": "x",
|
|
|
|
"type": "function"
|
|
|
|
}],
|
2016-11-14 22:37:19 +00:00
|
|
|
"name": "g",
|
|
|
|
"outputs": [],
|
|
|
|
"type" : "function"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)";
|
|
|
|
checkInterface(sourceCode, interface);
|
|
|
|
}
|
|
|
|
|
2014-11-12 10:39:42 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|