Tests for view and pure.

This commit is contained in:
chriseth 2018-03-21 18:38:06 +01:00
parent 44c0d7ca5e
commit c4a6a63f36
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,8 @@
contract C {
function f() pure public returns (bytes r) {
r = abi.encode(1, 2);
r = abi.encodePacked(f());
r = abi.encodeWithSelector(0x12345678, 1);
r = abi.encodeWithSignature("f(uint256)", 4);
}
}

View File

@ -0,0 +1,36 @@
contract C {
uint x;
function gView() public view returns (uint) { return x; }
function gNonPayable() public returns (uint) { x = 4; return 0; }
function f1() view public returns (bytes) {
return abi.encode(gView());
}
function f2() view public returns (bytes) {
return abi.encodePacked(gView());
}
function f3() view public returns (bytes) {
return abi.encodeWithSelector(0x12345678, gView());
}
function f4() view public returns (bytes) {
return abi.encodeWithSignature("f(uint256)", gView());
}
function g1() public returns (bytes) {
return abi.encode(gNonPayable());
}
function g2() public returns (bytes) {
return abi.encodePacked(gNonPayable());
}
function g3() public returns (bytes) {
return abi.encodeWithSelector(0x12345678, gNonPayable());
}
function g4() public returns (bytes) {
return abi.encodeWithSignature("f(uint256)", gNonPayable());
}
// This will generate the only warning.
function check() public returns (bytes) {
return abi.encode(2);
}
}
// ----
// Warning: (1044-1121): Function state mutability can be restricted to pure