From 6d4628ace4082a4318dc61fff49e8d193eea36e9 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 7 Feb 2017 22:11:50 +0000 Subject: Add ContractKind to ContractDefinition --- test/libsolidity/SolidityTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index 5362239d..0b5ab516 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(type_identifiers) TypePointer multiArray = make_shared(DataLocation::Storage, stringArray); BOOST_CHECK_EQUAL(multiArray->identifier(), "t_array$_t_array$_t_string_storage_$20_storage_$dyn_storage_ptr"); - ContractDefinition c(SourceLocation{}, make_shared("MyContract$"), {}, {}, {}, false); + ContractDefinition c(SourceLocation{}, make_shared("MyContract$"), {}, {}, {}, ContractDefinition::ContractKind::Contract); BOOST_CHECK_EQUAL(c.type()->identifier(), "t_type$_t_contract$_MyContract$$$_$2_$"); BOOST_CHECK_EQUAL(ContractType(c, true).identifier(), "t_super$_MyContract$$$_$2"); -- cgit From cfab70fd89e98f9301838682b28b9e400e1b2632 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 11 Feb 2017 21:17:24 +0000 Subject: Add tests for interfaces --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 98 ++++++++++++++++++++++ test/libsolidity/SolidityParser.cpp | 9 ++ 2 files changed, 107 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index fa310434..0861dded 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5327,6 +5327,104 @@ BOOST_AUTO_TEST_CASE(cyclic_dependency_for_constants) CHECK_SUCCESS(text); } +BOOST_AUTO_TEST_CASE(interface) +{ + char const* text = R"( + interface I { + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_constructor) +{ + char const* text = R"( + interface I { + function I(); + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_functions) +{ + char const* text = R"( + interface I { + function(); + function f(); + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_function_bodies) +{ + char const* text = R"( + interface I { + function f() { + } + } + )"; + CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation"); +} + +BOOST_AUTO_TEST_CASE(interface_events) +{ + char const* text = R"( + interface I { + event E(); + } + )"; + success(text); +} + +BOOST_AUTO_TEST_CASE(interface_inheritance) +{ + char const* text = R"( + interface A { + } + interface I is A { + } + )"; + CHECK_ERROR(text, TypeError, "Interfaces cannot inherit"); +} + + +BOOST_AUTO_TEST_CASE(interface_structs) +{ + char const* text = R"( + interface I { + struct A { + } + } + )"; + CHECK_ERROR(text, TypeError, "Structs cannot be defined in interfaces"); +} + +BOOST_AUTO_TEST_CASE(interface_variables) +{ + char const* text = R"( + interface I { + uint a; + } + )"; + CHECK_ERROR(text, TypeError, "Variables cannot be defined in interfaces"); +} + +BOOST_AUTO_TEST_CASE(using_interface) +{ + char const* text = R"( + interface I { + function f(); + } + contract C is I { + function f() { + } + } + )"; + success(text); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index ffb4b6f2..6e33aba5 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1493,6 +1493,15 @@ BOOST_AUTO_TEST_CASE(scientific_notation) BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(interface) +{ + char const* text = R"( + interface Interface { + function f(); + } + )"; + BOOST_CHECK(successParse(text)); +} BOOST_AUTO_TEST_SUITE_END() -- cgit From 16a91ef90aaf589361e34a10dcee2181ba6cb2ed Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 15 Feb 2017 11:43:26 +0000 Subject: Use declared instead of defined --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 0861dded..c30bb011 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5408,7 +5408,7 @@ BOOST_AUTO_TEST_CASE(interface_variables) uint a; } )"; - CHECK_ERROR(text, TypeError, "Variables cannot be defined in interfaces"); + CHECK_ERROR(text, TypeError, "Variables cannot be declared in interfaces"); } BOOST_AUTO_TEST_CASE(using_interface) -- cgit From 2c4bce2d62dc8bfc752858db12c625aec6e5960f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 15 Mar 2017 22:12:31 +0000 Subject: Disallow enums in interfaces --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index c30bb011..f6c875f1 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5411,6 +5411,16 @@ BOOST_AUTO_TEST_CASE(interface_variables) CHECK_ERROR(text, TypeError, "Variables cannot be declared in interfaces"); } +BOOST_AUTO_TEST_CASE(interface_enums) +{ + char const* text = R"( + interface I { + enum A { B, C } + } + )"; + CHECK_ERROR(text, TypeError, "Enumerable cannot be declared in interfaces"); +} + BOOST_AUTO_TEST_CASE(using_interface) { char const* text = R"( -- cgit From d5102c1db7cd2334e127ff684a6ecdd6aff156c6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 17 Mar 2017 16:37:02 +0000 Subject: Disallow constructor in interfaces --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index f6c875f1..39306f84 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5343,7 +5343,7 @@ BOOST_AUTO_TEST_CASE(interface_constructor) function I(); } )"; - success(text); + CHECK_ERROR(text, TypeError, "Constructor cannot be defined in interfaces"); } BOOST_AUTO_TEST_CASE(interface_functions) -- cgit From 5a71e4f1a7e856960d326be1743736cc04d3c238 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 17 Mar 2017 16:55:13 +0000 Subject: Add more complex tests for interfaces --- test/libsolidity/SolidityEndToEndTest.cpp | 35 ++++++++++++++++++++++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 17 +++++++++++ 2 files changed, 52 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 7ef34383..8dd5042a 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9266,6 +9266,41 @@ BOOST_AUTO_TEST_CASE(scientific_notation) BOOST_CHECK(callContractFunction("k()") == encodeArgs(u256(-25))); } +BOOST_AUTO_TEST_CASE(interface) +{ + char const* sourceCode = R"( + interface I { + event A(); + function f() returns (bool); + function() payable; + } + + contract A is I { + function f() returns (bool) { + return g(); + } + + function g() returns (bool) { + return true; + } + + function() payable { + } + } + + contract C { + function f(address _interfaceAddress) returns (bool) { + I i = I(_interfaceAddress); + return i.f(); + } + } + )"; + compileAndRun(sourceCode, 0, "A"); + u160 const recipient = m_contractAddress; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f(address)", recipient) == encodeArgs(true)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 39306f84..2a0f342c 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5435,6 +5435,23 @@ BOOST_AUTO_TEST_CASE(using_interface) success(text); } +BOOST_AUTO_TEST_CASE(using_interface_complex) +{ + char const* text = R"( + interface I { + event A(); + function f(); + function g(); + function(); + } + contract C is I { + function f() { + } + } + )"; + success(text); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit From 2067a00f2236980eeef812016ca923ec2cf3dbd2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 17 Mar 2017 16:59:36 +0000 Subject: Disallow private or internal functions in interfaces --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 2a0f342c..c002fd3e 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5368,6 +5368,26 @@ BOOST_AUTO_TEST_CASE(interface_function_bodies) CHECK_ERROR(text, TypeError, "Functions in interfaces cannot have an implementation"); } +BOOST_AUTO_TEST_CASE(interface_function_internal) +{ + char const* text = R"( + interface I { + function f() internal; + } + )"; + CHECK_ERROR(text, TypeError, "Functions in interfaces cannot be internal or private."); +} + +BOOST_AUTO_TEST_CASE(interface_function_private) +{ + char const* text = R"( + interface I { + function f() private; + } + )"; + CHECK_ERROR(text, TypeError, "Functions in interfaces cannot be internal or private."); +} + BOOST_AUTO_TEST_CASE(interface_events) { char const* text = R"( -- cgit