Skip to content

Commit be30965

Browse files
authored
Merge pull request #15665 from ipsilon/eof-semantic-tests
eof: Semantic tests update
2 parents 231a01c + c2f1425 commit be30965

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+244
-0
lines changed

test/libsolidity/semanticTests/constructor/callvalue_check.sol

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ contract B4 { constructor() {} }
1111
contract C {
1212
function createWithValue(bytes memory c, uint256 value) public payable returns (bool) {
1313
uint256 y = 0;
14+
// TODO: This test is hard to recreate for EOF as for now eofcreate is disallowed in inline assembly.
1415
assembly { y := create(value, add(c, 0x20), mload(c)) }
1516
return y != 0;
1617
}
@@ -29,6 +30,7 @@ contract C {
2930
}
3031
// ====
3132
// EVMVersion: >homestead
33+
// bytecodeFormat: legacy
3234
// ----
3335
// f(uint256), 2000 ether: 0 -> true
3436
// f(uint256), 2000 ether: 100 -> false

test/libsolidity/semanticTests/deployedCodeExclusion/bound_function.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
function longdata(S memory) pure returns (bytes memory) {
23
return
34
"xasopca.pngaibngidak.jbtnudak.cAP.BRRSMCPJAGPD KIAJDOMHUKR,SCPID"
@@ -36,5 +37,7 @@ contract C {
3637
return x < data.length;
3738
}
3839
}
40+
// ====
41+
// bytecodeFormat: legacy
3942
// ----
4043
// test() -> true

test/libsolidity/semanticTests/deployedCodeExclusion/library_function.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
library L {
23
function longdata() pure internal returns (bytes memory) {
34
return
@@ -30,5 +31,7 @@ contract C {
3031
return x < data.length;
3132
}
3233
}
34+
// ====
35+
// bytecodeFormat: legacy
3336
// ----
3437
// test() -> true

test/libsolidity/semanticTests/deployedCodeExclusion/module_function.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
==== Source: mod.sol ====
23
function longdata() pure returns (bytes memory) {
34
return
@@ -32,5 +33,7 @@ contract C {
3233
return x < data.length;
3334
}
3435
}
36+
// ====
37+
// bytecodeFormat: legacy
3538
// ----
3639
// test() -> true

test/libsolidity/semanticTests/deployedCodeExclusion/static_base_function.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
abstract contract S {
23
function longdata() internal pure returns (bytes memory) {
34
return
@@ -31,5 +32,7 @@ contract C is S {
3132
return x < data.length;
3233
}
3334
}
35+
// ====
36+
// bytecodeFormat: legacy
3437
// ----
3538
// test() -> true

test/libsolidity/semanticTests/deployedCodeExclusion/subassembly_deduplication.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
contract A {
23
function longdata() pure external returns (bytes memory) {
34
return
@@ -37,5 +38,7 @@ contract C {
3738
x < 2 * type(A).creationCode.length;
3839
}
3940
}
41+
// ====
42+
// bytecodeFormat: legacy
4043
// ----
4144
// test() -> true

test/libsolidity/semanticTests/deployedCodeExclusion/super_function.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
abstract contract S {
23
function longdata() internal pure returns (bytes memory) {
34
return
@@ -31,5 +32,7 @@ contract C is S {
3132
return x < data.length;
3233
}
3334
}
35+
// ====
36+
// bytecodeFormat: legacy
3437
// ----
3538
// test() -> true

test/libsolidity/semanticTests/deployedCodeExclusion/virtual_function.sol

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: Recreate this test for EOF when subassembly deduplication will be supported for EOF too.
12
abstract contract S {
23
function longdata() internal virtual pure returns (bytes memory);
34
}
@@ -35,5 +36,7 @@ contract C is X {
3536
return x < data.length;
3637
}
3738
}
39+
// ====
40+
// bytecodeFormat: legacy
3841
// ----
3942
// test() -> true

test/libsolidity/semanticTests/events/event_emit_from_other_contract.sol

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: Implement this test for EOF. Now it's not possible because deployed contract address depends on contract bytecode.
2+
// This means that the address changes when optimisations are applied.
13
contract D {
24
event Deposit(address indexed _from, bytes32 indexed _id, uint _value);
35
function deposit(bytes32 _id) public payable {
@@ -13,6 +15,8 @@ contract C {
1315
d.deposit(_id);
1416
}
1517
}
18+
// ====
19+
// bytecodeFormat: legacy
1620
// ----
1721
// constructor() ->
1822
// gas irOptimized: 113970

test/libsolidity/semanticTests/experimental/stub.sol

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ contract C {
9292
// EVMVersion: >=constantinople
9393
// ====
9494
// compileViaYul: true
95+
// bytecodeFormat: legacy
9596
// ----
9697
// (): 0 -> 0
9798
// (): 1 -> 544

test/libsolidity/semanticTests/experimental/type_class.sol

+1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,6 @@ contract C {
6363
// ====
6464
// EVMVersion: >=constantinople
6565
// compileViaYul: true
66+
// bytecodeFormat: legacy
6667
// ----
6768
// () -> 1, 0

test/libsolidity/semanticTests/freeFunctions/free_runtimecode.sol

+2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ contract D {
1111
return test();
1212
}
1313
}
14+
// ====
15+
// bytecodeFormat: legacy
1416
// ----
1517
// f() -> true

test/libsolidity/semanticTests/functionCall/call_options_overload.sol

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ contract C {
1010
function bal() external returns (uint) { return address(this).balance; }
1111
receive() external payable {}
1212
}
13+
// ====
14+
// bytecodeFormat: legacy
1315
// ----
1416
// (), 1 ether
1517
// call() -> 1, 2, 2, 2

test/libsolidity/semanticTests/functionCall/calling_nonexisting_contract_throws.sol

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ contract C {
2121
return 7;
2222
}
2323
}
24+
// ====
25+
// bytecodeFormat: legacy
2426
// ----
2527
// f() -> FAILURE
2628
// g() -> FAILURE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
contract C {
2+
function f(uint x) external payable returns (uint) { return 1; }
3+
function f(uint x, uint y) external payable returns (uint) { return 2; }
4+
function call() public payable returns (uint x, uint y) {
5+
x = this.f{value: 10}(2);
6+
y = this.f{value: 10}(2, 3);
7+
}
8+
function bal() external returns (uint) { return address(this).balance; }
9+
receive() external payable {}
10+
}
11+
// ====
12+
// bytecodeFormat: >=EOFv1
13+
// ----
14+
// (), 1 ether
15+
// call() -> 1, 2
16+
// bal() -> 1000000000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
abstract contract D {
2+
function g() public virtual;
3+
}
4+
5+
6+
contract C {
7+
D d = D(address(0x1212));
8+
9+
function f() public returns (uint256) {
10+
// This call throws on legacy bytecode because of calling nonexisting contract. Legacy checks that there is
11+
// a non-empty code under under an address. EOF doesn't do it because non-observability assumption
12+
d.g();
13+
return 7;
14+
}
15+
16+
function h() public returns (uint256) {
17+
address(d).call(""); // this does not throw (low-level)
18+
return 7;
19+
}
20+
}
21+
// ====
22+
// bytecodeFormat: >=EOFv1
23+
// ----
24+
// f() -> 7
25+
// h() -> 7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This tests skipping the extcodesize check.
2+
3+
contract T {
4+
constructor() { this.f(); }
5+
function f() external {}
6+
}
7+
contract U {
8+
constructor() { this.f(); }
9+
function f() external returns (uint) {}
10+
}
11+
12+
contract C {
13+
function f(uint c) external returns (uint) {
14+
if (c == 0) new T();
15+
else if (c == 1) new U();
16+
return 1 + c;
17+
}
18+
}
19+
// ====
20+
// bytecodeFormat: >=EOFv1
21+
// ----
22+
// f(uint256): 0 -> 1
23+
// f(uint256): 1 -> FAILURE
24+
// f(uint256): 2 -> 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This tests skipping the extcodesize check.
2+
3+
interface I {
4+
function a() external pure;
5+
function b() external;
6+
function c() external payable;
7+
function x() external returns (uint);
8+
function y() external returns (string memory);
9+
}
10+
contract C {
11+
I i = I(address(0xcafecafe));
12+
constructor() payable {}
13+
function f(uint c) external returns (uint) {
14+
if (c == 0) i.a();
15+
else if (c == 1) i.b();
16+
else if (c == 2) i.c();
17+
else if (c == 3) i.c{value: 1}();
18+
else if (c == 4) i.x();
19+
else if (c == 5) i.y();
20+
return 1 + c;
21+
}
22+
}
23+
// ====
24+
// bytecodeFormat: >=EOFv1
25+
// ----
26+
// constructor(), 1 ether ->
27+
// gas irOptimized: 88853
28+
// gas irOptimized code: 164400
29+
// gas legacy: 102721
30+
// gas legacy code: 334400
31+
// gas legacyOptimized: 91499
32+
// gas legacyOptimized code: 196400
33+
// f(uint256): 0 -> 1
34+
// f(uint256): 1 -> 2
35+
// f(uint256): 2 -> 3
36+
// f(uint256): 3 -> 4
37+
// f(uint256): 4 -> FAILURE
38+
// f(uint256): 5 -> FAILURE
39+
// f(uint256): 6 -> 7

test/libsolidity/semanticTests/functionCall/external_call_at_construction_time.sol

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ contract C {
1818
}
1919
// ====
2020
// EVMVersion: >=byzantium
21+
// bytecodeFormat: legacy
2122
// ----
2223
// f(uint256): 0 -> FAILURE
2324
// f(uint256): 1 -> FAILURE

test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting.sol

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ contract C {
2020
return 1 + c;
2121
}
2222
}
23+
// ====
24+
// bytecodeFormat: legacy
2325
// ----
2426
// constructor(), 1 ether ->
2527
// gas irOptimized: 88853

test/libsolidity/semanticTests/functionCall/external_call_to_nonexisting_debugstrings.sol

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ contract C {
2323
// ====
2424
// EVMVersion: >=byzantium
2525
// revertStrings: debug
26+
// bytecodeFormat: legacy
2627
// ----
2728
// constructor(), 1 ether ->
2829
// gas irOptimized: 98698

test/libsolidity/semanticTests/functionCall/gas_and_value_basic.sol

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ contract test {
3434
myBal = address(this).balance;
3535
}
3636
}
37+
// ====
38+
// bytecodeFormat: legacy
3739
// ----
3840
// constructor(), 20 wei ->
3941
// gas irOptimized: 120218

test/libsolidity/semanticTests/functionTypes/stack_height_check_on_adding_gas_variable_to_function.sol

+2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ contract C {
1919
return true;
2020
}
2121
}
22+
// ====
23+
// bytecodeFormat: legacy
2224
// ----
2325
// test_function() -> true

test/libsolidity/semanticTests/inlineAssembly/transient_storage_selfdestruct.sol

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ contract D {
3838
}
3939
// ====
4040
// EVMVersion: >=cancun
41+
// bytecodeFormat: legacy
4142
// ----
4243
// constructor() ->
4344
// gas irOptimized: 127596

test/libsolidity/semanticTests/revertStrings/called_contract_has_code.sol

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ contract C {
88
// ====
99
// EVMVersion: >=byzantium
1010
// revertStrings: debug
11+
// bytecodeFormat: legacy
1112
// ----
1213
// g() -> FAILURE, hex"08c379a0", 0x20, 37, "Target contract does not contain", " code"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
contract C {
2+
fallback() external {
3+
revert("abc");
4+
}
5+
6+
function f() public returns (uint s, uint r) {
7+
address x = address(this);
8+
assembly {
9+
mstore(0, 7)
10+
s := extcall(x, 0, 0, 0)
11+
returndatacopy(0, 0, 32)
12+
r := mload(0)
13+
}
14+
}
15+
}
16+
// ====
17+
// bytecodeFormat: >=EOFv1
18+
// ----
19+
// f() -> 0x01, 0x08c379a000000000000000000000000000000000000000000000000000000000

test/libsolidity/semanticTests/reverts/revert_return_area.sol

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ contract C {
1414
}
1515
// ====
1616
// EVMVersion: >=byzantium
17+
// bytecodeFormat: legacy
1718
// ----
1819
// f() -> 0x00, 0x08c379a000000000000000000000000000000000000000000000000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
contract B
2+
{
3+
uint x;
4+
function getBalance() public view returns (uint) {
5+
return address(this).balance * 1000 + x;
6+
}
7+
constructor(uint _x) payable {
8+
x = _x;
9+
}
10+
}
11+
12+
contract A {
13+
function f() public payable returns (uint, uint, uint) {
14+
B x = new B{salt: "abc1", value: 3}(7);
15+
B y = new B{value: 3, salt: "abc2"}(8);
16+
B z = new B{salt: "abc3", value: 3}(9);
17+
return (x.getBalance(), y.getBalance(), z.getBalance());
18+
}
19+
}
20+
// ====
21+
// bytecodeFormat: >=EOFv1
22+
// ----
23+
// f(), 10 ether -> 3007, 3008, 3009

test/libsolidity/semanticTests/saltedCreate/prediction_example.sol

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ contract C {
2424
// ====
2525
// EVMVersion: >=constantinople
2626
// compileViaYul: also
27+
// bytecodeFormat: legacy
2728
// ----
2829
// createDSalted(bytes32,uint256): 42, 64 ->
2930
// gas legacy: 78573

test/libsolidity/semanticTests/saltedCreate/salted_create_with_value.sol

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ contract A {
1919
}
2020
// ====
2121
// EVMVersion: >=constantinople
22+
// bytecodeFormat: legacy
2223
// ----
2324
// f(), 10 ether -> 3007, 3008, 3009
2425
// gas irOptimized: 187022

0 commit comments

Comments
 (0)