mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
test: add a test that compares overflown enums
This commit is contained in:
parent
a7c2509adf
commit
d49904c92a
@ -4506,6 +4506,39 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls)
|
|||||||
BOOST_CHECK(callContractFunction("t2()") == encodeArgs(u256(9)));
|
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)
|
BOOST_AUTO_TEST_CASE(invalid_enum_as_external_ret)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user