Skip to content

Commit

Permalink
Storage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta authored and Virgil Serbanuta committed Sep 10, 2024
1 parent 8632c37 commit 89754c9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions mx-rust-semantics/test/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module MX-RUST-EXECUTION-TEST-CONFIGURATION
<mx-rust-test>
<rust-test/>
<mx-test/>
<test-named> .Map </test-named>
</mx-rust-test>
endmodule
Expand Down
41 changes: 41 additions & 0 deletions mx-rust-semantics/test/execution.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
```k
module MX-RUST-TESTING-PARSING-SYNTAX
imports INT-SYNTAX
imports MX-TEST-EXECUTION-PARSING-SYNTAX
imports RUST-EXECUTION-TEST-PARSING-SYNTAX
imports RUST-SHARED-SYNTAX
imports RUST-VALUE-SYNTAX
imports STRING-SYNTAX
syntax MxRustTest ::= ExecutionTest
syntax ExecutionItem ::= "set_named" String
| "push_named" String
| "get_bigint_from_struct"
| "check_eq" Int
| TestInstruction
endmodule
module MX-RUST-TEST
imports private COMMON-K-CELL
imports private MX-RUST-EXECUTION-TEST-CONFIGURATION
imports private MX-RUST-TESTING-PARSING-SYNTAX
imports private RUST-EXECUTION-CONFIGURATION
rule
<k> set_named Name:String => .K ... </k>
<test-stack> ListItem(Value) => .List ... </test-stack>
<test-named> M:Map => M[Name <- Value] </test-named>
rule
<k> push_named Name:String => .K ... </k>
<test-stack> .List => ListItem(Value) ... </test-stack>
<test-named> Name |-> Value ... </test-named>
rule
<k>
ptrValue
( _
, struct
( #token("BigUint", "Identifier")
, #token("mx_biguint_id", "Identifier"):Identifier |-> BigUintIdId _:Map
)
)
~> get_bigint_from_struct ; Test:ExecutionTest
=> push mxIntValue(MInt2Unsigned(BigUintId))
~> get_big_int
~> Test
...
</k>
<values> BigUintIdId |-> i32(BigUintId:MInt{32}) ... </values>
endmodule
```
12 changes: 12 additions & 0 deletions tests/mx-rust/storage.1.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

addAccount("Owner");
setCallee("Owner");
new Storage;
set_named "self";
push_named "self";
push 10u64;
call Storage.set_no_arg;
push_named "self";
call Storage.get_no_arg;
get_bigint_from_struct;
check_eq mxIntValue(10)
29 changes: 29 additions & 0 deletions tests/mx-rust/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![no_std]

#[allow(unused_imports)]
use multiversx_sc::imports::*;

#[multiversx_sc::contract]
pub trait Storage {
#[view(noArg)]
#[storage_mapper("no_arg")]
fn no_arg_storage(&self) -> SingleValueMapper<BigUint>;

#[view(getName)]
#[storage_mapper("name")]
fn one_arg_storage(&self, key: u64) -> SingleValueMapper<BigUint>;

#[init]
fn init(&self) {}

#[upgrade]
fn upgrade(&self) {}

fn set_no_arg(&self, value: u64) {
self.no_arg_storage().set(BigUint::from(value))
}

fn get_no_arg(&self) -> BigUint {
self.no_arg_storage().get()
}
}

0 comments on commit 89754c9

Please sign in to comment.