diff options
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/InlineAssembly.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 73 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 111 |
3 files changed, 185 insertions, 1 deletions
diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index f8655c0c..6c04367f 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -51,7 +51,7 @@ bool successParse(std::string const& _source, bool _assemble = false) if (_assemble) { stack.assemble(); - if (!stack.errors().empty()) + if (!stack.errors().empty() && !Error::containsOnlyWarnings(stack.errors())) return false; } } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 088fe4d1..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"( @@ -7304,6 +7355,28 @@ BOOST_AUTO_TEST_CASE(shift_negative_constant_right) BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(-0x42))); } +BOOST_AUTO_TEST_CASE(inline_assembly_in_modifiers) +{ + char const* sourceCode = R"( + contract C { + modifier m { + uint a = 1; + assembly { + a := 2 + } + if (a != 2) + throw; + _; + } + function f() m returns (bool) { + return true; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(true)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 35d09d23..f024c03e 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1456,6 +1456,21 @@ BOOST_AUTO_TEST_CASE(enum_invalid_member_access) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(enum_invalid_direct_member_access) +{ + char const* text = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight, Sit } + function test() + { + choices = Sit; + } + ActionChoices choices; + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::DeclarationError); +} + BOOST_AUTO_TEST_CASE(enum_explicit_conversion_is_okay) { char const* text = R"( @@ -1517,6 +1532,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"( @@ -4096,6 +4128,85 @@ BOOST_AUTO_TEST_CASE(shift_constant_right_excessive_rvalue) BOOST_CHECK(expectError(text, false) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_positive_stack) +{ + char const* text = R"( + contract test { + function f() { + assembly { + 1 + } + } + } + )"; + BOOST_CHECK(expectError(text, true) == Error::Type::Warning); +} + +BOOST_AUTO_TEST_CASE(inline_assembly_unbalanced_negative_stack) +{ + char const* text = R"( + contract test { + function f() { + assembly { + pop + } + } + } + )"; + BOOST_CHECK(expectError(text, true) == Error::Type::Warning); +} + +BOOST_AUTO_TEST_CASE(inline_assembly_in_modifier) +{ + char const* text = R"( + contract test { + modifier m { + uint a = 1; + assembly { + a := 2 + } + _; + } + function f() m { + } + } + )"; + BOOST_CHECK(success(text)); +} + +BOOST_AUTO_TEST_CASE(inline_assembly_storage) +{ + char const* text = R"( + contract test { + uint x = 1; + function f() { + assembly { + x := 2 + } + } + } + )"; + BOOST_CHECK(expectError(text, false) == Error::Type::DeclarationError); +} + +BOOST_AUTO_TEST_CASE(inline_assembly_storage_in_modifiers) +{ + char const* text = R"( + contract test { + uint x = 1; + modifier m { + assembly { + x := 2 + } + _; + } + function f() m { + } + } + )"; + BOOST_CHECK(expectError(text, false) == Error::Type::DeclarationError); +} + BOOST_AUTO_TEST_SUITE_END() } |