-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1507 from multiversx/uerror
Result handlers - error handling and "expect"
- Loading branch information
Showing
30 changed files
with
465 additions
and
36 deletions.
There are no files selected for viewing
File renamed without changes.
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,4 +1,5 @@ | ||
[settings] | ||
proxy-paths = ["tests/pmf_proxy.rs"] | ||
main = "main" | ||
|
||
[contracts.main] | ||
|
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
93 changes: 93 additions & 0 deletions
93
contracts/feature-tests/panic-message-features/tests/pmf_blackbox_test.rs
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,93 @@ | ||
mod pmf_proxy; | ||
use multiversx_sc::types::{AddressExpr, ScExpr}; | ||
use multiversx_sc_scenario::{scenario_model::*, *}; | ||
|
||
const OWNER: AddressExpr = AddressExpr("owner"); | ||
const SC_PMF: ScExpr = ScExpr("pmf"); | ||
const CODE_EXPR: &str = "mxsc:output/panic-message-features.mxsc.json"; | ||
|
||
fn world() -> ScenarioWorld { | ||
let mut blockchain = ScenarioWorld::new(); | ||
blockchain.set_current_dir_from_workspace("contracts/examples/adder"); | ||
|
||
blockchain.register_contract(CODE_EXPR, panic_message_features::ContractBuilder); | ||
blockchain | ||
} | ||
|
||
fn setup() -> ScenarioWorld { | ||
let mut world = world(); | ||
let code = world.code_expression(CODE_EXPR); | ||
|
||
world.set_state_step( | ||
SetStateStep::new() | ||
.put_account(OWNER, Account::new().nonce(1)) | ||
.put_account(SC_PMF, Account::new().code(code)), | ||
); | ||
|
||
world | ||
} | ||
|
||
// TODO: move to basic-features a testing framework tester | ||
#[test] | ||
fn tx_returns_error_test() { | ||
let mut world = setup(); | ||
|
||
let (status, message) = world | ||
.tx() | ||
.from(OWNER) | ||
.to(SC_PMF) | ||
.typed(pmf_proxy::PanicMessageFeaturesProxy) | ||
.sc_panic() | ||
.returns(ReturnsStatus) | ||
.returns(ReturnsMessage) | ||
.run(); | ||
|
||
assert_eq!(status, 4); | ||
assert_eq!(message, "sc_panic! test"); | ||
} | ||
|
||
#[test] | ||
fn query_returns_error_test() { | ||
let mut world = setup(); | ||
|
||
let (status, message) = world | ||
.query() | ||
.to(SC_PMF) | ||
.typed(pmf_proxy::PanicMessageFeaturesProxy) | ||
.sc_panic() | ||
.returns(ReturnsStatus) | ||
.returns(ReturnsMessage) | ||
.run(); | ||
|
||
assert_eq!(status, 4); | ||
assert_eq!(message, "sc_panic! test"); | ||
} | ||
|
||
#[test] | ||
fn tx_expect_error_test() { | ||
let mut world = setup(); | ||
|
||
world | ||
.tx() | ||
.from(OWNER) | ||
.to(SC_PMF) | ||
.typed(pmf_proxy::PanicMessageFeaturesProxy) | ||
.sc_panic() | ||
.returns(ExpectStatus(4)) | ||
.returns(ExpectMessage("sc_panic! test")) | ||
.run(); | ||
} | ||
|
||
#[test] | ||
fn query_expect_error_test() { | ||
let mut world = setup(); | ||
|
||
world | ||
.query() | ||
.to(SC_PMF) | ||
.typed(pmf_proxy::PanicMessageFeaturesProxy) | ||
.sc_panic() | ||
.returns(ExpectStatus(4)) | ||
.returns(ExpectMessage("sc_panic! test")) | ||
.run(); | ||
} |
95 changes: 95 additions & 0 deletions
95
contracts/feature-tests/panic-message-features/tests/pmf_proxy.rs
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,95 @@ | ||
// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. | ||
|
||
//////////////////////////////////////////////////// | ||
////////////////// AUTO-GENERATED ////////////////// | ||
//////////////////////////////////////////////////// | ||
|
||
#![allow(dead_code)] | ||
#![allow(clippy::all)] | ||
|
||
use multiversx_sc::proxy_imports::*; | ||
|
||
pub struct PanicMessageFeaturesProxy; | ||
|
||
impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for PanicMessageFeaturesProxy | ||
where | ||
Env: TxEnv, | ||
From: TxFrom<Env>, | ||
To: TxTo<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
type TxProxyMethods = PanicMessageFeaturesProxyMethods<Env, From, To, Gas>; | ||
|
||
fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods { | ||
PanicMessageFeaturesProxyMethods { wrapped_tx: tx } | ||
} | ||
} | ||
|
||
pub struct PanicMessageFeaturesProxyMethods<Env, From, To, Gas> | ||
where | ||
Env: TxEnv, | ||
From: TxFrom<Env>, | ||
To: TxTo<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>, | ||
} | ||
|
||
#[rustfmt::skip] | ||
impl<Env, From, Gas> PanicMessageFeaturesProxyMethods<Env, From, (), Gas> | ||
where | ||
Env: TxEnv, | ||
Env::Api: VMApi, | ||
From: TxFrom<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
pub fn init( | ||
self, | ||
) -> TxProxyDeploy<Env, From, Gas, ()> { | ||
self.wrapped_tx | ||
.raw_deploy() | ||
.original_result() | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
impl<Env, From, To, Gas> PanicMessageFeaturesProxyMethods<Env, From, To, Gas> | ||
where | ||
Env: TxEnv, | ||
Env::Api: VMApi, | ||
From: TxFrom<Env>, | ||
To: TxTo<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
pub fn panic_with_message< | ||
Arg0: CodecInto<u32>, | ||
>( | ||
self, | ||
some_value: Arg0, | ||
) -> TxProxyCall<Env, From, To, Gas, ()> { | ||
self.wrapped_tx | ||
.raw_call() | ||
.function_name("panicWithMessage") | ||
.argument(&some_value) | ||
.original_result() | ||
} | ||
|
||
/// Logs do not get recorded in case of panic. | ||
pub fn panic_after_log( | ||
self, | ||
) -> TxProxyCall<Env, From, To, Gas, ()> { | ||
self.wrapped_tx | ||
.raw_call() | ||
.function_name("panicAfterLog") | ||
.original_result() | ||
} | ||
|
||
pub fn sc_panic( | ||
self, | ||
) -> TxProxyCall<Env, From, To, Gas, ()> { | ||
self.wrapped_tx | ||
.raw_call() | ||
.function_name("sc_panic") | ||
.original_result() | ||
} | ||
} |
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
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
Oops, something went wrong.