aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-03-22 00:54:05 +0800
committerGitHub <noreply@github.com>2017-03-22 00:54:05 +0800
commit6fb27dee635748110a27654a5a2c322d865b8578 (patch)
tree67b44c12852f074d93497d8f7129b95d89e43c73 /test
parent2cde2f9203f05b26bc0ffa45cb77c84a991f7d76 (diff)
parent5ced3af3a0579e4e0d5e0d923b3e9d3f21197bfa (diff)
downloaddexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.gz
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.bz2
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.lz
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.xz
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.tar.zst
dexon-solidity-6fb27dee635748110a27654a5a2c322d865b8578.zip
Merge pull request #1688 from ethereum/interface-keyword
Support strict interface contracts
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp35
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp145
-rw-r--r--test/libsolidity/SolidityParser.cpp9
-rw-r--r--test/libsolidity/SolidityTypes.cpp2
4 files changed, 190 insertions, 1 deletions
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 fa310434..c002fd3e 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -5327,6 +5327,151 @@ 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();
+ }
+ )";
+ CHECK_ERROR(text, TypeError, "Constructor cannot be defined in interfaces");
+}
+
+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_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"(
+ 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 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"(
+ interface I {
+ function f();
+ }
+ contract C is I {
+ function f() {
+ }
+ }
+ )";
+ 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()
}
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()
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<ArrayType>(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<string>("MyContract$"), {}, {}, {}, false);
+ ContractDefinition c(SourceLocation{}, make_shared<string>("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");