diff options
author | chriseth <chris@ethereum.org> | 2018-11-26 23:50:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-26 23:50:40 +0800 |
commit | f937896727d85dcdbb60783d10f9cea1eaf9f925 (patch) | |
tree | 9d202b2e05908be6d6b01d4813757ac2a5b2751e /test/libsolidity/SolidityEndToEndTest.cpp | |
parent | f6d8810103c762d1f5a41bf1c29d33b771cfed50 (diff) | |
parent | 597174119a5f8ab03286c58581e7bf5ec52c14dc (diff) | |
download | dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.tar dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.tar.gz dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.tar.bz2 dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.tar.lz dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.tar.xz dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.tar.zst dexon-solidity-f937896727d85dcdbb60783d10f9cea1eaf9f925.zip |
Merge pull request #5445 from ethereum/publicExternalOverwrite
Allow overwriting external functions (with ``calldata`` arguments) with public functions (with ``memory`` arguments)
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index e9667483..c34a1399 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -8207,6 +8207,58 @@ BOOST_AUTO_TEST_CASE(inherited_function) { ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(1))); } +BOOST_AUTO_TEST_CASE(inherited_function_calldata_memory) { + char const* sourceCode = R"( + contract A { function f(uint[] calldata a) external returns (uint) { return a[0]; } } + contract B is A { + function f(uint[] memory a) public returns (uint) { return a[1]; } + function g() public returns (uint) { + uint[] memory m = new uint[](2); + m[0] = 42; + m[1] = 23; + return A(this).f(m); + } + } + )"; + + compileAndRun(sourceCode, 0, "B"); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(23))); +} + +BOOST_AUTO_TEST_CASE(inherited_function_calldata_memory_interface) { + char const* sourceCode = R"( + interface I { function f(uint[] calldata a) external returns (uint); } + contract A is I { function f(uint[] memory a) public returns (uint) { return 42; } } + contract B { + function f(uint[] memory a) public returns (uint) { return a[1]; } + function g() public returns (uint) { + I i = I(new A()); + return i.f(new uint[](2)); + } + } + )"; + + compileAndRun(sourceCode, 0, "B"); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(42))); +} + +BOOST_AUTO_TEST_CASE(inherited_function_calldata_calldata_interface) { + char const* sourceCode = R"( + interface I { function f(uint[] calldata a) external returns (uint); } + contract A is I { function f(uint[] calldata a) external returns (uint) { return 42; } } + contract B { + function f(uint[] memory a) public returns (uint) { return a[1]; } + function g() public returns (uint) { + I i = I(new A()); + return i.f(new uint[](2)); + } + } + )"; + + compileAndRun(sourceCode, 0, "B"); + ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(42))); +} + BOOST_AUTO_TEST_CASE(inherited_function_from_a_library) { char const* sourceCode = R"( library A { function f() internal returns (uint) { return 1; } } |