From 823e67bf4014d20c6c83d509264e1464d9578f99 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 9 Jun 2017 18:28:13 +0200 Subject: Tests for external signatures. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 3cea8d60..9dfbea21 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -601,12 +601,36 @@ BOOST_AUTO_TEST_CASE(enum_external_type) BOOST_AUTO_TEST_CASE(external_structs) { - BOOST_FAIL("This should test external structs"); - // More test ideas: - // external function type as part of a struct and array - // external function type taking structs and arrays... + ASTPointer sourceUnit; + char const* text = R"( + contract 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(Nested) external {} + function h(function(Nested) external returns (uint)[]) external {} + function i(Nested[]) external {} + } + )"; + ETH_TEST_REQUIRE_NO_THROW(sourceUnit = parseAndAnalyse(text), "Parsing and name Resolving failed"); + for (ASTPointer const& node: sourceUnit->nodes()) + if (ContractDefinition* contract = dynamic_cast(node.get())) + { + auto functions = contract->definedFunctions(); + BOOST_REQUIRE(!functions.empty()); + for (auto const& f: functions) + cout << f->externalSignature() << endl; + BOOST_CHECK_EQUAL("f(uint8,uint256,())", functions[0]->externalSignature()); + BOOST_CHECK_EQUAL("g(((bytes32,address,()[])[2][],uint256))", functions[1]->externalSignature()); + BOOST_CHECK_EQUAL("h(function[])", functions[2]->externalSignature()); + BOOST_CHECK_EQUAL("i(((bytes32,address,()[])[2][],uint256)[])", functions[3]->externalSignature()); + } } +// TODO: Add a test that checks the signature of library functions taking structs + BOOST_AUTO_TEST_CASE(function_external_call_allowed_conversion) { char const* text = R"( -- cgit