Skip to content

Commit 19a7450

Browse files
trial test cases extracted from SoliidityEndToEndTest.cpp into .sol files.
removed libevmone.so files from the directory trial test cases extracted from SoliidityEndToEndTest.cpp into .sol files. Corresponding code in the .cpp file has been commented instead of begin removed pending preliminary reviews removed libevmone files Added testcase packed_storage_structs_delete added test case invalid_enum_logged added test case enum_referencing added test case memory_types_initialisation added test case return string added test case constant_string_literal.sol removed extractable keyword from solidityEndtoEnd.cpp, moved copying_bytes_multiassigned.sol to array/copying folder, added recv() function to copying_bytes_multiassigned.sol but this test case is failing now change typo error in the name of test case library_staticcall_delegatecal.sol to library_staticcall_delegatecall.sol Added compileToEwasm:false to call_forward_bytes.sol test case and moved it to semanticTests/fallback added compileToEwasm:false line to library_call_in_homestead added compileToEwasm: false line to copying_bytes_multiassign, copy_from_calldata_removes_bytes, enum_referencing, library_call_in_homestead, struct_referencing Added test case internal_types_in_library Added test case mapping_arguments_in_library Added test case mapping_returns_in_library Added test case mapping_returns_in_library_named Added test case using_library_mappings_public Added test case library_function_external Added test case library_stray_values added test case using_library_mappings_return added test case using_library_structs Added test case using_for_function_on_struct and corrections to using_library_structs, using_library_mpapings_return, library_stray_values Added test case using_for_overload added test case using_for_by_name added test case bound_function_in_function added test case bound_function_in_var added test case bound_function_to_string added test case payable_function_calls_library added function call corrections to copying_bytes_multiassign and call_forward_bytes Made changes to the test cases as per comments on PR #12289 mentioned in Changelog.md : Extraced some test cases from SolEndToEnd.cpp
1 parent 6363ff3 commit 19a7450

22 files changed

