multiversx_chain_vm/world_mock/
blockchain_mock.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
30
31
32
33
use crate::{tx_execution::BlockchainVMRef, with_shared::Shareable};
use multiversx_chain_vm_executor::Executor;
use std::{fmt::Debug, ops::Deref};

use super::{BlockchainState, FailingExecutor};

pub struct BlockchainMock {
    pub vm: BlockchainVMRef,
    pub state: Shareable<BlockchainState>,
}

impl BlockchainMock {
    pub fn new(executor: Box<dyn Executor + Send + Sync>) -> Self {
        BlockchainMock {
            vm: BlockchainVMRef::new(executor),
            state: Shareable::default(),
        }
    }
}

impl Default for BlockchainMock {
    fn default() -> Self {
        Self::new(Box::new(FailingExecutor))
    }
}

impl Debug for BlockchainMock {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        f.debug_struct("BlockchainMock")
            .field("state", self.state.deref())
            .finish()
    }
}