mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Moving some struct tests to semanticTests
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { C c; uint[] x; }
|
||||
function f(uint a, S[2] memory s1, uint b) public returns (uint r1, C r2, uint r3) {
|
||||
r1 = a;
|
||||
r2 = s1[0].c;
|
||||
r3 = b;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,(address,uint256[])[2],uint256): 7, 0x60, 8, 0x40, 0xE0, 0x0, 0x40, 2, 0x11, 0x12, 0x99, 0x40, 4, 0x31, 0x32, 0x34, 0x35 -> 7, 0x0, 8
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { C c; }
|
||||
function f(uint a, S[2] memory s1, uint b) public returns (uint r1, C r2, uint r3) {
|
||||
r1 = a;
|
||||
r2 = s1[0].c;
|
||||
r3 = b;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,(address)[2],uint256): 7, 0, 0, 8 -> 7, 0, 8
|
||||
@@ -0,0 +1,16 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { function () external returns (uint) f; uint b; }
|
||||
function f(S memory s) public returns (uint, uint) {
|
||||
return (s.f(), s.b);
|
||||
}
|
||||
function test() public returns (uint, uint) {
|
||||
return this.f(S(this.g, 3));
|
||||
}
|
||||
function g() public returns (uint) { return 7; }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 7, 3
|
||||
@@ -0,0 +1,13 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { int a; uint b; bytes16 c; }
|
||||
function f(S memory s) public pure returns (S memory q) {
|
||||
q = s;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f((int256,uint256,bytes16)): 0xff010, 0xff0002, "abcd" -> 0xff010, 0xff0002, "abcd"
|
||||
// f((int256,uint256,bytes16)): 0xff010, 0xff0002, 0x1111222233334444555566667777888800000000000000000000000000000000 -> 0xff010, 0xff0002, left(0x11112222333344445555666677778888)
|
||||
@@ -0,0 +1,15 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { uint a; uint8 b; uint8 c; bytes2 d; }
|
||||
function f(S memory s) public pure returns (uint a, uint b, uint c, uint d) {
|
||||
a = s.a;
|
||||
b = s.b;
|
||||
c = s.c;
|
||||
d = uint16(s.d);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f((uint256,uint8,uint8,bytes2)): 1, 2, 3, "ab" -> 1, 2, 3, 0x6162
|
||||
@@ -0,0 +1,19 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { int16 a; uint8 b; bytes2 c; }
|
||||
function f(S memory s) public pure returns (uint a, uint b, uint c) {
|
||||
assembly {
|
||||
a := mload(s)
|
||||
b := mload(add(s, 0x20))
|
||||
c := mload(add(s, 0x40))
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f((int16,uint8,bytes2)): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01, 0xff, "ab" -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01, 0xff, "ab"
|
||||
// f((int16,uint8,bytes2)): 0xff010, 0xff, "ab" -> FAILURE
|
||||
// f((int16,uint8,bytes2)): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01, 0xff0002, "ab" -> FAILURE
|
||||
// f((int16,uint8,bytes2)): 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01, 0xff, "abcd" -> FAILURE
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
struct S { function () external x; }
|
||||
function f(S memory) public pure returns (uint r) { r = 1; }
|
||||
function g(S calldata) external pure returns (uint r) { r = 2; }
|
||||
function h(S calldata s) external pure returns (uint r) { s.x; r = 3; }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f((function)): "01234567890123456789abcd" -> 1
|
||||
// f((function)): "01234567890123456789abcdX" -> FAILURE
|
||||
// g((function)): "01234567890123456789abcd" -> 2
|
||||
// g((function)): "01234567890123456789abcdX" -> 2
|
||||
// h((function)): "01234567890123456789abcd" -> 3
|
||||
// h((function)): "01234567890123456789abcdX" -> FAILURE
|
||||
Reference in New Issue
Block a user