diff options
author | Yoichi Hirai <i@yoichihirai.com> | 2016-11-15 18:23:43 +0800 |
---|---|---|
committer | Yoichi Hirai <i@yoichihirai.com> | 2016-11-24 18:31:45 +0800 |
commit | d49904c92a890b058a46031c0c872f7b4abe936b (patch) | |
tree | a2cc8f54efe3b98ac6fabf8a810ba19643e43a50 | |
parent | a7c2509adfe57f106cb87ed024925751732b5412 (diff) | |
download | dexon-solidity-d49904c92a890b058a46031c0c872f7b4abe936b.tar.gz dexon-solidity-d49904c92a890b058a46031c0c872f7b4abe936b.tar.zst dexon-solidity-d49904c92a890b058a46031c0c872f7b4abe936b.zip |
test: add a test that compares overflown enums
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index a9a88789..c7c627be 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4506,6 +4506,39 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls) BOOST_CHECK(callContractFunction("t2()") == encodeArgs(u256(9))); } +BOOST_AUTO_TEST_CASE(invalid_enum_compared) +{ + char const* sourceCode = R"( + contract C { + enum X { A, B } + + function test_eq() returns (bool) { + X garbled; + assembly { + garbled := 5 + } + return garbled == garbled; + } + function test_eq_ok() returns (bool) { + X garbled = X.A; + return garbled == garbled; + } + function test_neq() returns (bool) { + X garbled; + assembly { + garbled := 5 + } + return garbled != garbled; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("test_eq_ok()") == encodeArgs(u256(1))); + // both should throw + BOOST_CHECK(callContractFunction("test_eq()") == encodeArgs()); + BOOST_CHECK(callContractFunction("test_neq()") == encodeArgs()); +} + BOOST_AUTO_TEST_CASE(invalid_enum_as_external_ret) { char const* sourceCode = R"( |