New tests.

This commit is contained in:
chriseth 2020-05-25 19:30:42 +02:00
parent 499cb0526f
commit 99194b1450
7 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,12 @@
contract C {
function f(bytes calldata b, uint i) internal pure returns (byte) {
return b[i];
}
function f(uint, bytes calldata b, uint) external pure returns (byte) {
return f(b, 2);
}
}
// ====
// compileViaYul: also
// ----
// f(uint256,bytes,uint256): 7, 0x60, 7, 4, "abcd" -> "c"

View File

@ -0,0 +1,17 @@
contract C {
function(bytes calldata) returns (byte) x;
constructor() public { x = f; }
function f(bytes calldata b) internal pure returns (byte) {
return b[2];
}
function h(bytes calldata b) external returns (byte) {
return x(b);
}
function g() external returns (byte) {
bytes memory a = new bytes(34);
a[2] = byte(uint8(7));
return this.h(a);
}
}
// ----
// g() -> 0x0700000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,22 @@
library L {
function f(uint, bytes calldata _x, uint) internal returns (byte) {
return _x[2];
}
}
contract C {
function f(bytes calldata a)
external
returns (byte)
{
return L.f(3, a, 9);
}
function g() public returns (byte) {
bytes memory x = new bytes(4);
x[2] = 0x08;
return this.f(x);
}
}
// ====
// compileViaYul: also
// ----
// g() -> 0x0800000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,23 @@
pragma experimental ABIEncoderV2;
contract C {
function g(uint[][2] calldata s) internal pure returns (uint, uint[] calldata) {
return (s[0][1], s[1]);
}
function f(uint, uint[][2] calldata s, uint) external pure returns (uint, uint) {
(uint x, uint[] calldata y) = g(s);
return (x, y[0]);
}
function g() public returns (uint, uint) {
uint[][2] memory x;
x[0] = new uint[](2);
x[1] = new uint[](2);
x[0][1] = 7;
x[1][0] = 8;
return this.f(4, x, 5);
}
}
// ====
// compileViaYul: also
// ----
// g() -> 7, 8

View File

@ -0,0 +1,19 @@
contract C {
function g(uint[3][2] calldata s) internal pure returns (uint, uint[3] calldata) {
return (s[0][1], s[1]);
}
function f(uint, uint[3][2] calldata s, uint) external pure returns (uint, uint) {
(uint x, uint[3] calldata y) = g(s);
return (x, y[0]);
}
function g() public returns (uint, uint) {
uint[3][2] memory x;
x[0][1] = 7;
x[1][0] = 8;
return this.f(4, x, 5);
}
}
// ====
// compileViaYul: also
// ----
// g() -> 7, 8

View File

@ -0,0 +1,21 @@
contract C {
function f(bytes memory _a, bytes calldata _b, bytes memory _c)
public
returns (uint, byte, byte, byte)
{
return (_a.length + _b.length + _c.length, _a[1], _b[1], _c[1]);
}
function g() public returns (uint, byte, byte, byte) {
bytes memory x = new bytes(3);
bytes memory y = new bytes(4);
bytes memory z = new bytes(7);
x[1] = 0x08;
y[1] = 0x09;
z[1] = 0x0a;
return this.f(x, y, z);
}
}
// ====
// compileViaYul: also
// ----
// g() -> 0x0e, 0x0800000000000000000000000000000000000000000000000000000000000000, 0x0900000000000000000000000000000000000000000000000000000000000000, 0x0a00000000000000000000000000000000000000000000000000000000000000

View File

@ -0,0 +1,17 @@
pragma experimental ABIEncoderV2;
struct S {
uint x;
uint y;
}
contract C {
function f(S calldata s) internal pure returns (uint, uint) {
return (s.x, s.y);
}
function f(uint, S calldata s, uint) external pure returns (uint, uint) {
return f(s);
}
}
// ----
// f(uint256,(uint256,uint256),uint256): 7, 1, 2, 4 -> 1, 2