diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/ASTJSON.cpp | 14 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 36 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 15 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 2 |
4 files changed, 52 insertions, 15 deletions
diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp index a0fc5dd7..6c062ee8 100644 --- a/test/libsolidity/ASTJSON.cpp +++ b/test/libsolidity/ASTJSON.cpp @@ -94,20 +94,6 @@ BOOST_AUTO_TEST_CASE(using_for_directive) BOOST_CHECK_EQUAL(usingFor["children"][1]["attributes"]["name"], "uint"); } -BOOST_AUTO_TEST_CASE(enum_definition) -{ - CompilerStack c; - c.addSource("a", "contract C { enum E {} }"); - c.parse(); - map<string, unsigned> sourceIndices; - sourceIndices["a"] = 1; - Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json(); - Json::Value enumDefinition = astJson["children"][0]["children"][0]; - BOOST_CHECK_EQUAL(enumDefinition["name"], "EnumDefinition"); - BOOST_CHECK_EQUAL(enumDefinition["attributes"]["name"], "E"); - BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1"); -} - BOOST_AUTO_TEST_CASE(enum_value) { CompilerStack c; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bab54fab..5582e4a1 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3342,6 +3342,42 @@ BOOST_AUTO_TEST_CASE(using_enums) BOOST_CHECK(callContractFunction("getChoice()") == encodeArgs(2)); } +BOOST_AUTO_TEST_CASE(enum_explicit_overflow) +{ + char const* sourceCode = R"( + contract test { + enum ActionChoices { GoLeft, GoRight, GoStraight } + function test() + { + } + function getChoiceExp(uint x) returns (uint d) + { + choice = ActionChoices(x); + d = uint256(choice); + } + function getChoiceFromSigned(int x) returns (uint d) + { + choice = ActionChoices(x); + d = uint256(choice); + } + function getChoiceFromNegativeLiteral() returns (uint d) + { + choice = ActionChoices(-1); + d = uint256(choice); + } + ActionChoices choice; + } + )"; + compileAndRun(sourceCode); + // These should throw + BOOST_CHECK(callContractFunction("getChoiceExp(uint256)", 3) == encodeArgs()); + BOOST_CHECK(callContractFunction("getChoiceFromSigned(int256)", -1) == encodeArgs()); + BOOST_CHECK(callContractFunction("getChoiceFromNegativeLiteral()") == encodeArgs()); + // These should work + BOOST_CHECK(callContractFunction("getChoiceExp(uint256)", 2) == encodeArgs(2)); + BOOST_CHECK(callContractFunction("getChoiceExp(uint256)", 0) == encodeArgs(0)); +} + BOOST_AUTO_TEST_CASE(using_contract_enums_with_explicit_contract_name) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 099c3c00..f498a0b9 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1535,6 +1535,21 @@ BOOST_AUTO_TEST_CASE(enum_implicit_conversion_is_not_okay) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(enum_to_enum_conversion_is_not_okay) +{ + char const* text = R"( + contract test { + enum Paper { Up, Down, Left, Right } + enum Ground { North, South, West, East } + function test() + { + Ground(Paper.Up); + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + BOOST_AUTO_TEST_CASE(enum_duplicate_values) { char const* text = R"( diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index a81a9828..ec23d5fd 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -824,7 +824,7 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration) contract c { enum foo { } })"; - BOOST_CHECK(successParse(text)); + BOOST_CHECK(!successParse(text)); } BOOST_AUTO_TEST_CASE(malformed_enum_declaration) |