Merge pull request #9726 from ethereum/arrayCopySol2YulTests

Adding simple array copying tests
This commit is contained in:
chriseth 2020-09-02 11:05:01 +02:00 committed by GitHub
commit 5e66583b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"