mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Moving some array tests to semanticTests
This commit is contained in:
parent
18a464f4f4
commit
73fcd9b5f0
@ -184,113 +184,6 @@ BOOST_AUTO_TEST_CASE(fixed_arrays)
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(dynamic_arrays)
|
||||
{
|
||||
string sourceCode = R"(
|
||||
contract C {
|
||||
function f(uint a, uint16[] memory b, uint c)
|
||||
public pure returns (uint, uint, uint) {
|
||||
return (b.length, b[a], c);
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOTH_ENCODERS(
|
||||
compileAndRun(sourceCode);
|
||||
bytes args = encodeArgs(
|
||||
6, 0x60, 9,
|
||||
7,
|
||||
11, 12, 13, 14, 15, 16, 17
|
||||
);
|
||||
ABI_CHECK(
|
||||
callContractFunction("f(uint256,uint16[],uint256)", args),
|
||||
encodeArgs(u256(7), u256(17), u256(9))
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(dynamic_nested_arrays)
|
||||
{
|
||||
string sourceCode = R"(
|
||||
contract C {
|
||||
function f(uint a, uint16[][] memory b, uint[2][][3] memory c, uint d)
|
||||
public pure returns (uint, uint, uint, uint, uint, uint, uint) {
|
||||
return (a, b.length, b[1].length, b[1][1], c[1].length, c[1][1][1], d);
|
||||
}
|
||||
function test() public view returns (uint, uint, uint, uint, uint, uint, uint) {
|
||||
uint16[][] memory b = new uint16[][](3);
|
||||
b[0] = new uint16[](2);
|
||||
b[0][0] = 0x55;
|
||||
b[0][1] = 0x56;
|
||||
b[1] = new uint16[](4);
|
||||
b[1][0] = 0x65;
|
||||
b[1][1] = 0x66;
|
||||
b[1][2] = 0x67;
|
||||
b[1][3] = 0x68;
|
||||
|
||||
uint[2][][3] memory c;
|
||||
c[0] = new uint[2][](1);
|
||||
c[0][0][1] = 0x75;
|
||||
c[1] = new uint[2][](5);
|
||||
c[1][1][1] = 0x85;
|
||||
|
||||
return this.f(0x12, b, c, 0x13);
|
||||
}
|
||||
}
|
||||
)";
|
||||
NEW_ENCODER(
|
||||
compileAndRun(sourceCode);
|
||||
bytes args = encodeArgs(
|
||||
0x12, 4 * 0x20, 17 * 0x20, 0x13,
|
||||
// b
|
||||
3, 3 * 0x20, 6 * 0x20, 11 * 0x20,
|
||||
2, 85, 86,
|
||||
4, 101, 102, 103, 104,
|
||||
0,
|
||||
// c
|
||||
3 * 0x20, 6 * 0x20, 17 * 0x20,
|
||||
1, 0, 117,
|
||||
5, 0, 0, 0, 133, 0, 0, 0, 0, 0, 0,
|
||||
0
|
||||
);
|
||||
|
||||
bytes expectation = encodeArgs(0x12, 3, 4, 0x66, 5, 0x85, 0x13);
|
||||
ABI_CHECK(callContractFunction("test()"), expectation);
|
||||
ABI_CHECK(callContractFunction("f(uint256,uint16[][],uint256[2][][3],uint256)", args), expectation);
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(byte_arrays)
|
||||
{
|
||||
string sourceCode = R"(
|
||||
contract C {
|
||||
function f(uint a, bytes memory b, uint c)
|
||||
public pure returns (uint, uint, byte, uint) {
|
||||
return (a, b.length, b[3], c);
|
||||
}
|
||||
|
||||
function f_external(uint a, bytes calldata b, uint c)
|
||||
external pure returns (uint, uint, byte, uint) {
|
||||
return (a, b.length, b[3], c);
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOTH_ENCODERS(
|
||||
compileAndRun(sourceCode);
|
||||
bytes args = encodeArgs(
|
||||
6, 0x60, 9,
|
||||
7, "abcdefg"
|
||||
);
|
||||
ABI_CHECK(
|
||||
callContractFunction("f(uint256,bytes,uint256)", args),
|
||||
encodeArgs(u256(6), u256(7), "d", 9)
|
||||
);
|
||||
ABI_CHECK(
|
||||
callContractFunction("f_external(uint256,bytes,uint256)", args),
|
||||
encodeArgs(u256(6), u256(7), "d", 9)
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(calldata_arrays_too_large)
|
||||
{
|
||||
string sourceCode = R"(
|
||||
|
16
test/libsolidity/semanticTests/abiEncoderV1/byte_arrays.sol
Normal file
16
test/libsolidity/semanticTests/abiEncoderV1/byte_arrays.sol
Normal file
@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
function f(uint a, bytes memory b, uint c)
|
||||
public pure returns (uint, uint, byte, uint) {
|
||||
return (a, b.length, b[3], c);
|
||||
}
|
||||
|
||||
function f_external(uint a, bytes calldata b, uint c)
|
||||
external pure returns (uint, uint, byte, uint) {
|
||||
return (a, b.length, b[3], c);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,bytes,uint256): 6, 0x60, 9, 7, "abcdefg" -> 6, 7, "d", 9
|
||||
// f_external(uint256,bytes,uint256): 6, 0x60, 9, 7, "abcdefg" -> 6, 7, "d", 9
|
@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
function f(uint a, uint16[] memory b, uint c)
|
||||
public pure returns (uint, uint, uint) {
|
||||
return (b.length, b[a], c);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,uint16[],uint256): 6, 0x60, 9, 7, 11, 12, 13, 14, 15, 16, 17 -> 7, 17, 9
|
18
test/libsolidity/semanticTests/abiEncoderV2/byte_arrays.sol
Normal file
18
test/libsolidity/semanticTests/abiEncoderV2/byte_arrays.sol
Normal file
@ -0,0 +1,18 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
function f(uint a, bytes memory b, uint c)
|
||||
public pure returns (uint, uint, byte, uint) {
|
||||
return (a, b.length, b[3], c);
|
||||
}
|
||||
|
||||
function f_external(uint a, bytes calldata b, uint c)
|
||||
external pure returns (uint, uint, byte, uint) {
|
||||
return (a, b.length, b[3], c);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,bytes,uint256): 6, 0x60, 9, 7, "abcdefg" -> 6, 7, "d", 9
|
||||
// f_external(uint256,bytes,uint256): 6, 0x60, 9, 7, "abcdefg" -> 6, 7, "d", 9
|
@ -0,0 +1,12 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
function f(uint a, uint16[] memory b, uint c)
|
||||
public pure returns (uint, uint, uint) {
|
||||
return (b.length, b[a], c);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint256,uint16[],uint256): 6, 0x60, 9, 7, 11, 12, 13, 14, 15, 16, 17 -> 7, 17, 9
|
@ -0,0 +1,32 @@
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
contract C {
|
||||
function f(uint a, uint16[][] memory b, uint[2][][3] memory c, uint d)
|
||||
public pure returns (uint, uint, uint, uint, uint, uint, uint) {
|
||||
return (a, b.length, b[1].length, b[1][1], c[1].length, c[1][1][1], d);
|
||||
}
|
||||
function test() public view returns (uint, uint, uint, uint, uint, uint, uint) {
|
||||
uint16[][] memory b = new uint16[][](3);
|
||||
b[0] = new uint16[](2);
|
||||
b[0][0] = 0x55;
|
||||
b[0][1] = 0x56;
|
||||
b[1] = new uint16[](4);
|
||||
b[1][0] = 0x65;
|
||||
b[1][1] = 0x66;
|
||||
b[1][2] = 0x67;
|
||||
b[1][3] = 0x68;
|
||||
|
||||
uint[2][][3] memory c;
|
||||
c[0] = new uint[2][](1);
|
||||
c[0][0][1] = 0x75;
|
||||
c[1] = new uint[2][](5);
|
||||
c[1][1][1] = 0x85;
|
||||
|
||||
return this.f(12, b, c, 13);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 12, 3, 4, 0x66, 5, 0x85, 13
|
||||
// f(uint256,uint16[][],uint256[2][][3],uint256): 12, 0x80, 0x220, 13, 3, 0x60, 0xC0, 0x160, 2, 85, 86, 4, 101, 102, 103, 104, 0, 0x60, 0xC0, 0x220, 1, 0, 117, 5, 0, 0, 0, 133, 0, 0, 0, 0, 0, 0, 0 -> 12, 3, 4, 0x66, 5, 0x85, 13
|
Loading…
Reference in New Issue
Block a user