Browse Source

Ensure that mappings in structs are handled correctly

Substrate storage does not understand solidity mappings, so drop them
from the abi file.

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 4 years ago
parent
commit
039f9eb4cb
2 changed files with 36 additions and 1 deletions
  1. 1 1
      src/abi/substrate.rs
  2. 35 0
      tests/substrate_tests/mappings.rs

+ 1 - 1
src/abi/substrate.rs

@@ -368,7 +368,7 @@ fn gen_abi(contract_no: usize, ns: &ast::Namespace) -> Abi {
         .filter_map(|layout| {
             let var = &ns.contracts[layout.contract_no].variables[layout.var_no];
 
-            if !var.ty.is_mapping() {
+            if !var.ty.contains_mapping(ns) {
                 Some(StorageLayout {
                     name: var.name.to_string(),
                     layout: LayoutField {

+ 35 - 0
tests/substrate_tests/mappings.rs

@@ -180,6 +180,41 @@ fn basic() {
     );
 
     runtime.function("test", Vec::new());
+
+    let mut runtime = build_solidity(
+        r##"
+        contract Test {
+            using TestLib for TestLib.data;
+
+            TestLib.data libdata;
+
+            function contfunc(uint64 num) public {
+                libdata.libfunc(num);
+            }
+        }
+
+        library TestLib {
+            using TestLib for TestLib.data;
+
+            struct pair {
+                uint64 a;
+                uint64 b;
+            }
+
+            struct data {
+                mapping(uint64 => pair) pairmap;
+            }
+
+            function libfunc(data storage self, uint64 value) internal {
+                self.pairmap[self.pairmap[value].a].a = 1;
+                //self.pairmap[self.pairmap[value].b].b = 2;
+            }
+        }
+        "##,
+    );
+
+    runtime.constructor(0, Vec::new());
+    runtime.function("contfunc", 1u64.encode());
 }
 
 #[test]