Przeglądaj źródła

Fix cfg for modifiers

Signed-off-by: Iwan Waitusenok <sleepplease@protonmail.ch>
Iwan Waitusenok 4 lat temu
rodzic
commit
0f60e1a813
2 zmienionych plików z 32 dodań i 1 usunięć
  1. 1 1
      src/codegen/cfg.rs
  2. 31 0
      tests/substrate_tests/modifier.rs

+ 1 - 1
src/codegen/cfg.rs

@@ -1566,7 +1566,7 @@ pub fn generate_modifier_dispatch(
     for stmt in &modifier.body {
         statement(
             stmt,
-            func,
+            modifier,
             &mut cfg,
             contract_no,
             ns,

+ 31 - 0
tests/substrate_tests/modifier.rs

@@ -178,6 +178,37 @@ fn function_modifier() {
 
 #[test]
 fn chain() {
+    let mut runtime = build_solidity(
+        r#"
+        contract c {
+            uint16 public var;
+
+            modifier foo() { 
+                bool boom = true;
+                if (boom) {
+                    _; 
+                }
+            }
+
+            function bar() foo() public {
+                var = 7;
+            }
+        }"#,
+    );
+
+    runtime.constructor(0, Vec::new());
+
+    let slot = [0u8; 32];
+
+    assert_eq!(runtime.store.get(&(runtime.vm.address, slot)), None);
+
+    runtime.function("bar", Vec::new());
+
+    assert_eq!(
+        runtime.store.get(&(runtime.vm.address, slot)).unwrap(),
+        &vec!(7, 0)
+    );
+
     let mut runtime = build_solidity(
         r##"
         contract c {