aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-11-08 18:22:57 +0800
committerchriseth <chris@ethereum.org>2018-11-26 23:31:46 +0800
commit30e6f8d3fb9a16dc1e07367c9010aabe3577e2f1 (patch)
tree0d250ea55121d0a3f9805d99a8b20d030dd60a1e /test/libsolidity/SolidityEndToEndTest.cpp
parentf6d8810103c762d1f5a41bf1c29d33b771cfed50 (diff)
downloaddexon-solidity-30e6f8d3fb9a16dc1e07367c9010aabe3577e2f1.tar.gz
dexon-solidity-30e6f8d3fb9a16dc1e07367c9010aabe3577e2f1.tar.zst
dexon-solidity-30e6f8d3fb9a16dc1e07367c9010aabe3577e2f1.zip
Allow mapping arguments for public and external library functions.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index e9667483..145783a8 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -8658,6 +8658,90 @@ BOOST_AUTO_TEST_CASE(mapping_returns_in_library_named)
ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(17)));
}
+BOOST_AUTO_TEST_CASE(using_library_mappings_public)
+{
+ char const* sourceCode = R"(
+ library Lib {
+ function set(mapping(uint => uint) storage m, uint key, uint value) public
+ {
+ m[key] = value;
+ }
+ }
+ contract Test {
+ mapping(uint => uint) m1;
+ mapping(uint => uint) m2;
+ function f() public returns (uint, uint, uint, uint, uint, uint)
+ {
+ Lib.set(m1, 0, 1);
+ Lib.set(m1, 2, 42);
+ Lib.set(m2, 0, 23);
+ Lib.set(m2, 2, 99);
+ return (m1[0], m1[1], m1[2], m2[0], m2[1], m2[2]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99)));
+}
+
+BOOST_AUTO_TEST_CASE(using_library_mappings_external)
+{
+ char const* libSourceCode = R"(
+ library Lib {
+ function set(mapping(uint => uint) storage m, uint key, uint value) external
+ {
+ m[key] = value * 2;
+ }
+ }
+ )";
+ char const* sourceCode = R"(
+ library Lib {
+ function set(mapping(uint => uint) storage m, uint key, uint value) external;
+ }
+ contract Test {
+ mapping(uint => uint) m1;
+ mapping(uint => uint) m2;
+ function f() public returns (uint, uint, uint, uint, uint, uint)
+ {
+ Lib.set(m1, 0, 1);
+ Lib.set(m1, 2, 42);
+ Lib.set(m2, 0, 23);
+ Lib.set(m2, 2, 99);
+ return (m1[0], m1[1], m1[2], m2[0], m2[1], m2[2]);
+ }
+ }
+ )";
+ compileAndRun(libSourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(2), u256(0), u256(84), u256(46), u256(0), u256(198)));
+}
+
+BOOST_AUTO_TEST_CASE(using_library_mappings_return)
+{
+ char const* sourceCode = R"(
+ library Lib {
+ function choose(mapping(uint => mapping(uint => uint)) storage m, uint key) external returns (mapping(uint => uint) storage) {
+ return m[key];
+ }
+ }
+ contract Test {
+ mapping(uint => mapping(uint => uint)) m;
+ function f() public returns (uint, uint, uint, uint, uint, uint)
+ {
+ Lib.choose(m, 0)[0] = 1;
+ Lib.choose(m, 0)[2] = 42;
+ Lib.choose(m, 1)[0] = 23;
+ Lib.choose(m, 1)[2] = 99;
+ return (m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(1), u256(0), u256(42), u256(23), u256(0), u256(99)));
+}
+
BOOST_AUTO_TEST_CASE(using_library_structs)
{
char const* sourceCode = R"(