solidity/test/libsolidity/semanticTests/libraries/library_delegatecall_guard_view_staticcall.sol

32 lines
862 B
Solidity
Raw Normal View History

contract D {
uint public x;
2020-06-23 12:14:24 +00:00
constructor() { x = 42; }
}
library L {
function f(D d) public view returns (uint256) {
return d.x();
}
}
contract C {
D d;
2020-06-23 12:14:24 +00:00
constructor() { d = new D(); }
function f() public view returns (uint256) {
return L.f(d);
}
function g() public returns (bool, uint256) {
(bool success, bytes memory data) = address(L).delegatecall(abi.encodeWithSelector(L.f.selector, d));
return (success, success ? abi.decode(data,(uint256)) : 0);
}
function h() public returns (bool, uint256) {
(bool success, bytes memory data) = address(L).call(abi.encodeWithSelector(L.f.selector, d));
return (success, success ? abi.decode(data,(uint256)) : 0);
}
}
// ====
// EVMVersion: >homestead
// ----
// library: L
// f() -> 42
// g() -> true, 42
// h() -> true, 42