mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests
This commit is contained in:
parent
cdf243a9af
commit
1a9e66f4b0
@ -0,0 +1,22 @@
|
|||||||
|
contract C {
|
||||||
|
uint32[] s;
|
||||||
|
constructor()
|
||||||
|
{
|
||||||
|
s.push();
|
||||||
|
s.push();
|
||||||
|
}
|
||||||
|
function f() external returns (uint)
|
||||||
|
{
|
||||||
|
(s[1], s) = (4, [0]);
|
||||||
|
s = [0];
|
||||||
|
s.push();
|
||||||
|
return s[1];
|
||||||
|
// used to return 4 via IR.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// constructor()
|
||||||
|
// gas irOptimized: 237351
|
||||||
|
// gas legacy: 221315
|
||||||
|
// gas legacyOptimized: 185247
|
||||||
|
// f() -> 0
|
@ -0,0 +1,56 @@
|
|||||||
|
contract C {
|
||||||
|
string log;
|
||||||
|
function() external[] fs;
|
||||||
|
function() external[] gs;
|
||||||
|
|
||||||
|
function a() external {
|
||||||
|
log = string.concat(log, "[a called]");
|
||||||
|
}
|
||||||
|
function b() external {
|
||||||
|
log = string.concat(log, "[b called]");
|
||||||
|
}
|
||||||
|
|
||||||
|
function f(function() external[] calldata x) external {
|
||||||
|
fs = x;
|
||||||
|
}
|
||||||
|
function g(function() external[] memory x) public {
|
||||||
|
fs = x;
|
||||||
|
}
|
||||||
|
function test() external returns (string memory) {
|
||||||
|
log = "";
|
||||||
|
function() external[] memory x = new function() external[](2);
|
||||||
|
x[0] = this.a;
|
||||||
|
x[1] = this.b;
|
||||||
|
this.f(x);
|
||||||
|
fs[0]();
|
||||||
|
fs[1]();
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
function test2() external returns (string memory) {
|
||||||
|
log = "";
|
||||||
|
function() external[] memory x = new function() external[](2);
|
||||||
|
x[0] = this.b;
|
||||||
|
x[1] = this.a;
|
||||||
|
g(x);
|
||||||
|
fs[0]();
|
||||||
|
fs[1]();
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
function test3() external returns (string memory) {
|
||||||
|
log = "";
|
||||||
|
gs = fs;
|
||||||
|
gs[0]();
|
||||||
|
gs[1]();
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 0x20, 0x14, "[a called][b called]"
|
||||||
|
// gas irOptimized: 116724
|
||||||
|
// gas legacy: 120707
|
||||||
|
// gas legacyOptimized: 119241
|
||||||
|
// test2() -> 0x20, 0x14, "[b called][a called]"
|
||||||
|
// test3() -> 0x20, 0x14, "[b called][a called]"
|
||||||
|
// gas irOptimized: 103304
|
||||||
|
// gas legacy: 104648
|
||||||
|
// gas legacyOptimized: 104075
|
Loading…
Reference in New Issue
Block a user