Struct novax::executor::MockExecutor
source · pub struct MockExecutor<A>where
A: Deref + Send + Sync,
Address: for<'a> From<&'a <A as Deref>::Target>,{ /* private fields */ }Expand description
A structure to execute smart contract queries, transactions, and deployments in a mocked blockchain environment.
This executor utilizes the scenario engine from the MultiversX Rust Testing Framework for executing smart contract interactions.
Implementations§
source§impl<A> MockExecutor<A>where
A: Deref + Send + Sync,
Address: for<'a> From<&'a <A as Deref>::Target>,
impl<A> MockExecutor<A>where A: Deref + Send + Sync, Address: for<'a> From<&'a <A as Deref>::Target>,
sourcepub fn new(
world: Arc<Mutex<ScenarioWorld>>,
opt_caller: Option<A>
) -> MockExecutor<A>
pub fn new( world: Arc<Mutex<ScenarioWorld>>, opt_caller: Option<A> ) -> MockExecutor<A>
Constructs a new MockExecutor with the specified mocked world and an optional caller address.
Parameters
world: The mocked world where the smart contract interactions are executed.opt_caller: Optional caller address.
Returns
A new instance of MockExecutor.
Trait Implementations§
source§impl<A> Clone for MockExecutor<A>where
A: Clone + Deref + Send + Sync,
Address: for<'a> From<&'a <A as Deref>::Target>,
impl<A> Clone for MockExecutor<A>where A: Clone + Deref + Send + Sync, Address: for<'a> From<&'a <A as Deref>::Target>,
source§fn clone(&self) -> MockExecutor<A>
fn clone(&self) -> MockExecutor<A>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<A> DeployExecutor for MockExecutor<A>where
A: Deref + Send + Sync,
Address: for<'a> From<&'a <A as Deref>::Target>,
impl<A> DeployExecutor for MockExecutor<A>where A: Deref + Send + Sync, Address: for<'a> From<&'a <A as Deref>::Target>,
Mock implementation of the DeployExecutor trait for testing and development purposes.
This implementation uses a mock executor to simulate the deployment of smart contracts
on the blockchain without actually interacting with a real blockchain network.
The MockExecutor struct encapsulates the state and behavior necessary for simulating
blockchain interactions.
Type Parameters
A: A type implementingDeref,Send, andSync. This type is used to derive anAddresstype instance representing a blockchain address.
source§fn sc_deploy<'life0, 'life1, 'async_trait, OriginalResult>(
&'life0 mut self,
sc_deploy_step: &'life1 mut TypedScDeploy<OriginalResult>
) -> Pin<Box<dyn Future<Output = Result<(), ExecutorError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
OriginalResult: TopEncodeMulti + Send + Sync + 'async_trait,
MockExecutor<A>: 'async_trait,
fn sc_deploy<'life0, 'life1, 'async_trait, OriginalResult>( &'life0 mut self, sc_deploy_step: &'life1 mut TypedScDeploy<OriginalResult> ) -> Pin<Box<dyn Future<Output = Result<(), ExecutorError>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, OriginalResult: TopEncodeMulti + Send + Sync + 'async_trait, MockExecutor<A>: 'async_trait,
Asynchronously deploys a smart contract to the mock blockchain environment.
Type Parameters
OriginalResult: Represents the result type expected from the smart contract deployment. This type must implementTopEncodeMulti,Send, andSync.S: Represents the type encapsulating the smart contract deployment step. This type must implementAsMut<TypedScDeploy<OriginalResult>>andSend.
Parameters
sc_deploy_step: A mutable reference to the smart contract deployment step to be executed.
Returns
A Result with an empty Ok(()) value indicating success, or an Err(ExecutorError) indicating failure,
specifically a MockDeployError::WalletAddressNotPresent error if the wallet address is not present.
source§fn should_skip_deserialization<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
MockExecutor<A>: 'async_trait,
fn should_skip_deserialization<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where 'life0: 'async_trait, MockExecutor<A>: 'async_trait,
Specifies whether deserialization should be skipped during the deployment execution. In this implementation, deserialization is not skipped.
Returns
A bool value of false, indicating that deserialization should not be skipped.
source§impl<A> QueryExecutor for MockExecutor<A>where
A: Clone + Deref + Send + Sync,
Address: for<'a> From<&'a <A as Deref>::Target>,
impl<A> QueryExecutor for MockExecutor<A>where A: Clone + Deref + Send + Sync, Address: for<'a> From<&'a <A as Deref>::Target>,
The MockExecutor implementation for the QueryExecutor trait, used to simulate smart contract queries in a mock environment.
This struct is typically utilized in testing and development scenarios where interaction with a real blockchain is undesirable or unnecessary.
Type Parameters
A: A type that implementsClone,Deref,Send, andSynctraits. This type is used to derive anAddressinstance representing a blockchain address.
source§fn execute<'life0, 'life1, 'async_trait, OutputManaged>(
&'life0 self,
request: &'life1 ScCallStep
) -> Pin<Box<dyn Future<Output = Result<<OutputManaged as NativeConvertible>::Native, ExecutorError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
OutputManaged: TopDecodeMulti + NativeConvertible + Send + Sync + 'async_trait,
MockExecutor<A>: 'async_trait,
fn execute<'life0, 'life1, 'async_trait, OutputManaged>( &'life0 self, request: &'life1 ScCallStep ) -> Pin<Box<dyn Future<Output = Result<<OutputManaged as NativeConvertible>::Native, ExecutorError>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, OutputManaged: TopDecodeMulti + NativeConvertible + Send + Sync + 'async_trait, MockExecutor<A>: 'async_trait,
Executes a simulated smart contract query in the mock environment.
Type Parameters
OutputManaged: The type representing the expected output of the smart contract query. It should implementTopDecodeMulti,NativeConvertible,Send, andSync.
Parameters
request: A reference to theScCallStepdetailing the smart contract query to be executed.
Returns
Result<OutputManaged::Native, ExecutorError>: On successful execution, returns aResultcontaining the native converted query output. On failure, returns aResultcontaining anExecutorError.
source§impl<A> TransactionExecutor for MockExecutor<A>where
A: Deref + Send + Sync,
Address: for<'a> From<&'a <A as Deref>::Target>,
impl<A> TransactionExecutor for MockExecutor<A>where A: Deref + Send + Sync, Address: for<'a> From<&'a <A as Deref>::Target>,
source§fn sc_call<'life0, 'life1, 'async_trait, OriginalResult>(
&'life0 mut self,
sc_call_step: &'life1 mut TypedScCall<OriginalResult>
) -> Pin<Box<dyn Future<Output = Result<(), ExecutorError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
OriginalResult: 'async_trait + Send,
MockExecutor<A>: 'async_trait,
fn sc_call<'life0, 'life1, 'async_trait, OriginalResult>( &'life0 mut self, sc_call_step: &'life1 mut TypedScCall<OriginalResult> ) -> Pin<Box<dyn Future<Output = Result<(), ExecutorError>> + Send + 'async_trait>>where 'life0: 'async_trait, 'life1: 'async_trait, OriginalResult: 'async_trait + Send, MockExecutor<A>: 'async_trait,
Executes a smart contract call within a mocked environment.
This method extracts or determines the caller’s address, performs a smart contract call, and updates the world state accordingly, all within a controlled, mocked environment.
Parameters
sc_call_step: A mutable reference to aTypedScCallobject representing the smart contract call step.
Type Parameters
OriginalResult: The type of the result expected from the smart contract call. Must implement theSendtrait.
Returns
- A
Resultobject with an emptyOk(())value if the call is successful, or anErr(ExecutorError)if the call fails for any reason.
source§fn should_skip_deserialization<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
MockExecutor<A>: 'async_trait,
fn should_skip_deserialization<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where 'life0: 'async_trait, MockExecutor<A>: 'async_trait,
Specifies whether deserialization should be skipped during the smart contract call execution.
In the context of the mocked environment, deserialization is not skipped,
hence this method returns false.
Returns
- A boolean value
false, indicating that deserialization should not be skipped.