Extract some semantic tests

This commit is contained in:
Mathias Baumann 2020-01-28 11:59:44 +01:00
parent cebca57ac2
commit 1027f6f78f
4 changed files with 64 additions and 82 deletions

View File

@ -784,26 +784,6 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
testContractAgainstCpp("run()", small_signed_types_cpp);
}
BOOST_AUTO_TEST_CASE(strings)
{
char const* sourceCode = R"(
contract test {
function fixedBytes() public returns(bytes32 ret) {
return "abc\x00\xff__";
}
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
oneRet = one;
large = small;
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("fixedBytes()"), encodeArgs(string("abc\0\xff__", 7)));
ABI_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true), encodeArgs(string("\0\x2", 2), true));
)
}
BOOST_AUTO_TEST_CASE(compound_assign)
{
char const* sourceCode = R"(
@ -843,40 +823,6 @@ BOOST_AUTO_TEST_CASE(compound_assign)
)
}
BOOST_AUTO_TEST_CASE(simple_mapping)
{
char const* sourceCode = R"(
contract test {
mapping(uint8 => uint8) table;
function get(uint8 k) public returns (uint8 v) {
return table[k];
}
function set(uint8 k, uint8 v) public {
table[k] = v;
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0)), encodeArgs(uint8_t(0x00)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x00)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0xa1));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0x00)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
callContractFunction("set(uint8,uint8)", uint8_t(0x00), uint8_t(0xef));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0x05));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x05)));
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
)
}
BOOST_AUTO_TEST_CASE(mapping_state)
{
char const* sourceCode = R"(
@ -1057,34 +1003,6 @@ BOOST_AUTO_TEST_CASE(constructor)
)
}
BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
{
char const* sourceCode = R"(
contract test {
uint256 public data;
bytes6 public name;
bytes32 public a_hash;
address public an_address;
constructor() public {
data = 8;
name = "Celina";
a_hash = keccak256("\x7b");
an_address = address(0x1337);
super_secret_data = 42;
}
uint256 super_secret_data;
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("data()"), encodeArgs(8));
ABI_CHECK(callContractFunction("name()"), encodeArgs("Celina"));
ABI_CHECK(callContractFunction("a_hash()"), encodeArgs(util::keccak256(bytes(1, 0x7b))));
ABI_CHECK(callContractFunction("an_address()"), encodeArgs(util::toBigEndian(u160(0x1337))));
ABI_CHECK(callContractFunction("super_secret_data()"), bytes());
);
}
BOOST_AUTO_TEST_CASE(balance)
{
char const* sourceCode = R"(

View File

@ -0,0 +1,22 @@
contract test {
uint256 public data;
bytes6 public name;
bytes32 public a_hash;
address public an_address;
constructor() public {
data = 8;
name = "Celina";
a_hash = keccak256("\x7b");
an_address = address(0x1337);
super_secret_data = 42;
}
uint256 super_secret_data;
}
// ====
// compileViaYul: also
// ----
// data() -> 8
// name() -> "Celina"
// a_hash() -> 0xa91eddf639b0b768929589c1a9fd21dcb0107199bdd82e55c5348018a1572f52
// an_address() -> 0x1337
// super_secret_data() -> FAILURE

View File

@ -0,0 +1,27 @@
contract test {
mapping(uint8 => uint8) table;
function get(uint8 k) public returns (uint8 v) {
return table[k];
}
function set(uint8 k, uint8 v) public {
table[k] = v;
}
}
// ====
// compileViaYul: also
// ----
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0
// get(uint8): 0xa7 -> 0
// set(uint8,uint8): 0x01, 0xa1 ->
// get(uint8): 0 -> 0
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> 0
// set(uint8,uint8): 0x00, 0xef ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0xa1
// get(uint8): 0xa7 -> 0
// set(uint8,uint8): 0x01, 0x05 ->
// get(uint8): 0 -> 0xef
// get(uint8): 0x01 -> 0x05
// get(uint8): 0xa7 -> 0

View File

@ -0,0 +1,15 @@
contract test {
function fixedBytes() public returns(bytes32 ret) {
return "abc\x00\xff__";
}
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
oneRet = one;
large = small;
}
}
// ====
// compileViaYul: also
// ----
// fixedBytes() -> "abc\0\xff__"
// pipeThrough(bytes2, bool): "\0\x02", true -> "\0\x2", true