mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10192 from ethereum/refactorMoveTests2
Moving tests to semanticTests part2
This commit is contained in:
commit
0f6d3bc4ed
@ -73,117 +73,6 @@ BOOST_AUTO_TEST_CASE(value_types)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(cleanup)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function f(uint16 a, int16 b, address c, bytes3 d, bool e)
|
|
||||||
public pure returns (uint v, uint w, uint x, uint y, uint z) {
|
|
||||||
assembly { v := a w := b x := c y := d z := e}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
bool newDecoder = solidity::test::CommonOptions::get().useABIEncoderV2;
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f(uint16,int16,address,bytes3,bool)", 1, 2, 3, "a", true),
|
|
||||||
encodeArgs(u256(1), u256(2), u256(3), string("a"), true)
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction(
|
|
||||||
"f(uint16,int16,address,bytes3,bool)",
|
|
||||||
u256(0xffffff), u256(0x1ffff), u256(-1), string("abcd"), u256(1)
|
|
||||||
),
|
|
||||||
newDecoder ? bytes{} : encodeArgs(u256(0xffff), u256(-1), (u256(1) << 160) - 1, string("abc"), true)
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction(
|
|
||||||
"f(uint16,int16,address,bytes3,bool)",
|
|
||||||
u256(0xffffff), u256(0), u256(0), string("bcd"), u256(1)
|
|
||||||
),
|
|
||||||
newDecoder ? bytes{} : encodeArgs(u256(0xffff), u256(0), 0, string("bcd"), true)
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction(
|
|
||||||
"f(uint16,int16,address,bytes3,bool)",
|
|
||||||
u256(0), u256(0x1ffff), u256(0), string("ab"), u256(1)
|
|
||||||
),
|
|
||||||
newDecoder ? bytes{} : encodeArgs(u256(0), u256(-1), 0, string("ab"), true)
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction(
|
|
||||||
"f(uint16,int16,address,bytes3,bool)",
|
|
||||||
u256(0), u256(0), u256(-1), string("ad"), u256(1)
|
|
||||||
),
|
|
||||||
newDecoder ? bytes{} : encodeArgs(u256(0), u256(0), (u256(1) << 160) - 1, string("ad"), true)
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction(
|
|
||||||
"f(uint16,int16,address,bytes3,bool)",
|
|
||||||
u256(0), u256(0), u256(0), string("abcd"), u256(1)
|
|
||||||
),
|
|
||||||
newDecoder ? bytes{} : encodeArgs(u256(0), u256(0), 0, string("abc"), true)
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction(
|
|
||||||
"f(uint16,int16,address,bytes3,bool)",
|
|
||||||
u256(0), u256(0), u256(0), string("abc"), u256(2)
|
|
||||||
),
|
|
||||||
newDecoder ? bytes{} : encodeArgs(u256(0), u256(0), 0, string("abc"), true)
|
|
||||||
);
|
|
||||||
newDecoder = true;
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(fixed_arrays)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function f(uint16[3] memory a, uint16[2][3] memory b, uint i, uint j, uint k)
|
|
||||||
public pure returns (uint, uint) {
|
|
||||||
return (a[i], b[j][k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode);
|
|
||||||
bytes args = encodeArgs(
|
|
||||||
1, 2, 3,
|
|
||||||
11, 12,
|
|
||||||
21, 22,
|
|
||||||
31, 32,
|
|
||||||
1, 2, 1
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f(uint16[3],uint16[2][3],uint256,uint256,uint256)", args),
|
|
||||||
encodeArgs(u256(2), u256(32))
|
|
||||||
);
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(calldata_arrays_too_large)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function f(uint a, uint[] calldata b, uint c) external pure returns (uint) {
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode);
|
|
||||||
bytes args = encodeArgs(
|
|
||||||
6, 0x60, 9,
|
|
||||||
(u256(1) << 255) + 2, 1, 2
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f(uint256,uint256[],uint256)", args),
|
|
||||||
encodeArgs()
|
|
||||||
);
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(decode_from_memory_simple)
|
BOOST_AUTO_TEST_CASE(decode_from_memory_simple)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
string sourceCode = R"(
|
||||||
@ -463,121 +352,6 @@ BOOST_AUTO_TEST_CASE(validation_function_type)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(validation_function_type_inside_struct)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
string validFun{"01234567890123456789abcd"};
|
|
||||||
string invalidFun{"01234567890123456789abcdX"};
|
|
||||||
NEW_ENCODER(
|
|
||||||
compileAndRun(sourceCode);
|
|
||||||
ABI_CHECK(callContractFunction("f((function))", validFun), encodeArgs(1));
|
|
||||||
// Error because we copy to memory
|
|
||||||
ABI_CHECK(callContractFunction("f((function))", invalidFun), encodeArgs());
|
|
||||||
ABI_CHECK(callContractFunction("g((function))", validFun), encodeArgs(2));
|
|
||||||
// No error because x is not accessed.
|
|
||||||
ABI_CHECK(callContractFunction("g((function))", invalidFun), encodeArgs(2));
|
|
||||||
ABI_CHECK(callContractFunction("h((function))", validFun), encodeArgs(3));
|
|
||||||
// Error on access.
|
|
||||||
ABI_CHECK(callContractFunction("h((function))", invalidFun), encodeArgs());
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(storage_ptr)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
library L {
|
|
||||||
struct S { uint x; uint y; }
|
|
||||||
function f(uint[] storage r, S storage s) public returns (uint, uint, uint, uint) {
|
|
||||||
r[2] = 8;
|
|
||||||
s.x = 7;
|
|
||||||
return (r[0], r[1], s.x, s.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contract C {
|
|
||||||
uint8 x = 3;
|
|
||||||
L.S s;
|
|
||||||
uint[] r;
|
|
||||||
function f() public returns (uint, uint, uint, uint, uint, uint) {
|
|
||||||
r = new uint[](6);
|
|
||||||
r[0] = 1;
|
|
||||||
r[1] = 2;
|
|
||||||
r[2] = 3;
|
|
||||||
s.x = 11;
|
|
||||||
s.y = 12;
|
|
||||||
(uint a, uint b, uint c, uint d) = L.f(r, s);
|
|
||||||
return (r[2], s.x, a, b, c, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode, 0, "L");
|
|
||||||
compileAndRun(sourceCode, 0, "C", bytes(), map<string, Address>{{"L", m_contractAddress}});
|
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(8, 7, 1, 2, 7, 12));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_simple)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
NEW_ENCODER(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
ABI_CHECK(callContractFunction("f((uint256,uint8,uint8,bytes2))", 1, 2, 3, "ab"), encodeArgs(1, 2, 3, 'a' * 0x100 + 'b'));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_validation)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
u256 largeNeg("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01");
|
|
||||||
NEW_ENCODER(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f((int16,uint8,bytes2))", largeNeg, 0xff, "ab"),
|
|
||||||
encodeArgs(largeNeg, 0xff, "ab")
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f((int16,uint8,bytes2))", 0xff010, 0xff, "ab"),
|
|
||||||
encodeArgs()
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f((int16,uint8,bytes2))", largeNeg, 0xff0002, "ab"),
|
|
||||||
encodeArgs()
|
|
||||||
);
|
|
||||||
ABI_CHECK(
|
|
||||||
callContractFunction("f((int16,uint8,bytes2))", largeNeg, 0xff, "abcd"),
|
|
||||||
encodeArgs()
|
|
||||||
);
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_short)
|
BOOST_AUTO_TEST_CASE(struct_short)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
string sourceCode = R"(
|
||||||
@ -605,73 +379,6 @@ BOOST_AUTO_TEST_CASE(struct_short)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(struct_function)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
NEW_ENCODER(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
ABI_CHECK(callContractFunction("test()"), encodeArgs(7, 3));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mediocre_struct)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
NEW_ENCODER(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
string sig = "f(uint256,(address)[2],uint256)";
|
|
||||||
ABI_CHECK(callContractFunction(sig,
|
|
||||||
7, u256(u160(m_contractAddress)), 0, 8
|
|
||||||
), encodeArgs(7, u256(u160(m_contractAddress)), 8));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(mediocre2_struct)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
NEW_ENCODER(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
string sig = "f(uint256,(address,uint256[])[2],uint256)";
|
|
||||||
ABI_CHECK(callContractFunction(sig,
|
|
||||||
7, 0x60, 8,
|
|
||||||
0x40, 7 * 0x20,
|
|
||||||
u256(u160(m_contractAddress)), 0x40,
|
|
||||||
2, 0x11, 0x12,
|
|
||||||
0x99, 0x40,
|
|
||||||
4, 0x31, 0x32, 0x34, 0x35
|
|
||||||
), encodeArgs(7, u256(u160(m_contractAddress)), 8));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(complex_struct)
|
BOOST_AUTO_TEST_CASE(complex_struct)
|
||||||
{
|
{
|
||||||
string sourceCode = R"(
|
string sourceCode = R"(
|
||||||
@ -731,108 +438,6 @@ BOOST_AUTO_TEST_CASE(complex_struct)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_simple)
|
|
||||||
{
|
|
||||||
if (m_evmVersion == langutil::EVMVersion::homestead())
|
|
||||||
return;
|
|
||||||
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function dyn() public returns (bytes memory) {
|
|
||||||
return "1234567890123456789012345678901234567890";
|
|
||||||
}
|
|
||||||
function f() public returns (bytes memory) {
|
|
||||||
return this.dyn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(0x20, 40, string("1234567890123456789012345678901234567890")));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_advanced)
|
|
||||||
{
|
|
||||||
if (m_evmVersion == langutil::EVMVersion::homestead())
|
|
||||||
return;
|
|
||||||
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function dyn() public returns (bytes memory a, uint b, bytes20[] memory c, uint d) {
|
|
||||||
a = "1234567890123456789012345678901234567890";
|
|
||||||
b = uint(-1);
|
|
||||||
c = new bytes20[](4);
|
|
||||||
c[0] = bytes20(uint160(1234));
|
|
||||||
c[3] = bytes20(uint160(6789));
|
|
||||||
d = 0x1234;
|
|
||||||
}
|
|
||||||
function f() public returns (bytes memory, uint, bytes20[] memory, uint) {
|
|
||||||
return this.dyn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(
|
|
||||||
0x80, u256(-1), 0xe0, 0x1234,
|
|
||||||
40, string("1234567890123456789012345678901234567890"),
|
|
||||||
4, u256(1234) << (8 * (32 - 20)), 0, 0, u256(6789) << (8 * (32 - 20))
|
|
||||||
));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(return_dynamic_types_cross_call_out_of_range)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function dyn(uint x) public returns (bytes memory a) {
|
|
||||||
assembly {
|
|
||||||
mstore(0, 0x20)
|
|
||||||
mstore(0x20, 0x21)
|
|
||||||
return(0, x)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function f(uint x) public returns (bool) {
|
|
||||||
this.dyn(x);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
|
||||||
if (m_evmVersion == langutil::EVMVersion::homestead())
|
|
||||||
{
|
|
||||||
ABI_CHECK(callContractFunction("f(uint256)", 0x60), encodeArgs(true));
|
|
||||||
ABI_CHECK(callContractFunction("f(uint256)", 0x7f), encodeArgs(true));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ABI_CHECK(callContractFunction("f(uint256)", 0x60), encodeArgs());
|
|
||||||
ABI_CHECK(callContractFunction("f(uint256)", 0x61), encodeArgs(true));
|
|
||||||
}
|
|
||||||
ABI_CHECK(callContractFunction("f(uint256)", 0x80), encodeArgs(true));
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(out_of_bounds_bool_value)
|
|
||||||
{
|
|
||||||
string sourceCode = R"(
|
|
||||||
contract C {
|
|
||||||
function f(bool b) public pure returns (bool) { return b; }
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
bool newDecoder = solidity::test::CommonOptions::get().useABIEncoderV2;
|
|
||||||
BOTH_ENCODERS(
|
|
||||||
compileAndRun(sourceCode);
|
|
||||||
ABI_CHECK(callContractFunction("f(bool)", true), encodeArgs(true));
|
|
||||||
ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(false));
|
|
||||||
ABI_CHECK(callContractFunctionNoEncoding("f(bool)", bytes(32, 0)), encodeArgs(0));
|
|
||||||
ABI_CHECK(callContractFunctionNoEncoding("f(bool)", bytes(32, 0xff)), newDecoder ? encodeArgs() : encodeArgs(1));
|
|
||||||
newDecoder = true;
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
} // end namespaces
|
} // end namespaces
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
contract C {
|
||||||
|
function f(uint16[3] memory a, uint16[2][3] memory b, uint i, uint j, uint k)
|
||||||
|
public pure returns (uint, uint) {
|
||||||
|
return (a[i], b[j][k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(uint16[3],uint16[2][3],uint256,uint256,uint256): 1, 2, 3, 11, 12, 21, 22, 31, 32, 1, 2, 1 -> 2, 32
|
@ -0,0 +1,10 @@
|
|||||||
|
contract C {
|
||||||
|
function f(bool b) public pure returns (bool) { return b; }
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// ABIEncoderV1Only: true
|
||||||
|
// ----
|
||||||
|
// f(bool): true -> true
|
||||||
|
// f(bool): false -> false
|
||||||
|
// f(bool): 0x000000 -> false
|
||||||
|
// f(bool): 0xffffff -> true
|
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
function f(uint a, uint[] calldata b, uint c) external pure returns (uint) {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(uint256,uint256[],uint256): 6, 0x60, 9, 0x8000000000000000000000000000000000000000000000000000000000000002, 1, 2 -> FAILURE
|
@ -0,0 +1,16 @@
|
|||||||
|
contract C {
|
||||||
|
function f(uint16 a, int16 b, address c, bytes3 d, bool e)
|
||||||
|
public pure returns (uint v, uint w, uint x, uint y, uint z) {
|
||||||
|
assembly { v := a w := b x := c y := d z := e}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// ABIEncoderV1Only: true
|
||||||
|
// ----
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 1, 2, 3, "a", true -> 1, 2, 3, "a", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0xffffff, 0x1ffff, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, "abcd", 1 -> 0xffff, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0xffffffffffffffffffffffffffffffffffffffff, "abc", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0xffffff, 0, 0, "bcd", 1 -> 0xffff, 0, 0, "bcd", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0x1ffff, 0, "ab", 1 -> 0, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0, "ab", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, "ad", 1 -> 0, 0, 0xffffffffffffffffffffffffffffffffffffffff, "ad", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0, 0, "abcd", 1 -> 0, 0, 0, "abc", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0, 0, "abc", 2 -> 0, 0, 0, "abc", true
|
@ -0,0 +1,18 @@
|
|||||||
|
contract C {
|
||||||
|
function dyn() public returns (bytes memory a, uint b, bytes20[] memory c, uint d) {
|
||||||
|
a = "1234567890123456789012345678901234567890";
|
||||||
|
b = uint(-1);
|
||||||
|
c = new bytes20[](4);
|
||||||
|
c[0] = bytes20(uint160(1234));
|
||||||
|
c[3] = bytes20(uint160(6789));
|
||||||
|
d = 0x1234;
|
||||||
|
}
|
||||||
|
function f() public returns (bytes memory, uint, bytes20[] memory, uint) {
|
||||||
|
return this.dyn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// EVMVersion: >homestead
|
||||||
|
// ----
|
||||||
|
// f() -> 0x80, -1, 0xe0, 0x1234, 40, "12345678901234567890123456789012", "34567890", 4, 97767552542602192590433234714624, 0, 0, 537879995309340587922569878831104
|
@ -0,0 +1,20 @@
|
|||||||
|
contract C {
|
||||||
|
function dyn(uint x) public returns (bytes memory a) {
|
||||||
|
assembly {
|
||||||
|
mstore(0, 0x20)
|
||||||
|
mstore(0x20, 0x21)
|
||||||
|
return(0, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f(uint x) public returns (bool) {
|
||||||
|
this.dyn(x);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// EVMVersion: =homestead
|
||||||
|
// ----
|
||||||
|
// f(uint256): 0x60 -> true
|
||||||
|
// f(uint256): 0x7f -> true
|
||||||
|
// f(uint256): 0x80 -> true
|
@ -0,0 +1,20 @@
|
|||||||
|
contract C {
|
||||||
|
function dyn(uint x) public returns (bytes memory a) {
|
||||||
|
assembly {
|
||||||
|
mstore(0, 0x20)
|
||||||
|
mstore(0x20, 0x21)
|
||||||
|
return(0, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function f(uint x) public returns (bool) {
|
||||||
|
this.dyn(x);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// EVMVersion: >homestead
|
||||||
|
// ----
|
||||||
|
// f(uint256): 0x60 -> FAILURE
|
||||||
|
// f(uint256): 0x61 -> true
|
||||||
|
// f(uint256): 0x80 -> true
|
@ -0,0 +1,13 @@
|
|||||||
|
contract C {
|
||||||
|
function dyn() public returns (bytes memory) {
|
||||||
|
return "1234567890123456789012345678901234567890";
|
||||||
|
}
|
||||||
|
function f() public returns (bytes memory) {
|
||||||
|
return this.dyn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// EVMVersion: >homestead
|
||||||
|
// ----
|
||||||
|
// f() -> 0x20, 40, "12345678901234567890123456789012", "34567890"
|
@ -0,0 +1,26 @@
|
|||||||
|
library L {
|
||||||
|
struct S { uint x; uint y; }
|
||||||
|
function f(uint[] storage r, S storage s) public returns (uint, uint, uint, uint) {
|
||||||
|
r[2] = 8;
|
||||||
|
s.x = 7;
|
||||||
|
return (r[0], r[1], s.x, s.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contract C {
|
||||||
|
uint8 x = 3;
|
||||||
|
L.S s;
|
||||||
|
uint[] r;
|
||||||
|
function f() public returns (uint, uint, uint, uint, uint, uint) {
|
||||||
|
r = new uint[](6);
|
||||||
|
r[0] = 1;
|
||||||
|
r[1] = 2;
|
||||||
|
r[2] = 3;
|
||||||
|
s.x = 11;
|
||||||
|
s.y = 12;
|
||||||
|
(uint a, uint b, uint c, uint d) = L.f(r, s);
|
||||||
|
return (r[2], s.x, a, b, c, d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// library: L
|
||||||
|
// f() -> 8, 7, 1, 2, 7, 12
|
@ -0,0 +1,12 @@
|
|||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function f(bool b) public pure returns (bool) { return b; }
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(bool): true -> true
|
||||||
|
// f(bool): false -> false
|
||||||
|
// f(bool): 0x000000 -> false
|
||||||
|
// f(bool): 0xffffff -> FAILURE
|
@ -0,0 +1,18 @@
|
|||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function f(uint16 a, int16 b, address c, bytes3 d, bool e)
|
||||||
|
public pure returns (uint v, uint w, uint x, uint y, uint z) {
|
||||||
|
assembly { v := a w := b x := c y := d z := e}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 1, 2, 3, "a", true -> 1, 2, 3, "a", true
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0xffffff, 0x1ffff, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, "abcd", 1 -> FAILURE
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0xffffff, 0, 0, "bcd", 1 -> FAILURE
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0x1ffff, 0, "ab", 1 -> FAILURE
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, "ad", 1 -> FAILURE
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0, 0, "abcd", 1 -> FAILURE
|
||||||
|
// f(uint16,int16,address,bytes3,bool): 0, 0, 0, "abc", 2 -> FAILURE
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user