Skip to content

Commit

Permalink
Merge pull request ethereum#8203 from ethereum/extract-tests
Browse files Browse the repository at this point in the history
Extract some semantic tests
  • Loading branch information
erak authored Jan 28, 2020
2 parents 0dd398e + 1027f6f commit 2d3bd91
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 82 deletions.
82 changes: 0 additions & 82 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
Expand Down Expand Up @@ -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"(
Expand Down Expand Up @@ -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"(
Expand Down
22 changes: 22 additions & 0 deletions test/libsolidity/semanticTests/functionCall/member_accessors.sol
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions test/libsolidity/semanticTests/types/mapping_simple.sol
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions test/libsolidity/semanticTests/types/strings.sol
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d3bd91

Please sign in to comment.