diff options
author | chriseth <chris@ethereum.org> | 2018-02-14 12:00:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-14 12:00:41 +0800 |
commit | 3155dd8058672ce8f04bc2c0f2536cb549067d0a (patch) | |
tree | 7ddb56e276c74db30671eb17ffdde5eda027142d /test/libsolidity/ViewPureChecker.cpp | |
parent | c4cbbb054b5ed3b8ceaa21ee5b47b0704762ff40 (diff) | |
parent | ef8292c6bb337d3c4b27836da6732b85021d1c5d (diff) | |
download | dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.tar dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.tar.gz dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.tar.bz2 dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.tar.lz dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.tar.xz dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.tar.zst dexon-solidity-3155dd8058672ce8f04bc2c0f2536cb549067d0a.zip |
Merge pull request #3503 from ethereum/develop
Merge develop into release for v0.4.20.
Diffstat (limited to 'test/libsolidity/ViewPureChecker.cpp')
-rw-r--r-- | test/libsolidity/ViewPureChecker.cpp | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 6353ae8a..3a03c877 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -136,10 +136,12 @@ BOOST_AUTO_TEST_CASE(environment_access) } for (string const& x: pure) { - CHECK_WARNING( + CHECK_WARNING_ALLOW_MULTI( "contract C { function f() view public { var x = " + x + "; x; } }", - "restricted to pure" - ); + (std::vector<std::string>{ + "Function state mutability can be restricted to pure", + "Use of the \"var\" keyword is deprecated." + })); } } @@ -181,10 +183,10 @@ BOOST_AUTO_TEST_CASE(interface) { string text = R"( interface D { - function f() view public; + function f() view external; } contract C is D { - function f() view public {} + function f() view external {} } )"; CHECK_SUCCESS_NO_WARNINGS(text); @@ -282,9 +284,9 @@ BOOST_AUTO_TEST_CASE(builtin_functions) require(this.call()); } function g() pure public { - var x = keccak256("abc"); - var y = sha256("abc"); - var z = ecrecover(1, 2, 3, 4); + bytes32 x = keccak256("abc"); + bytes32 y = sha256("abc"); + address z = ecrecover(1, 2, 3, 4); require(true); assert(true); x; y; z; @@ -324,6 +326,53 @@ BOOST_AUTO_TEST_CASE(function_types) CHECK_SUCCESS_NO_WARNINGS(text); } +BOOST_AUTO_TEST_CASE(selector) +{ + string text = R"( + contract C { + uint public x; + function f() payable public { + } + function g() pure public returns (bytes4) { + return this.f.selector ^ this.x.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + +BOOST_AUTO_TEST_CASE(selector_complex) +{ + string text = R"( + contract C { + function f(C c) pure public returns (C) { + return c; + } + function g() pure public returns (bytes4) { + // By passing `this`, we read from the state, even if f itself is pure. + return f(this).f.selector; + } + } + )"; + CHECK_ERROR(text, TypeError, "reads from the environment or state and thus requires \"view\""); +} + +BOOST_AUTO_TEST_CASE(selector_complex2) +{ + string text = R"( + contract C { + function f() payable public returns (C) { + return this; + } + function g() pure public returns (bytes4) { + C x = C(0x123); + return x.f.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + BOOST_AUTO_TEST_CASE(creation) { string text = R"( |