multiversx_sc_scenario/facade/result_handlers/
expect_error.rs

1use multiversx_chain_scenario_format::serde_raw::ValueSubTree;
2use multiversx_sc::types::{RHListItem, RHListItemExec, TxEnv};
3
4use crate::scenario_model::{BytesValue, CheckValue, TxExpect, TxResponse};
5
6/// Verifies that transaction result error matches the given one.
7///
8/// Can only be used in tests and interactors, not available in contracts.
9pub struct ExpectError<'a>(pub u64, pub &'a str);
10
11impl<Env, Original> RHListItem<Env, Original> for ExpectError<'_>
12where
13    Env: TxEnv,
14{
15    type Returns = ();
16}
17
18impl<Env, Original> RHListItemExec<TxResponse, Env, Original> for ExpectError<'_>
19where
20    Env: TxEnv<RHExpect = TxExpect>,
21{
22    fn item_preprocessing(&self, mut prev: TxExpect) -> TxExpect {
23        prev.status = CheckValue::Equal(self.0.into());
24        let expect_message_expr = BytesValue {
25            value: self.1.to_string().into_bytes(),
26            original: ValueSubTree::Str(format!("str:{}", self.1)),
27        };
28        prev.message = CheckValue::Equal(expect_message_expr);
29        prev
30    }
31
32    fn item_process_result(self, _: &TxResponse) -> Self::Returns {}
33}