diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-08-10 21:56:29 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-08-13 21:50:22 +0800 |
commit | a9f31da41146221c674356d5678030616110d471 (patch) | |
tree | 9027bbe7082cd658b5a0763e1b5ae4d99cca419d /test | |
parent | 57ada1d69e311f847b4581a0e487aebd1b0e468f (diff) | |
download | dexon-solidity-a9f31da41146221c674356d5678030616110d471.tar dexon-solidity-a9f31da41146221c674356d5678030616110d471.tar.gz dexon-solidity-a9f31da41146221c674356d5678030616110d471.tar.bz2 dexon-solidity-a9f31da41146221c674356d5678030616110d471.tar.lz dexon-solidity-a9f31da41146221c674356d5678030616110d471.tar.xz dexon-solidity-a9f31da41146221c674356d5678030616110d471.tar.zst dexon-solidity-a9f31da41146221c674356d5678030616110d471.zip |
Allow mapping arguments and return values in all internal functions.
Diffstat (limited to 'test')
4 files changed, 56 insertions, 9 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cc89a307..09e94028 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1543,6 +1543,62 @@ BOOST_AUTO_TEST_CASE(mapping_local_compound_assignment) ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21))); } +BOOST_AUTO_TEST_CASE(mapping_internal_argument) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) a; + mapping(uint8 => uint8) b; + function set_internal(mapping(uint8 => uint8) storage m, uint8 key, uint8 value) internal returns (uint8) { + uint8 oldValue = m[key]; + m[key] = value; + return oldValue; + } + function set(uint8 key, uint8 value_a, uint8 value_b) public returns (uint8 old_a, uint8 old_b) { + old_a = set_internal(a, key, value_a); + old_b = set_internal(b, key, value_b); + } + function get(uint8 key) public returns (uint8, uint8) { + return (a[key], b[key]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(21), byte(42)), encodeArgs(byte(0), byte(0))); + ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(42))); + ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(10), byte(11)), encodeArgs(byte(21), byte(42))); + ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(11))); +} + +BOOST_AUTO_TEST_CASE(mapping_internal_return) +{ + char const* sourceCode = R"( + contract test { + mapping(uint8 => uint8) a; + mapping(uint8 => uint8) b; + function f() internal returns (mapping(uint8 => uint8) storage r) { + r = a; + r[1] = 42; + r = b; + r[1] = 84; + } + function g() public returns (uint8, uint8, uint8, uint8, uint8, uint8) { + f()[2] = 21; + return (a[0], a[1], a[2], b[0], b[1], b[2]); + } + function h() public returns (uint8, uint8, uint8, uint8, uint8, uint8) { + mapping(uint8 => uint8) storage m = f(); + m[2] = 17; + return (a[0], a[1], a[2], b[0], b[1], b[2]); + } + } + )"; + compileAndRun(sourceCode); + + ABI_CHECK(callContractFunction("g()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (21))); + ABI_CHECK(callContractFunction("h()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (17))); +} BOOST_AUTO_TEST_CASE(structs) { diff --git a/test/libsolidity/syntaxTests/types/mapping/argument_internal.sol b/test/libsolidity/syntaxTests/types/mapping/argument_internal.sol index 395f5808..3c021515 100644 --- a/test/libsolidity/syntaxTests/types/mapping/argument_internal.sol +++ b/test/libsolidity/syntaxTests/types/mapping/argument_internal.sol @@ -1,7 +1,5 @@ -// This is expected to fail now, but may work in the future. contract C { function f(mapping(uint => uint) storage) internal pure { } } // ---- -// TypeError: (89-110): Type is required to live outside storage. diff --git a/test/libsolidity/syntaxTests/types/mapping/argument_private.sol b/test/libsolidity/syntaxTests/types/mapping/argument_private.sol index 0360514e..63733d71 100644 --- a/test/libsolidity/syntaxTests/types/mapping/argument_private.sol +++ b/test/libsolidity/syntaxTests/types/mapping/argument_private.sol @@ -1,7 +1,5 @@ -// This is expected to fail now, but may work in the future. contract C { function f(mapping(uint => uint) storage) private pure { } } // ---- -// TypeError: (89-110): Type is required to live outside storage. diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol index a46003f8..4912836e 100644 --- a/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol +++ b/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol @@ -1,4 +1,3 @@ -// This should be allowed in a future release. contract C { mapping(uint=>uint) m; function f() internal view returns (mapping(uint=>uint) storage) { @@ -15,7 +14,3 @@ contract C { } } // ---- -// TypeError: (127-146): Type is required to live outside storage. -// TypeError: (221-240): Type is required to live outside storage. -// TypeError: (316-345): Type is required to live outside storage. -// TypeError: (409-438): Type is required to live outside storage. |