Moving enum test to semanticTests

This commit is contained in:
Djordje Mijovic 2020-11-03 11:33:16 +01:00
parent 73fcd9b5f0
commit 3f60223c41
3 changed files with 28 additions and 22 deletions

View File

@ -73,28 +73,6 @@ BOOST_AUTO_TEST_CASE(value_types)
)
}
BOOST_AUTO_TEST_CASE(enums)
{
string sourceCode = R"(
contract C {
enum E { A, B }
function f(E e) public pure returns (uint x) {
assembly { x := e }
}
}
)";
bool newDecoder = solidity::test::CommonOptions::get().useABIEncoderV2;
BOTH_ENCODERS(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f(uint8)", 0), encodeArgs(u256(0)));
ABI_CHECK(callContractFunction("f(uint8)", 1), encodeArgs(u256(1)));
// The old decoder was not as strict about enums
ABI_CHECK(callContractFunction("f(uint8)", 2), (newDecoder ? encodeArgs() : encodeArgs(2)));
ABI_CHECK(callContractFunction("f(uint8)", u256(-1)), (newDecoder? encodeArgs() : encodeArgs(u256(0xff))));
newDecoder = true;
)
}
BOOST_AUTO_TEST_CASE(cleanup)
{
string sourceCode = R"(

View File

@ -0,0 +1,13 @@
contract C {
enum E { A, B }
function f(E e) public pure returns (uint x) {
assembly { x := e }
}
}
// ====
// ABIEncoderV1Only: true
// ----
// f(uint8): 0 -> 0
// f(uint8): 1 -> 1
// f(uint8): 2 -> 2
// f(uint8): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> 0xff

View File

@ -0,0 +1,15 @@
pragma experimental ABIEncoderV2;
contract C {
enum E { A, B }
function f(E e) public pure returns (uint x) {
assembly { x := e }
}
}
// ====
// compileViaYul: also
// ----
// f(uint8): 0 -> 0
// f(uint8): 1 -> 1
// f(uint8): 2 -> FAILURE
// f(uint8): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -> FAILURE