diff options
author | chriseth <chris@ethereum.org> | 2018-03-22 01:38:06 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-04-12 06:10:25 +0800 |
commit | c4a6a63f362f478414ac886ed6e5e159038460aa (patch) | |
tree | 8c3f620b7bc4299aa5000df187a2d7dc038aeea4 /test/libsolidity/syntaxTests | |
parent | 44c0d7ca5e1d97027e4f1e24fb02fd805eda578d (diff) | |
download | dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.tar dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.tar.gz dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.tar.bz2 dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.tar.lz dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.tar.xz dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.tar.zst dexon-solidity-c4a6a63f362f478414ac886ed6e5e159038460aa.zip |
Tests for view and pure.
Diffstat (limited to 'test/libsolidity/syntaxTests')
-rw-r--r-- | test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol | 8 | ||||
-rw-r--r-- | test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol | 36 |
2 files changed, 44 insertions, 0 deletions
diff --git a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol new file mode 100644 index 00000000..ca7db42e --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode.sol @@ -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); + } +} diff --git a/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol new file mode 100644 index 00000000..547362c3 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPure/view_pure_abi_encode_arguments.sol @@ -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 |