+584
-519
lines changed

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 0 additions & 519 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
contract receiver {
2+
uint public received;
3+
function recv(uint x) public { received += x + 1; }
4+
fallback() external { received = 0x80; }
5+
}
6+
contract sender {
7+
constructor() { rec = new receiver(); }
8+
fallback() external { savedData1 = savedData2 = msg.data; }
9+
function forward(bool selector) public returns (bool) {
10+
if (selector) { address(rec).call(savedData1); delete savedData1; }
11+
else { address(rec).call(savedData2); delete savedData2; }
12+
return true;
13+
}
14+
function val() public returns (uint) { return rec.received(); }
15+
receiver rec;
16+
bytes savedData1;
17+
bytes savedData2;
18+
}
19+
// ====
20+
// compileToEwasm: false
21+
// compileViaYul: also
22+
// ----
23+
// (): 7 ->
24+
// gas irOptimized: 110941
25+
// gas legacy: 111082
26+
// gas legacyOptimized: 111027
27+
// val() -> 0
28+
// forward(bool): true -> true
29+
// val() -> 0x80
30+
// forward(bool): false -> true
31+
// val() -> 0x80
32+
// forward(bool): true -> true
33+
// val() -> 0x80
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
contract c {
2+
function set() public returns (bool) { data = msg.data; return true; }
3+
function checkIfDataIsEmpty() public returns (bool) { return data.length == 0; }
4+
function sendMessage() public returns (bool, bytes memory) { bytes memory emptyData; return address(this).call(emptyData);}
5+
fallback() external { data = msg.data; }
6+
bytes data;
7+
}
8+
// ====
9+
// EVMVersion: >=byzantium
10+
// compileToEwasm: false
11+
// compileViaYul: also
12+
// ----
13+
// (): 1, 2, 3, 4, 5 ->
14+
// gas irOptimized: 155178
15+
// gas legacy: 155254
16+
// gas legacyOptimized: 155217
17+
// checkIfDataIsEmpty() -> false
18+
// sendMessage() -> true, 0x40, 0
19+
// checkIfDataIsEmpty() -> true
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
interface I {
2+
enum Direction { A, B, Left, Right }
3+
}
4+
library L {
5+
enum Direction { Left, Right }
6+
function f() public pure returns (Direction) {
7+
return Direction.Right;
8+
}
9+
function g() public pure returns (I.Direction) {
10+
return I.Direction.Right;
11+
}
12+
}
13+
contract C is I {
14+
function f() public pure returns (Direction) {
15+
return Direction.Right;
16+
}
17+
function g() public pure returns (I.Direction) {
18+
return I.Direction.Right;
19+
}
20+
function h() public pure returns (L.Direction) {
21+
return L.Direction.Right;
22+
}
23+
function x() public pure returns (L.Direction) {
24+
return L.f();
25+
}
26+
function y() public pure returns (I.Direction) {
27+
return L.g();
28+
}
29+
}
30+
// ====
31+
// compileViaYul: also
32+
// compileToEwasm: false
33+
// ----
34+
// library: L
35+
// f() -> 3
36+
// g() -> 3
37+
// f() -> 3
38+
// g() -> 3
39+
// h() -> 1
40+
// x() -> 1
41+
// y() -> 3
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
contract receiver {
2+
uint256 public received;
3+
function recv(uint256 x) public { received += x + 1; }
4+
fallback() external { received = 0x80; }
5+
}
6+
contract sender {
7+
constructor() { rec = new receiver();}
8+
fallback() external { savedData = msg.data; }
9+
function forward() public returns (bool) { address(rec).call(savedData); return true; }
10+
function clear() public returns (bool) { delete savedData; return true; }
11+
function val() public returns (uint) { return rec.received(); }
12+
receiver rec;
13+
bytes savedData;
14+
}
15+
// ====
16+
// allowNonExistingFunctions: true
17+
// compileToEwasm: false
18+
// compileViaYul: also
19+
// ----
20+
// recv(uint256): 7 ->
21+
// val() -> 0
22+
// forward() -> true
23+
// val() -> 8
24+
// clear() -> true
25+
// val() -> 8
26+
// forward() -> true
27+
// val() -> 0x80
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library L {
2+
function g(function() internal returns (uint) _t) internal returns (uint) { return _t(); }
3+
}
4+
contract C {
5+
using L for *;
6+
function f() public returns (uint) {
7+
return t.g();
8+
}
9+
function t() public pure returns (uint) { return 7; }
10+
}
11+
// ====
12+
// compileToEwasm: false
13+
// compileViaYul: also
14+
// ----
15+
// library: L
16+
// f() -> 7
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library D { struct s { uint a; } function mul(s storage self, uint x) public returns (uint) { return self.a *= x; } }
2+
contract C {
3+
using D for D.s;
4+
D.s public x;
5+
function f(uint a) public returns (uint) {
6+
x.a = 6;
7+
return (x.mul)({x: a});
8+
}
9+
}
10+
// ====
11+
// compileToEwasm: false
12+
// compileViaYul: also
13+
// ----
14+
// library: D
15+
// f(uint256): 7 -> 0x2a
16+
// x() -> 0x2a
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library D { function length(string memory self) public returns (uint) { return bytes(self).length; } }
2+
contract C {
3+
using D for string;
4+
string x;
5+
function f() public returns (uint) {
6+
x = "abc";
7+
return x.length();
8+
}
9+
function g() public returns (uint) {
10+
string memory s = "abc";
11+
return s.length();
12+
}
13+
}
14+
// ====
15+
// compileToEwasm: false
16+
// compileViaYul: also
17+
// ----
18+
// library: D
19+
// f() -> 3
20+
// g() -> 3
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
library Lib {
2+
function find(uint16[] storage _haystack, uint16 _needle) public view returns (uint)
3+
{
4+
for (uint i = 0; i < _haystack.length; ++i)
5+
if (_haystack[i] == _needle)
6+
return i;
7+
return type(uint).max;
8+
}
9+
}
10+
contract Test {
11+
mapping(string => uint16[]) data;
12+
function f() public returns (uint a, uint b)
13+
{
14+
while (data["abc"].length < 20)
15+
data["abc"].push();
16+
data["abc"][4] = 9;
17+
data["abc"][17] = 3;
18+
a = Lib.find(data["abc"], 9);
19+
b = Lib.find(data["abc"], 3);
20+
}
21+
}
22+
// ====
23+
// compileToEwasm: false
24+
// compileViaYul: also
25+
// ----
26+
// library: Lib
27+
// f() -> 4, 0x11
28+
// gas irOptimized: 115822
29+
// gas legacy: 135952
30+
// gas legacyOptimized: 119643
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
library Lib { function m() public returns (address) { return msg.sender; } }
2+
contract Test {
3+
address public sender;
4+
function f() public {
5+
sender = Lib.m();
6+
}
7+
}
8+
// ====
9+
// compileViaYul: also
10+
// compileToEwasm: false
11+
// EVMVersion: >=homestead
12+
// ----
13+
// library: Lib
14+
// f() ->
15+
// sender() -> 0x1212121212121212121212121212120000000012

0 commit comments

Comments
 (0)