aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-10-18 19:02:43 +0800
committerYoichi Hirai <i@yoichihirai.com>2016-10-21 19:01:45 +0800
commitf967623a5b7a6ca5f07edd99537d07dd664a99fe (patch)
treee920df38b717d00ed10f4c14ab01a87fbb3224ae /test/libsolidity
parent984b8ac1b58309757380101aad644d3b1b30a2cd (diff)
downloaddexon-solidity-f967623a5b7a6ca5f07edd99537d07dd664a99fe.tar.gz
dexon-solidity-f967623a5b7a6ca5f07edd99537d07dd664a99fe.tar.zst
dexon-solidity-f967623a5b7a6ca5f07edd99537d07dd664a99fe.zip
test: add tests for #1131
The tests are about enum inheritance.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp51
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp17
2 files changed, 68 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0a028a45..16002f9a 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3314,6 +3314,57 @@ BOOST_AUTO_TEST_CASE(using_enums)
BOOST_CHECK(callContractFunction("getChoice()") == encodeArgs(2));
}
+BOOST_AUTO_TEST_CASE(using_contract_enums_with_explicit_contract_name)
+{
+ char const* sourceCode = R"(
+ contract test {
+ enum Choice { A, B, C }
+ function answer () returns (test.Choice _ret)
+ {
+ _ret = test.Choice.B;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("answer()") == encodeArgs(1));
+}
+
+BOOST_AUTO_TEST_CASE(using_inherited_enum)
+{
+ char const* sourceCode = R"(
+ contract base {
+ enum Choice { A, B, C }
+ }
+
+ contract test is base {
+ function answer () returns (Choice _ret)
+ {
+ _ret = Choice.B;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("answer()") == encodeArgs(1));
+}
+
+BOOST_AUTO_TEST_CASE(using_inherited_enum_excplicitly)
+{
+ char const* sourceCode = R"(
+ contract base {
+ enum Choice { A, B, C }
+ }
+
+ contract test is base {
+ function answer () returns (base.Choice _ret)
+ {
+ _ret = base.Choice.B;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("answer()") == encodeArgs(1));
+}
+
BOOST_AUTO_TEST_CASE(constructing_enums_from_ints)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 2c69f663..c580e491 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1500,6 +1500,23 @@ BOOST_AUTO_TEST_CASE(enum_duplicate_values)
BOOST_CHECK(expectError(text) == Error::Type::DeclarationError);
}
+BOOST_AUTO_TEST_CASE(enum_name_resolution_under_current_contract_name)
+{
+ char const* text = R"(
+ contract A {
+ enum Foo {
+ First,
+ Second
+ }
+
+ function a() {
+ A.Foo;
+ }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
BOOST_AUTO_TEST_CASE(private_visibility)
{
char const* sourceCode = R"(