mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests for suffixes making external calls
This commit is contained in:
parent
08d54f274a
commit
4adfb76467
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user