multiversx_sc_scenario/facade/
whitebox_contract.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use multiversx_sc::contract_base::{CallableContract, ContractBase};

use crate::{scenario_model::AddressKey, DebugApi};

/// Wraps a contract that is supposed to be used in whitebox tests.
///
/// For this reason it references the concrete SC type explicitly.
pub struct WhiteboxContract<ContractObj>
where
    ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
{
    pub address_expr: AddressKey,
    pub contract_obj_builder: fn() -> ContractObj,
}

impl<ContractObj> WhiteboxContract<ContractObj>
where
    ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
{
    pub fn new<A: Into<AddressKey>>(
        address_expr: A,
        contract_obj_builder: fn() -> ContractObj,
    ) -> Self {
        Self {
            address_expr: address_expr.into(),
            contract_obj_builder,
        }
    }
}