aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp30
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/array_argument_external.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/array_argument_internal.sol5
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/array_argument_private.sol5
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/array_argument_public.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/library_array_argument_external.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/library_array_argument_internal.sol4
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/library_array_argument_private.sol4
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/library_array_argument_public.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/mapping_array_return_external.sol6
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/mapping_array_return_internal.sol16
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/mapping_array_return_public.sol6
12 files changed, 100 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 09e94028..a978a654 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -1571,6 +1571,36 @@ BOOST_AUTO_TEST_CASE(mapping_internal_argument)
ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(11)));
}
+BOOST_AUTO_TEST_CASE(mapping_array_internal_argument)
+{
+ char const* sourceCode = R"(
+ contract test {
+ mapping(uint8 => uint8)[2] a;
+ mapping(uint8 => uint8)[2] b;
+ function set_internal(mapping(uint8 => uint8)[2] storage m, uint8 key, uint8 value1, uint8 value2) internal returns (uint8, uint8) {
+ uint8 oldValue1 = m[0][key];
+ uint8 oldValue2 = m[1][key];
+ m[0][key] = value1;
+ m[1][key] = value2;
+ return (oldValue1, oldValue2);
+ }
+ function set(uint8 key, uint8 value_a1, uint8 value_a2, uint8 value_b1, uint8 value_b2) public returns (uint8 old_a1, uint8 old_a2, uint8 old_b1, uint8 old_b2) {
+ (old_a1, old_a2) = set_internal(a, key, value_a1, value_a2);
+ (old_b1, old_b2) = set_internal(b, key, value_b1, value_b2);
+ }
+ function get(uint8 key) public returns (uint8, uint8, uint8, uint8) {
+ return (a[0][key], a[1][key], b[0][key], b[1][key]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(21), byte(22), byte(42), byte(43)), encodeArgs(byte(0), byte(0), byte(0), byte(0)));
+ ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(22), byte(42), byte(43)));
+ ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(10), byte(30), byte(11), byte(31)), encodeArgs(byte(21), byte(22), byte(42), byte(43)));
+ ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(30), byte(11), byte(31)));
+}
+
BOOST_AUTO_TEST_CASE(mapping_internal_return)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/syntaxTests/types/mapping/array_argument_external.sol b/test/libsolidity/syntaxTests/types/mapping/array_argument_external.sol
new file mode 100644
index 00000000..8dea6907
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/array_argument_external.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f(mapping(uint => uint)[] storage) external pure {
+ }
+}
+// ----
+// TypeError: (28-51): Location has to be calldata for external functions (remove the "memory" or "storage" keyword).
diff --git a/test/libsolidity/syntaxTests/types/mapping/array_argument_internal.sol b/test/libsolidity/syntaxTests/types/mapping/array_argument_internal.sol
new file mode 100644
index 00000000..352d0982
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/array_argument_internal.sol
@@ -0,0 +1,5 @@
+contract C {
+ function f(mapping(uint => uint)[] storage) internal pure {
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/mapping/array_argument_private.sol b/test/libsolidity/syntaxTests/types/mapping/array_argument_private.sol
new file mode 100644
index 00000000..332dbe6c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/array_argument_private.sol
@@ -0,0 +1,5 @@
+contract C {
+ function f(mapping(uint => uint)[] storage) private pure {
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/mapping/array_argument_public.sol b/test/libsolidity/syntaxTests/types/mapping/array_argument_public.sol
new file mode 100644
index 00000000..69dcec01
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/array_argument_public.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f(mapping(uint => uint)[] storage) public pure {
+ }
+}
+// ----
+// TypeError: (28-51): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword).
diff --git a/test/libsolidity/syntaxTests/types/mapping/library_array_argument_external.sol b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_external.sol
new file mode 100644
index 00000000..f5691675
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_external.sol
@@ -0,0 +1,6 @@
+library L {
+ function f(mapping(uint => uint)[] storage) external pure {
+ }
+}
+// ----
+// TypeError: (27-50): Type is required to live outside storage.
diff --git a/test/libsolidity/syntaxTests/types/mapping/library_array_argument_internal.sol b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_internal.sol
new file mode 100644
index 00000000..55c1cea0
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_internal.sol
@@ -0,0 +1,4 @@
+library L {
+ function f(mapping(uint => uint)[] storage) internal pure {
+ }
+}
diff --git a/test/libsolidity/syntaxTests/types/mapping/library_array_argument_private.sol b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_private.sol
new file mode 100644
index 00000000..d37d6504
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_private.sol
@@ -0,0 +1,4 @@
+library L {
+ function f(mapping(uint => uint)[] storage) private pure {
+ }
+}
diff --git a/test/libsolidity/syntaxTests/types/mapping/library_array_argument_public.sol b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_public.sol
new file mode 100644
index 00000000..bb06d4bc
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/library_array_argument_public.sol
@@ -0,0 +1,6 @@
+library L {
+ function f(mapping(uint => uint)[] storage) public pure {
+ }
+}
+// ----
+// TypeError: (27-50): Type is required to live outside storage.
diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_external.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_external.sol
new file mode 100644
index 00000000..dbe030fb
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_external.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() external pure returns (mapping(uint=>uint)[] storage m) {
+ }
+}
+// ----
+// TypeError: (53-84): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword).
diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_internal.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_internal.sol
new file mode 100644
index 00000000..8837c745
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_internal.sol
@@ -0,0 +1,16 @@
+contract C {
+ mapping(uint=>uint)[] m;
+ function f() internal view returns (mapping(uint=>uint)[] storage) {
+ return m;
+ }
+ function g() private view returns (mapping(uint=>uint)[] storage) {
+ return m;
+ }
+ function h() internal view returns (mapping(uint=>uint)[] storage r) {
+ r = m;
+ }
+ function i() private view returns (mapping(uint=>uint)[] storage r) {
+ (r,r) = (m,m);
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_public.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_public.sol
new file mode 100644
index 00000000..7dfecf19
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/mapping_array_return_public.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() public pure returns (mapping(uint=>uint)[] storage m) {
+ }
+}
+// ----
+// TypeError: (51-82): Location has to be memory for publicly visible functions (remove the "storage" or "calldata" keyword).