diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-14 00:35:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-14 00:35:48 +0800 |
commit | 5c9dbd50839ac153f367ce69abb10dd22877842e (patch) | |
tree | 98e3b524aaacdafb2c30feb04567159591bad562 /test/libsolidity | |
parent | 3f3bcc4f8a0d12e9b92d6b63e7cfd92cbbfa775d (diff) | |
parent | 8b166c36369d0d1b39a4c537bc6ee8a08f3c6e5a (diff) | |
download | dexon-solidity-5c9dbd50839ac153f367ce69abb10dd22877842e.tar.gz dexon-solidity-5c9dbd50839ac153f367ce69abb10dd22877842e.tar.zst dexon-solidity-5c9dbd50839ac153f367ce69abb10dd22877842e.zip |
Merge pull request #2473 from ethereum/functiontype-sig
Add .selector member on function types
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 24 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 81 |
2 files changed, 105 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index fa4d675c..ea924fcb 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10051,6 +10051,30 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value) BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1))); } +BOOST_AUTO_TEST_CASE(function_types_sig) +{ + char const* sourceCode = R"( + contract C { + function f() returns (bytes4) { + return this.f.selector; + } + function g() returns (bytes4) { + function () external returns (bytes4) fun = this.f; + return fun.selector; + } + function h() returns (bytes4) { + function () external returns (bytes4) fun = this.f; + var funvar = fun; + return funvar.selector; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); + BOOST_CHECK(callContractFunction("g()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); + BOOST_CHECK(callContractFunction("h()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes()))); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 04d3d2d3..d3c9802b 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6285,6 +6285,87 @@ BOOST_AUTO_TEST_CASE(modifiers_access_storage_pointer) CHECK_SUCCESS_NO_WARNINGS(text); } +BOOST_AUTO_TEST_CASE(function_types_sig) +{ + char const* text = R"( + contract C { + function f() returns (bytes4) { + return f.selector; + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); + text = R"( + contract C { + function g() internal { + } + function f() returns (bytes4) { + return g.selector; + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); + text = R"( + contract C { + function f() returns (bytes4) { + function () g; + return g.selector; + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"selector\" not found"); + text = R"( + contract C { + function f() returns (bytes4) { + return this.f.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function f() external returns (bytes4) { + return this.f.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function h() external { + } + function f() external returns (bytes4) { + var g = this.h; + return g.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function h() external { + } + function f() external returns (bytes4) { + function () external g = this.h; + return g.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function h() external { + } + function f() external returns (bytes4) { + function () external g = this.h; + var i = g; + return i.selector; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + BOOST_AUTO_TEST_CASE(using_this_in_constructor) { char const* text = R"( |