diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-02-02 06:17:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-02 06:17:44 +0800 |
commit | 5225a5bb5e9a23657f496e6638146746594e9bf9 (patch) | |
tree | c8cd95b2eb13808f2b6ff3c07c5c70398fcc5cb7 /test/libsolidity | |
parent | c1a675da4f01728784c9b7e1d82665bb8dfbcc99 (diff) | |
parent | ee147e14d392e62dae92d345735ec768bd486633 (diff) | |
download | dexon-solidity-5225a5bb5e9a23657f496e6638146746594e9bf9.tar.gz dexon-solidity-5225a5bb5e9a23657f496e6638146746594e9bf9.tar.zst dexon-solidity-5225a5bb5e9a23657f496e6638146746594e9bf9.zip |
Merge pull request #1630 from ethereum/function-to-address
Explicit external function type to address conversion
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 19 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 36 |
2 files changed, 55 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 4075a016..4924b55d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8462,6 +8462,25 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls) BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(5), u256(6), u256(7))); } +BOOST_AUTO_TEST_CASE(external_function_to_address) +{ + char const* sourceCode = R"( + contract C { + function f() returns (bool) { + return address(this.f) == address(this); + } + function g(function() external cb) returns (address) { + return address(cb); + } + } + )"; + + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(true)); + BOOST_CHECK(callContractFunction("g(function)", fromHex("00000000000000000000000000000000000004226121ff00000000000000000")) == encodeArgs(u160(0x42))); +} + + BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 472067ec..f5768022 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -4725,6 +4725,42 @@ BOOST_AUTO_TEST_CASE(delete_external_function_type_invalid) CHECK_ERROR(text, TypeError, ""); } +BOOST_AUTO_TEST_CASE(external_function_type_to_address) +{ + char const* text = R"( + contract C { + function f() returns (address) { + return address(this.f); + } + } + )"; + CHECK_SUCCESS(text); +} + +BOOST_AUTO_TEST_CASE(internal_function_type_to_address) +{ + char const* text = R"( + contract C { + function f() returns (address) { + return address(f); + } + } + )"; + CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); +} + +BOOST_AUTO_TEST_CASE(external_function_type_to_uint) +{ + char const* text = R"( + contract C { + function f() returns (uint) { + return uint(this.f); + } + } + )"; + CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); +} + BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal) { char const* text = R"( |