Tests for suffixes making external calls

This commit is contained in:
Kamil Śliwak 2023-03-22 13:15:58 +01:00
parent 08d54f274a
commit 4adfb76467
2 changed files with 78 additions and 0 deletions

View File

@ -0,0 +1,37 @@
function suffix(int32 x) pure suffix returns (int32) {
return loadNegator().negate(x);
}
interface INegator {
function negate(int32) external pure returns (int32);
}
contract Negator is INegator {
function negate(int32 x) external pure override returns (int32) {
return -x;
}
}
function storeNegator(INegator negator) pure {
assembly {
// this test would also work without assembly if we could hard-code an address here.
mstore(0, negator)
}
}
function loadNegator() pure returns (INegator negator) {
assembly {
negator := mload(0)
}
}
contract C {
function testSuffix() public returns (int32) {
storeNegator(new Negator());
return 10 suffix;
}
}
// ----
// testSuffix() -> -10
// gas legacy: 131793

View File

@ -0,0 +1,41 @@
function suffix(int32 x) pure suffix returns (int32) {
return loadNegator().negate(x);
}
interface INegatorPure {
function negate(int32) external pure returns (int32);
}
interface INegatorView {
function negate(int32) external view returns (int32);
}
contract Negator is INegatorView {
function negate(int32 x) external view override returns (int32) {
return -x;
}
}
function storeNegator(INegatorView negator) pure {
assembly {
// this test would also work without assembly if we could hard-code an address here.
mstore(0, negator)
}
}
function loadNegator() pure returns (INegatorPure negator) {
assembly {
negator := mload(0)
}
}
contract C {
function testSuffix() public returns (int32) {
storeNegator(new Negator());
return 10 suffix;
}
}
// ----
// testSuffix() -> -10
// gas legacy: 131793