From 8856adce8f1829cecf7353c64c8cf07058da6f4f Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 8 Nov 2016 11:37:44 +0100 Subject: test: add tests that witness issue #1311 --- test/libsolidity/SolidityEndToEndTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index bab54fab..90547ad9 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -3342,6 +3342,30 @@ 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); + } + ActionChoices choice; + } + )"; + compileAndRun(sourceCode); + // These should throw + BOOST_CHECK(callContractFunction("getChoiceExp(uint256)", 3) == 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"( -- cgit