Adding simple array copying tests

This commit is contained in:
Djordje Mijovic 2020-09-02 09:36:20 +02:00
parent 0d83977d5a
commit e7a05324af
5 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,11 @@
contract C {
uint[] a;
function f() public returns (uint, uint) {
uint[] memory b = new uint[](3);
b[0] = 1;
a = b;
return (a[0], a.length);
}
}
// ----
// f() -> 1, 3

View File

@ -0,0 +1,10 @@
contract C {
uint[] a;
function f() public returns (uint, uint) {
a.push(1); a.push(0); a.push(0);
uint[] memory b = a;
return (b[0], b.length);
}
}
// ----
// f() -> 1, 3

View File

@ -0,0 +1,10 @@
contract C {
bytes s;
function f() external returns (byte) {
bytes memory data = "abcd";
s = data;
return s[0];
}
}
// ----
// f() -> "a"

View File

@ -0,0 +1,9 @@
contract C {
bytes s = "abcd";
function f() external returns (byte) {
bytes memory data = s;
return data[0];
}
}
// ----
// f() -> "a"

View File

@ -0,0 +1,9 @@
contract C {
bytes s;
function f(bytes calldata data) external returns (byte) {
s = data;
return s[0];
}
}
// ----
// f(bytes): 0x20, 0x08, "abcdefgh" -> "a"