solidity/test/libsolidity/semanticTests/various/address_code.sol
2021-11-15 16:32:45 +01:00

27 lines
765 B
Solidity

contract C {
bytes public initCode;
constructor() {
// This should catch problems, but lets also test the case the optimiser is buggy.
assert(address(this).code.length == 0);
initCode = address(this).code;
}
// To avoid dependency on exact length.
function f() public view returns (bool) { return address(this).code.length > 400; }
function g() public view returns (uint) { return address(0).code.length; }
function h() public view returns (uint) { return address(1).code.length; }
}
// ====
// compileToEwasm: also
// compileViaYul: also
// ----
// constructor() ->
// gas irOptimized: 199687
// gas legacy: 241124
// gas legacyOptimized: 155549
// initCode() -> 0x20, 0
// f() -> true
// g() -> 0
// h() -> 0