diff --git a/mx-rust-semantics/test/configuration.md b/mx-rust-semantics/test/configuration.md index 3b0d2d1..0701dcb 100644 --- a/mx-rust-semantics/test/configuration.md +++ b/mx-rust-semantics/test/configuration.md @@ -8,6 +8,7 @@ module MX-RUST-EXECUTION-TEST-CONFIGURATION + .Map endmodule diff --git a/mx-rust-semantics/test/execution.md b/mx-rust-semantics/test/execution.md index 8a11b20..267e32f 100644 --- a/mx-rust-semantics/test/execution.md +++ b/mx-rust-semantics/test/execution.md @@ -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 + set_named Name:String => .K ... + ListItem(Value) => .List ... + M:Map => M[Name <- Value] + + rule + push_named Name:String => .K ... + .List => ListItem(Value) ... + Name |-> Value ... + + rule + + 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 + ... + + BigUintIdId |-> i32(BigUintId:MInt{32}) ... endmodule ``` diff --git a/tests/mx-rust/storage.1.run b/tests/mx-rust/storage.1.run new file mode 100644 index 0000000..911768f --- /dev/null +++ b/tests/mx-rust/storage.1.run @@ -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) diff --git a/tests/mx-rust/storage.2.run b/tests/mx-rust/storage.2.run new file mode 100644 index 0000000..bdefa78 --- /dev/null +++ b/tests/mx-rust/storage.2.run @@ -0,0 +1,9 @@ + +addAccount("Owner"); +setCallee("Owner"); +new Storage; +set_named "self"; +push_named "self"; +call Storage.get_no_arg; +get_bigint_from_struct; +check_eq mxIntValue(0) diff --git a/tests/mx-rust/storage.3.run b/tests/mx-rust/storage.3.run new file mode 100644 index 0000000..7881110 --- /dev/null +++ b/tests/mx-rust/storage.3.run @@ -0,0 +1,20 @@ +addAccount("Owner"); +setCallee("Owner"); +new Storage; +set_named "self"; + +push_named "self"; +push 10u64; +call Storage.set_no_arg_if_empty; +push_named "self"; +call Storage.get_no_arg; +get_bigint_from_struct; +check_eq mxIntValue(10); + +push_named "self"; +push 20u64; +call Storage.set_no_arg_if_empty; +push_named "self"; +call Storage.get_no_arg; +get_bigint_from_struct; +check_eq mxIntValue(10) diff --git a/tests/mx-rust/storage.rs b/tests/mx-rust/storage.rs new file mode 100644 index 0000000..0b16596 --- /dev/null +++ b/tests/mx-rust/storage.rs @@ -0,0 +1,33 @@ +#![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; + + #[view(getName)] + #[storage_mapper("name")] + fn one_arg_storage(&self, key: u64) -> SingleValueMapper; + + #[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() + } + + fn set_no_arg_if_empty(&self, value: u64) { + self.no_arg_storage().set_if_empty(BigUint::from(value)) + } +} diff --git a/tests/mx/storage/get-existing-storage.mx b/tests/mx/storage/get-existing-storage.mx index 0ebcd78..23a3457 100644 --- a/tests/mx/storage/get-existing-storage.mx +++ b/tests/mx/storage/get-existing-storage.mx @@ -1,6 +1,6 @@ addAccount("Owner"); setCallee("Owner"); -setStorage("Owner", "MyKey", mxStringValue("Hello")); +setStorage("Owner", "MyKey", wrappedMx(mxStringValue("Hello"))); push mxIntValue(12); push mxStringValue("MyKey"); diff --git a/tests/mx/storage/set-existing-storage.mx b/tests/mx/storage/set-existing-storage.mx index 094fc9b..58be307 100644 --- a/tests/mx/storage/set-existing-storage.mx +++ b/tests/mx/storage/set-existing-storage.mx @@ -1,6 +1,6 @@ addAccount("Owner"); setCallee("Owner"); -setStorage("Owner", "MyKey", mxStringValue("Hello")); +setStorage("Owner", "MyKey", wrappedMx(mxStringValue("Hello"))); push wrappedMx(mxStringValue("World")); push mxStringValue("MyKey");