Skip to main content

multiversx_sc_scenario/executor/debug/
contract_debug_whitebox_lambda.rs

1use multiversx_chain_vm::host::{
2    context::TxFunctionName,
3    runtime::{RuntimeInstanceCall, RuntimeInstanceCallLambda},
4};
5
6use crate::executor::debug::ContractDebugInstance;
7
8pub struct ContractDebugWhiteboxLambda<F>
9where
10    F: FnOnce(),
11{
12    function_name: TxFunctionName,
13    whitebox_fn: F,
14    panic_message_flag: bool,
15}
16
17impl<F> ContractDebugWhiteboxLambda<F>
18where
19    F: FnOnce(),
20{
21    pub fn new(function_name: TxFunctionName, whitebox_fn: F) -> Self {
22        ContractDebugWhiteboxLambda {
23            function_name,
24            whitebox_fn,
25            panic_message_flag: true,
26        }
27    }
28
29    pub fn panic_message(mut self, panic_message_flag: bool) -> Self {
30        self.panic_message_flag = panic_message_flag;
31        self
32    }
33}
34
35impl<F> RuntimeInstanceCallLambda for ContractDebugWhiteboxLambda<F>
36where
37    F: FnOnce(),
38{
39    fn call(self, instance_call: RuntimeInstanceCall<'_>) {
40        assert_eq!(
41            self.function_name,
42            instance_call.tx_context_ref.input_ref().func_name,
43            "unexpected whitebox function name"
44        );
45
46        ContractDebugInstance::wrap_lambda_call(
47            self.panic_message_flag,
48            instance_call,
49            self.whitebox_fn,
50        );
51    }
52
53    fn override_function_name(&self) -> Option<TxFunctionName> {
54        Some(self.function_name.clone())
55    }
56}