Skip to content

Commit

Permalink
set storage hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Sep 2, 2024
1 parent 6b18d42 commit 59b2d13
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mx-semantics/main/accounts/storage-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module MX-STORAGE-HOOKS
rule MX#storageLoad(mxStringValue(Key:String), Destination:MxValue )
=> storageLoad(getCallee(), Key, Destination)
rule MX#storageStore(mxStringValue(Key:String), Value:MxWrappedValue)
=> storageStore(getCallee(), Key, Value)
endmodule
```
29 changes: 29 additions & 0 deletions mx-semantics/main/accounts/storage-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module MX-STORAGE-TOOLS-SYNTAX
imports STRING-SYNTAX
syntax MxInstructions ::= storageLoad(address: String, key: String, destination: MxValue)
| storageStore(address: String, key: String, value: MxWrappedValue)
endmodule
module MX-STORAGE-TOOLS
Expand Down Expand Up @@ -34,6 +35,34 @@ module MX-STORAGE-TOOLS
<mx-account-address> Address </mx-account-address>
[priority(100)]
rule
<k>
storageStore(... address: Address:String, key: Key:String, value: Value:MxWrappedValue)
=> .K
...
</k>
<mx-account-address> Address </mx-account-address>
<mx-account-storage-key> Key </mx-account-storage-key>
<mx-account-storage-value> _ => Value </mx-account-storage-value>
[priority(50)]
rule
<k>
storageStore(... address: Address:String, key: Key:String, value: Value:MxWrappedValue)
=> .K
...
</k>
<mx-account-address> Address </mx-account-address>
<mx-account-storage>
.Bag =>
<mx-account-storage-item>
<mx-account-storage-key> Key </mx-account-storage-key>
<mx-account-storage-value> Value </mx-account-storage-value>
</mx-account-storage-item>
...
</mx-account-storage>
[priority(100)]
endmodule
```
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/mx/storage/set-empty-storage.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
addAccount("Owner");
setCallee("Owner");

push wrappedMx(mxStringValue("Hello"));
push mxStringValue("MyKey");
call 2 MX#storageStore;

push mxIntValue(12);
push mxStringValue("MyKey");
call 2 MX#storageLoad;
push_store_data;
check_eq mxIntValue(12);
check_eq wrappedMx(mxStringValue("Hello"))
14 changes: 14 additions & 0 deletions tests/mx/storage/set-existing-storage.mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
addAccount("Owner");
setCallee("Owner");
setStorage("Owner", "MyKey", mxStringValue("Hello"));

push wrappedMx(mxStringValue("World"));
push mxStringValue("MyKey");
call 2 MX#storageStore;

push mxIntValue(12);
push mxStringValue("MyKey");
call 2 MX#storageLoad;
push_store_data;
check_eq mxIntValue(12);
check_eq wrappedMx(mxStringValue("World"))

0 comments on commit 59b2d13

Please sign in to comment.