-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
655ed4f
commit a2d98a0
Showing
22 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
```k | ||
requires "calls/implementation.md" | ||
requires "calls/macros.md" | ||
module MX-RUST-CALLS | ||
imports private MX-RUST-CALLS-IMPLEMENTATION | ||
imports private MX-RUST-CALLS-MACROS | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
```k | ||
module MX-RUST-CALLS-MACROS | ||
imports private RUST-SHARED-SYNTAX | ||
imports private RUST-VALUE-SYNTAX | ||
imports private MX-COMMON-SYNTAX | ||
syntax MxRustInstruction ::= requireMacro(condition:Expression, message:Expression) | ||
[seqstrict] | ||
rule ( #token("require", "Identifier") :: .SimplePathList ! | ||
( Condition:Expression, Message:Expression, .CallParamsList ) ; | ||
):MacroInvocationSemi:KItem | ||
=> requireMacro(... condition:Condition, message:Message) | ||
rule requireMacro(... condition: ptrValue(_, true), message: _:PtrValue) => .K | ||
rule requireMacro(... condition: ptrValue(_, false), message: ptrValue(_, Message:String)) | ||
=> MX#signalError(mxStringValue(Message)) | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
```k | ||
module MX-ERRORS-HOOKS | ||
imports private MX-COMMON-SYNTAX | ||
rule MX#signalError(mxStringValue(Message:String)) => #exception(UserError, Message) | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
```k | ||
module MX-ERRORS-TOOLS | ||
imports private COMMON-K-CELL | ||
imports private K-EQUAL-SYNTAX | ||
imports private MX-CALL-RESULT-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
syntax MxInstructions ::= setErrorVMOutput(ExceptionCode, String) | ||
rule #exception(_, _) ~> (Next:KItem => .K) | ||
requires Next =/=K endCall | ||
rule #exception(Code, Message) ~> endCall | ||
=> setErrorVMOutput(Code, Message) ~> popCallState ~> popWorldState | ||
rule [setErrorVMOutput]: | ||
<k> setErrorVMOutput(Code, Message) => .K ... </k> | ||
<mx-call-result> | ||
_ => mxCallResult | ||
(... returnCode: Code | ||
, returnMessage: Message | ||
, out: mxListValue(.MxValueList) | ||
) | ||
</mx-call-result> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(); | ||
push mxStringValue("callRequirePassesRetv"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(0); | ||
|
||
push_return_value; | ||
check_eq mxIntValue(3) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(); | ||
push mxStringValue("callRequireFailsRetv"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(7000); | ||
|
||
catch_error "error signalled by smartcontract: Require failure" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(); | ||
push mxStringValue("callRequirePassesInstr"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(0); | ||
|
||
push_return_value; | ||
check_eq mxListValue() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(); | ||
push mxStringValue("callRequireFailsInstr"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(7000); | ||
|
||
catch_error "error signalled by smartcontract: Require failure" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(); | ||
push mxStringValue("callRequireFailsUndoRetv"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(7000); | ||
|
||
catch_error "error signalled by smartcontract: Require failure"; | ||
|
||
push mxListValue(); | ||
push mxStringValue("getMyStorage"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(0); | ||
|
||
push_return_value; | ||
check_eq mxIntValue(10) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
setCallee("Owner"); | ||
|
||
push mxListValue(); | ||
push mxStringValue("callRequireFailsUndoInstr"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(7000); | ||
|
||
catch_error "error signalled by smartcontract: Require failure"; | ||
|
||
push mxListValue(); | ||
push mxStringValue("getMyStorage"); | ||
push mxIntValue(0); | ||
push mxTransfersValue(); | ||
push mxIntValue(0); | ||
push mxStringValue("TestContract"); | ||
call 6 MX#managedExecuteOnDestContext; | ||
check_eq mxIntValue(0); | ||
|
||
push_return_value; | ||
check_eq mxIntValue(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#![no_std] | ||
|
||
#[allow(unused_imports)] | ||
use multiversx_sc::imports::*; | ||
|
||
#[multiversx_sc::contract] | ||
pub trait RequireContract { | ||
#[view(noArg)] | ||
#[storage_mapper("my_value")] | ||
fn my_storage(&self) -> SingleValueMapper<BigUint>; | ||
|
||
#[init] | ||
fn init(&self) { | ||
self.my_storage().set_if_empty(BigUint::from(10)) | ||
} | ||
|
||
#[upgrade] | ||
fn upgrade(&self) {} | ||
|
||
#[endpoint(callRequirePassesRetv)] | ||
fn call_require_passes_retv(&self) -> u64 { | ||
require!(5_u64 > 4_u64, "Require failure"); | ||
3_u64 | ||
} | ||
|
||
#[endpoint(callRequireFailsRetv)] | ||
fn call_require_fails_retv(&self) -> u64 { | ||
require!(5_u64 > 6_u64, "Require failure"); | ||
3_u64 | ||
} | ||
|
||
#[endpoint(callRequirePassesInstr)] | ||
fn call_require_passes_Instr(&self) { | ||
require!(5_u64 > 4_u64, "Require failure"); | ||
3_u64; | ||
} | ||
|
||
#[endpoint(callRequireFailsInstr)] | ||
fn call_require_fails_instr(&self) -> u64 { | ||
require!(5_u64 > 6_u64, "Require failure"); | ||
3_u64; | ||
} | ||
|
||
#[endpoint(callRequireFailsUndoRetv)] | ||
fn call_require_fails_undo_retv(&self) { | ||
self.my_storage().set(BigUint::from(100_u64)); | ||
require!(5_u64 > 6_u64, "Require failure"); | ||
self.my_storage().set(BigUint::from(100_u64)) | ||
} | ||
|
||
#[endpoint(callRequireFailsUndoInstr)] | ||
fn call_require_fails_undo_instr(&self) -> u64 { | ||
self.my_storage().set(BigUint::from(100_u64)); | ||
require!(5_u64 > 6_u64, "Require failure"); | ||
self.my_storage().set(BigUint::from(100_u64)); | ||
} | ||
|
||
#[endpoint(getMyStorage)] | ||
fn get_my_storage(&self) -> BigUint { | ||
self.my_storage().get() | ||
} | ||
} |