diff --git a/contracts/feature-tests/panic-message-features/tests/pmf_blackbox_test.rs b/contracts/feature-tests/panic-message-features/tests/pmf_blackbox_test.rs index 3d13175c09..28499c0e84 100644 --- a/contracts/feature-tests/panic-message-features/tests/pmf_blackbox_test.rs +++ b/contracts/feature-tests/panic-message-features/tests/pmf_blackbox_test.rs @@ -75,6 +75,7 @@ fn tx_expect_error_test() { .sc_panic() .with_result(ExpectStatus(4)) .with_result(ExpectMessage("sc_panic! test")) + .with_result(ExpectError(4, "sc_panic! test")) .run(); } @@ -89,5 +90,6 @@ fn query_expect_error_test() { .sc_panic() .with_result(ExpectStatus(4)) .with_result(ExpectMessage("sc_panic! test")) + .with_result(ExpectError(4, "sc_panic! test")) .run(); } diff --git a/framework/scenario/src/facade/result_handlers.rs b/framework/scenario/src/facade/result_handlers.rs index 30823bf6f5..24709626ea 100644 --- a/framework/scenario/src/facade/result_handlers.rs +++ b/framework/scenario/src/facade/result_handlers.rs @@ -1,3 +1,4 @@ +mod expect_error; mod expect_message; mod expect_status; mod returns_message; @@ -6,6 +7,7 @@ mod returns_new_token_identifier; mod returns_status; mod with_tx_raw_response; +pub use expect_error::ExpectError; pub use expect_message::ExpectMessage; pub use expect_status::ExpectStatus; pub use returns_message::ReturnsMessage; diff --git a/framework/scenario/src/facade/result_handlers/expect_error.rs b/framework/scenario/src/facade/result_handlers/expect_error.rs new file mode 100644 index 0000000000..a06a227424 --- /dev/null +++ b/framework/scenario/src/facade/result_handlers/expect_error.rs @@ -0,0 +1,33 @@ +use multiversx_chain_scenario_format::serde_raw::ValueSubTree; +use multiversx_sc::types::{RHListItem, RHListItemExec, TxEnv}; + +use crate::scenario_model::{BytesValue, CheckValue, TxExpect, TxResponse}; + +/// Verifies that transaction result error matches the given one. +/// +/// Can only be used in tests and interactors, not available in contracts. +pub struct ExpectError<'a>(pub u64, pub &'a str); + +impl<'a, Env, Original> RHListItem for ExpectError<'a> +where + Env: TxEnv, +{ + type Returns = (); +} + +impl<'a, Env, Original> RHListItemExec for ExpectError<'a> +where + Env: TxEnv, +{ + fn item_tx_expect(&self, mut prev: TxExpect) -> TxExpect { + prev.status = CheckValue::Equal(self.0.into()); + let expect_message_expr = BytesValue { + value: self.1.to_string().into_bytes(), + original: ValueSubTree::Str(format!("str:{}", self.1)), + }; + prev.message = CheckValue::Equal(expect_message_expr); + prev + } + + fn item_process_result(self, _: &TxResponse) -> Self::Returns {} +}