Skip to content

Commit

Permalink
Moving some byte array pop tests to semanticTests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mijovic committed Nov 13, 2020
1 parent 31981ba commit 29d480d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 75 deletions.
75 changes: 0 additions & 75 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2854,81 +2854,6 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi)
);
}

BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty)
{
char const* sourceCode = R"(
contract c {
bytes data;
function test() public {
data.push(0x07);
data.push(0x05);
data.push(0x03);
data.pop();
data.pop();
data.pop();
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("test()"), encodeArgs());
BOOST_CHECK(storageEmpty(m_contractAddress));
);
}

BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty)
{
char const* sourceCode = R"(
contract c {
uint256 a;
uint256 b;
uint256 c;
bytes data;
function test() public returns (bool) {
for (uint8 i = 0; i <= 40; i++)
data.push(byte(i+1));
for (int8 j = 40; j >= 0; j--) {
require(data[uint8(j)] == byte(j+1));
require(data.length == uint8(j+1));
data.pop();
}
return true;
}
}
)";
ALSO_VIA_YUL(
DISABLE_EWASM_TESTRUN()
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("test()"), encodeArgs(true));
BOOST_CHECK(storageEmpty(m_contractAddress));
);
}

BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty_garbage_ref)
{
char const* sourceCode = R"(
contract c {
uint256 a;
uint256 b;
bytes data;
function test() public {
for (uint8 i = 0; i <= 40; i++)
data.push(0x03);
for (uint8 j = 0; j <= 40; j++) {
assembly {
mstore(0, "garbage")
}
data.pop();
}
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("test()"), encodeArgs());
BOOST_CHECK(storageEmpty(m_contractAddress));
}

BOOST_AUTO_TEST_CASE(external_array_args)
{
char const* sourceCode = R"(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
contract c {
uint256 a;
uint256 b;
uint256 c;
bytes data;
function test() public returns (bool) {
for (uint8 i = 0; i <= 40; i++)
data.push(byte(i+1));
for (int8 j = 40; j >= 0; j--) {
require(data[uint8(j)] == byte(j+1));
require(data.length == uint8(j+1));
data.pop();
}
return true;
}
}
// ====
// compileViaYul: also
// ----
// test() -> true
// storage: empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
contract c {
uint256 a;
uint256 b;
bytes data;
function test() public {
for (uint8 i = 0; i <= 40; i++)
data.push(0x03);
for (uint8 j = 0; j <= 40; j++) {
assembly {
mstore(0, "garbage")
}
data.pop();
}
}
}
// ====
// compileViaYul: also
// ----
// test() ->
// storage: empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
contract c {
bytes data;
function test() public {
data.push(0x07);
data.push(0x05);
data.push(0x03);
data.pop();
data.pop();
data.pop();
}
}
// ====
// compileViaYul: also
// ----
// test() ->
// storage: empty

0 comments on commit 29d480d

Please sign in to comment.