From b545987ec7916209f0a1dfe196d78b49cdf2ddae Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 31 Jan 2018 16:42:46 +0000 Subject: Issue warning for using public visibility for interface functions --- test/libsolidity/ViewPureChecker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/libsolidity/ViewPureChecker.cpp') diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 6353ae8a..debeb4dc 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -181,10 +181,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); -- cgit v1.2.3 From 3ddbf1617fb8d981131d2df5a48fa0a2615f83a2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 12 Feb 2018 22:09:14 +0000 Subject: Do not use var where not neccessary in tests --- test/libsolidity/ViewPureChecker.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/ViewPureChecker.cpp') diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index debeb4dc..837f9aa9 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -282,9 +282,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; -- cgit v1.2.3 From 573aa01fd2a208a119a77fe75129d76a59392abc Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 12 Feb 2018 22:26:13 +0000 Subject: Adjust tests for multiple errors with the var keyword --- test/libsolidity/ViewPureChecker.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/libsolidity/ViewPureChecker.cpp') diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 837f9aa9..e91e713c 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{ + "Function state mutability can be restricted to pure", + "Use of the \"var\" keyword is deprecated." + })); } } -- cgit v1.2.3 From 5916cf1e0ace5d9855af4d785c22c742cf106b8a Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 13 Feb 2018 09:49:50 +0100 Subject: Allow `this.f.selector` to be pure. --- test/libsolidity/ViewPureChecker.cpp | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test/libsolidity/ViewPureChecker.cpp') diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index e91e713c..0fee95c5 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -326,6 +326,52 @@ BOOST_AUTO_TEST_CASE(function_types) CHECK_SUCCESS_NO_WARNINGS(text); } +BOOST_AUTO_TEST_CASE(selector) +{ + string text = R"( + contract C { + function f() payable public { + } + function g() pure public returns (bytes4) { + return this.f.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"( -- cgit v1.2.3 From aea9e7fe549d93436a1eb355258ea1b11b5dfb22 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 13 Feb 2018 12:03:02 +0100 Subject: Add tests for selectors for public variables. --- test/libsolidity/ViewPureChecker.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/libsolidity/ViewPureChecker.cpp') diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 0fee95c5..3a03c877 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -330,10 +330,11 @@ 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; + return this.f.selector ^ this.x.selector; } } )"; -- cgit v1.2.3