From c5063d315583270e88a01a0a82a84a68190f6ba1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 1 Sep 2017 13:37:40 +0200 Subject: Use "tuple" for struct types in ABI JSON. Only use tuple as a type in the ABI (and remove all "anonymous struct" references too) --- test/libsolidity/SolidityABIJSON.cpp | 16 +++++------ test/libsolidity/SolidityNameAndTypeResolution.cpp | 31 +++++++++++++++++++--- 2 files changed, 36 insertions(+), 11 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index e4ab54ec..e5d9e99c 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -973,11 +973,11 @@ BOOST_AUTO_TEST_CASE(return_structs) } ], "name" : "sub", - "type" : "[]" + "type" : "tuple[]" } ], "name" : "s", - "type" : "" + "type" : "tuple" } ], "payable" : false, @@ -1015,7 +1015,7 @@ BOOST_AUTO_TEST_CASE(return_structs_with_contracts) } ], "name": "s", - "type": "" + "type": "tuple" }, { "name": "c", @@ -1052,7 +1052,7 @@ BOOST_AUTO_TEST_CASE(event_structs) ], "indexed": false, "name": "t", - "type": "" + "type": "tuple" }, { "components": [ @@ -1068,7 +1068,7 @@ BOOST_AUTO_TEST_CASE(event_structs) } ], "name": "sub", - "type": "[]" + "type": "tuple[]" }, { "name": "b", @@ -1077,7 +1077,7 @@ BOOST_AUTO_TEST_CASE(event_structs) ], "indexed": false, "name": "s", - "type": "" + "type": "tuple" } ], "name": "E", @@ -1115,7 +1115,7 @@ BOOST_AUTO_TEST_CASE(structs_in_libraries) } ], "name": "sub", - "type": "[]" + "type": "tuple[]" }, { "name": "b", @@ -1123,7 +1123,7 @@ BOOST_AUTO_TEST_CASE(structs_in_libraries) } ], "name": "s", - "type": "" + "type": "tuple" } ], "name": "g", diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 778c12c5..5ab824d3 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -601,7 +601,6 @@ BOOST_AUTO_TEST_CASE(enum_external_type) BOOST_AUTO_TEST_CASE(external_structs) { - ASTPointer sourceUnit; char const* text = R"( contract Test { enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } @@ -614,7 +613,7 @@ BOOST_AUTO_TEST_CASE(external_structs) function i(Nested[]) external {} } )"; - ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name Resolving failed"); + SourceUnit const* sourceUnit = parseAndAnalyse(text); for (ASTPointer const& node: sourceUnit->nodes()) if (ContractDefinition* contract = dynamic_cast(node.get())) { @@ -627,7 +626,33 @@ BOOST_AUTO_TEST_CASE(external_structs) } } -// TODO: Add a test that checks the signature of library functions taking structs +BOOST_AUTO_TEST_CASE(external_structs_in_libraries) +{ + char const* text = R"( + library Test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + struct Empty {} + struct Nested { X[2][] a; mapping(uint => uint) m; uint y; } + struct X { bytes32 x; Test t; Empty[] e; } + function f(ActionChoices, uint, Empty) external {} + function g(Test, Nested) external {} + function h(function(Nested) external returns (uint)[]) external {} + function i(Nested[]) external {} + } + )"; + SourceUnit const* sourceUnit = parseAndAnalyse(text); + for (ASTPointer const& node: sourceUnit->nodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + auto functions = contract->definedFunctions(); + BOOST_REQUIRE(!functions.empty()); + BOOST_CHECK_EQUAL("f(Test.ActionChoices,uint256,Test.Empty)", functions[0]->externalSignature()); + BOOST_CHECK_EQUAL("g(Test,Test.Nested)", functions[1]->externalSignature()); + BOOST_CHECK_EQUAL("h(function[])", functions[2]->externalSignature()); + BOOST_CHECK_EQUAL("i(Test.Nested[])", functions[3]->externalSignature()); + } +} + BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion) { -- cgit