test: add tests that witness issue #1311

This commit is contained in:
Yoichi Hirai 2016-11-08 11:37:44 +01:00
parent e6098f0039
commit 8856adce8f
No known key found for this signature in database
GPG Key ID: E7B75D080FCF7992

View File

@ -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"(