mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #913 from arkpar/sol_abi_fix
Fixed json ABI generation for events
This commit is contained in:
commit
69fa5db471
@ -37,7 +37,7 @@ class InterfaceChecker
|
|||||||
public:
|
public:
|
||||||
InterfaceChecker(): m_compilerStack(false) {}
|
InterfaceChecker(): m_compilerStack(false) {}
|
||||||
|
|
||||||
void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString)
|
void checkInterface(std::string const& _code, std::string const& _expectedInterfaceString, std::string const& expectedSolidityInterface)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -49,13 +49,17 @@ public:
|
|||||||
BOOST_FAIL(msg);
|
BOOST_FAIL(msg);
|
||||||
}
|
}
|
||||||
std::string generatedInterfaceString = m_compilerStack.getMetadata("", DocumentationType::ABI_INTERFACE);
|
std::string generatedInterfaceString = m_compilerStack.getMetadata("", DocumentationType::ABI_INTERFACE);
|
||||||
|
std::string generatedSolidityInterfaceString = m_compilerStack.getMetadata("", DocumentationType::ABI_SOLIDITY_INTERFACE);
|
||||||
Json::Value generatedInterface;
|
Json::Value generatedInterface;
|
||||||
m_reader.parse(generatedInterfaceString, generatedInterface);
|
m_reader.parse(generatedInterfaceString, generatedInterface);
|
||||||
Json::Value expectedInterface;
|
Json::Value expectedInterface;
|
||||||
m_reader.parse(_expectedInterfaceString, expectedInterface);
|
m_reader.parse(_expectedInterfaceString, expectedInterface);
|
||||||
BOOST_CHECK_MESSAGE(expectedInterface == generatedInterface,
|
BOOST_CHECK_MESSAGE(expectedInterface == generatedInterface,
|
||||||
"Expected " << _expectedInterfaceString <<
|
"Expected:\n" << expectedInterface.toStyledString() <<
|
||||||
"\n but got:\n" << generatedInterfaceString);
|
"\n but got:\n" << generatedInterface.toStyledString());
|
||||||
|
BOOST_CHECK_MESSAGE(expectedSolidityInterface == generatedSolidityInterfaceString,
|
||||||
|
"Expected:\n" << expectedSolidityInterface <<
|
||||||
|
"\n but got:\n" << generatedSolidityInterfaceString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -71,6 +75,8 @@ BOOST_AUTO_TEST_CASE(basic_test)
|
|||||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
char const* sourceInterface = "contract test{function f(uint256 a)returns(uint256 d){}}";
|
||||||
|
|
||||||
char const* interface = R"([
|
char const* interface = R"([
|
||||||
{
|
{
|
||||||
"name": "f",
|
"name": "f",
|
||||||
@ -91,17 +97,18 @@ BOOST_AUTO_TEST_CASE(basic_test)
|
|||||||
}
|
}
|
||||||
])";
|
])";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(empty_contract)
|
BOOST_AUTO_TEST_CASE(empty_contract)
|
||||||
{
|
{
|
||||||
char const* sourceCode = "contract test {\n"
|
char const* sourceCode = "contract test {\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
char const* sourceInterface = "contract test{}";
|
||||||
|
|
||||||
char const* interface = "[]";
|
char const* interface = "[]";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multiple_methods)
|
BOOST_AUTO_TEST_CASE(multiple_methods)
|
||||||
@ -110,6 +117,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
|
|||||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||||
" function g(uint b) returns(uint e) { return b * 8; }\n"
|
" function g(uint b) returns(uint e) { return b * 8; }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
char const* sourceInterface = "contract test{function f(uint256 a)returns(uint256 d){}function g(uint256 b)returns(uint256 e){}}";
|
||||||
|
|
||||||
char const* interface = R"([
|
char const* interface = R"([
|
||||||
{
|
{
|
||||||
@ -148,7 +156,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
|
|||||||
}
|
}
|
||||||
])";
|
])";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multiple_params)
|
BOOST_AUTO_TEST_CASE(multiple_params)
|
||||||
@ -156,6 +164,7 @@ BOOST_AUTO_TEST_CASE(multiple_params)
|
|||||||
char const* sourceCode = "contract test {\n"
|
char const* sourceCode = "contract test {\n"
|
||||||
" function f(uint a, uint b) returns(uint d) { return a + b; }\n"
|
" function f(uint a, uint b) returns(uint d) { return a + b; }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
char const* sourceInterface = "contract test{function f(uint256 a,uint256 b)returns(uint256 d){}}";
|
||||||
|
|
||||||
char const* interface = R"([
|
char const* interface = R"([
|
||||||
{
|
{
|
||||||
@ -181,7 +190,7 @@ BOOST_AUTO_TEST_CASE(multiple_params)
|
|||||||
}
|
}
|
||||||
])";
|
])";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
||||||
@ -191,6 +200,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
|||||||
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||||
" function c(uint b) returns(uint e) { return b * 8; }\n"
|
" function c(uint b) returns(uint e) { return b * 8; }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
char const* sourceInterface = "contract test{function c(uint256 b)returns(uint256 e){}function f(uint256 a)returns(uint256 d){}}";
|
||||||
|
|
||||||
char const* interface = R"([
|
char const* interface = R"([
|
||||||
{
|
{
|
||||||
@ -229,7 +239,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
|||||||
}
|
}
|
||||||
])";
|
])";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(const_function)
|
BOOST_AUTO_TEST_CASE(const_function)
|
||||||
@ -238,6 +248,7 @@ BOOST_AUTO_TEST_CASE(const_function)
|
|||||||
" function foo(uint a, uint b) returns(uint d) { return a + b; }\n"
|
" function foo(uint a, uint b) returns(uint d) { return a + b; }\n"
|
||||||
" function boo(uint32 a) constant returns(uint b) { return a * 4; }\n"
|
" function boo(uint32 a) constant returns(uint b) { return a * 4; }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
char const* sourceInterface = "contract test{function foo(uint256 a,uint256 b)returns(uint256 d){}function boo(uint32 a)constant returns(uint256 b){}}";
|
||||||
|
|
||||||
char const* interface = R"([
|
char const* interface = R"([
|
||||||
{
|
{
|
||||||
@ -278,18 +289,144 @@ BOOST_AUTO_TEST_CASE(const_function)
|
|||||||
}
|
}
|
||||||
])";
|
])";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(exclude_fallback_function)
|
BOOST_AUTO_TEST_CASE(exclude_fallback_function)
|
||||||
{
|
{
|
||||||
char const* sourceCode = "contract test { function() {} }";
|
char const* sourceCode = "contract test { function() {} }";
|
||||||
|
char const* sourceInterface = "contract test{}";
|
||||||
|
|
||||||
char const* interface = "[]";
|
char const* interface = "[]";
|
||||||
|
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(events)
|
||||||
|
{
|
||||||
|
char const* sourceCode = "contract test {\n"
|
||||||
|
" function f(uint a) returns(uint d) { return a * 7; }\n"
|
||||||
|
" event e1(uint b, address indexed c); \n"
|
||||||
|
" event e2(); \n"
|
||||||
|
"}\n";
|
||||||
|
char const* sourceInterface = "contract test{function f(uint256 a)returns(uint256 d){}event e1(uint256 b,address indexed c);event e2;}";
|
||||||
|
|
||||||
|
char const* interface = R"([
|
||||||
|
{
|
||||||
|
"name": "f",
|
||||||
|
"constant": false,
|
||||||
|
"type": "function",
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"name": "a",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "d",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "e1",
|
||||||
|
"type": "event",
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": false,
|
||||||
|
"name": "b",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "c",
|
||||||
|
"type": "address"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "e2",
|
||||||
|
"type": "event",
|
||||||
|
"inputs": []
|
||||||
|
}
|
||||||
|
|
||||||
|
])";
|
||||||
|
|
||||||
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(inherited)
|
||||||
|
{
|
||||||
|
char const* sourceCode =
|
||||||
|
" contract Base { \n"
|
||||||
|
" function baseFunction(uint p) returns (uint i) { return p; } \n"
|
||||||
|
" event baseEvent(string32 indexed evtArgBase); \n"
|
||||||
|
" } \n"
|
||||||
|
" contract Derived is Base { \n"
|
||||||
|
" function derivedFunction(string32 p) returns (string32 i) { return p; } \n"
|
||||||
|
" event derivedEvent(uint indexed evtArgDerived); \n"
|
||||||
|
" }";
|
||||||
|
char const* sourceInterface = "contract Derived{function baseFunction(uint256 p)returns(uint256 i){}function derivedFunction(string32 p)returns(string32 i){}event derivedEvent(uint256 indexed evtArgDerived);event baseEvent(string32 indexed evtArgBase);}";
|
||||||
|
|
||||||
|
char const* interface = R"([
|
||||||
|
{
|
||||||
|
"name": "baseFunction",
|
||||||
|
"constant": false,
|
||||||
|
"type": "function",
|
||||||
|
"inputs":
|
||||||
|
[{
|
||||||
|
"name": "p",
|
||||||
|
"type": "uint256"
|
||||||
|
}],
|
||||||
|
"outputs":
|
||||||
|
[{
|
||||||
|
"name": "i",
|
||||||
|
"type": "uint256"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "derivedFunction",
|
||||||
|
"constant": false,
|
||||||
|
"type": "function",
|
||||||
|
"inputs":
|
||||||
|
[{
|
||||||
|
"name": "p",
|
||||||
|
"type": "string32"
|
||||||
|
}],
|
||||||
|
"outputs":
|
||||||
|
[{
|
||||||
|
"name": "i",
|
||||||
|
"type": "string32"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "derivedEvent",
|
||||||
|
"type": "event",
|
||||||
|
"inputs":
|
||||||
|
[{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "evtArgDerived",
|
||||||
|
"type": "uint256"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "baseEvent",
|
||||||
|
"type": "event",
|
||||||
|
"inputs":
|
||||||
|
[{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "evtArgBase",
|
||||||
|
"type": "string32"
|
||||||
|
}]
|
||||||
|
}])";
|
||||||
|
|
||||||
|
|
||||||
|
checkInterface(sourceCode, interface, sourceInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user