multiversx_sc_snippets::imports

Struct ScenarioWorld

Source
pub struct ScenarioWorld { /* private fields */ }
Expand description

A facade for contracts tests.

Contains all the context needed to execute scenarios involving contracts.

Currently defers most of the operations to the blockchain mock object directly, but that one will be refactored and broken up into smaller pieces.

Implementations§

Source§

impl ScenarioWorld

Source

pub fn debugger() -> ScenarioWorld

Source

pub fn new() -> ScenarioWorld

Backwards compatibility only.

Source

pub fn vm_go() -> ScenarioWorld

Source

pub fn run<P>(self, relative_path: P)
where P: AsRef<Path>,

Runs a scenario file (.scen.json) with the configured backend.

Will crash and produce an output if the test failed for any reason.

Source

pub fn start_trace(&mut self) -> &mut ScenarioWorld

Source

pub fn set_current_dir_from_workspace( &mut self, relative_path: &str, ) -> &mut ScenarioWorld

Tells the tests where the crate lies relative to the workspace. This ensures that the paths are set correctly, including in debug mode.

Source

pub fn current_dir(&self) -> &PathBuf

Source

pub fn write_scenario_trace<P>(&mut self, file_path: P)
where P: AsRef<Path>,

Exports current scenario to a JSON file, as created.

Source

pub fn write_mandos_trace<P>(&mut self, file_path: P)
where P: AsRef<Path>,

👎Deprecated since 0.39.0: Renamed, use write_scenario_trace instead.
Source§

impl ScenarioWorld

Source

pub fn interpreter_context(&self) -> InterpreterContext

Source

pub fn code_expression(&self, path: &str) -> BytesValue

Convenient way of creating a code expression based on the current context (i.e. with the paths resolved, as configured).

Source

pub fn register_contract_container( &mut self, expression: impl RegisterCodeSource, contract_container: ContractContainer, )

Source

pub fn register_contract<B>( &mut self, expression: impl RegisterCodeSource, contract_builder: B, )

Links a contract path in a test to a contract implementation.

Source

pub fn register_contract_builder<B>( &mut self, expression: &str, contract_builder: B, )

👎Deprecated since 0.37.0: Got renamed to register_contract, but not completely removed, in order to ease test migration. Please replace with register_contract.
Source

pub fn register_partial_contract<Abi, B>( &mut self, expression: impl RegisterCodeSource, contract_builder: B, sub_contract_name: &str, )

Links a contract path in a test to a multi-contract output.

This simulates the effects of building such a contract with only part of the endpoints.

Source

pub fn register_contract_variant<B>( &mut self, expression: impl RegisterCodeSource, contract_builder: B, contract_variant: &ContractVariant, )

Links a contract path in a test to a multi-contract output.

This simulates the effects of building such a contract with only part of the endpoints.

Source§

impl ScenarioWorld

Source

pub fn for_each_runner_mut<F>(&mut self, f: F)
where F: FnMut(&mut dyn ScenarioRunner),

Source§

impl ScenarioWorld

Source

pub fn external_steps(&mut self, step: ExternalStepsStep) -> &mut ScenarioWorld

Imports and processes steps from an external scenario file.

Source

pub fn set_state_step(&mut self, step: SetStateStep) -> &mut ScenarioWorld

Adds a SC call step, then executes it.

Source

pub fn sc_call<S>(&mut self, step: S) -> &mut ScenarioWorld
where S: AsMut<ScCallStep>,

Adds a SC call step, then executes it.

Source

pub fn sc_call_use_raw_response<S, F>( &mut self, step: S, use_raw_response: F, ) -> &mut ScenarioWorld

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_call_use_result<OriginalResult, RequestedResult, F>( &mut self, step: TypedScCall<OriginalResult>, use_result: F, ) -> &mut ScenarioWorld
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>, F: FnOnce(TypedResponse<RequestedResult>),

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_call_get_result<OriginalResult, RequestedResult>( &mut self, step: TypedScCall<OriginalResult>, ) -> RequestedResult
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_query<S>(&mut self, step: S) -> &mut ScenarioWorld
where S: AsMut<ScQueryStep>,

Adds a SC query step, then executes it.

Source

pub fn sc_query_use_raw_response<S, F>( &mut self, step: S, use_raw_response: F, ) -> &mut ScenarioWorld

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_query_use_result<OriginalResult, RequestedResult, F>( &mut self, step: TypedScQuery<OriginalResult>, use_result: F, ) -> &mut ScenarioWorld
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>, F: FnOnce(TypedResponse<RequestedResult>),

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_query_get_result<OriginalResult, RequestedResult>( &mut self, step: TypedScQuery<OriginalResult>, ) -> RequestedResult
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn quick_query<CC, RequestedResult>( &mut self, contract_call: CC, ) -> RequestedResult
where CC: ContractCall<VMHooksApi<StaticApiBackend>>, RequestedResult: TopDecodeMulti + TypeAbiFrom<<CC as ContractCallBase<VMHooksApi<StaticApiBackend>>>::OriginalResult>,

Performs a SC query to a contract, leaves no scenario trace behind.

Meant to be used for the test to investigate the state of the contract.

Use mandos_sc_query to embed the SC query in the resulting scenario.

Source

pub fn sc_deploy<S>(&mut self, step: S) -> &mut ScenarioWorld
where S: AsMut<ScDeployStep>,

Adds a SC deploy step, then executes it.

Source

pub fn sc_deploy_use_raw_response<S, F>( &mut self, step: S, use_raw_response: F, ) -> &mut ScenarioWorld

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_deploy_use_result<OriginalResult, RequestedResult, F>( &mut self, step: TypedScDeploy<OriginalResult>, use_result: F, ) -> &mut ScenarioWorld
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>, F: FnOnce(Address, TypedResponse<RequestedResult>),

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn sc_deploy_get_result<OriginalResult, RequestedResult>( &mut self, step: TypedScDeploy<OriginalResult>, ) -> (Address, RequestedResult)
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source

pub fn transfer_step(&mut self, step: TransferStep) -> &mut ScenarioWorld

Adds a simple transfer step, then executes it.

Source

pub fn validator_reward_step( &mut self, step: ValidatorRewardStep, ) -> &mut ScenarioWorld

Adds a validator reward step, then executes it.

Source

pub fn check_state_step(&mut self, step: CheckStateStep) -> &mut ScenarioWorld

Adds a check state step, then executes it.

Source

pub fn dump_state_step(&mut self) -> &mut ScenarioWorld

Adds a dump state step, then executes it.

Source§

impl ScenarioWorld

Source

pub fn sc_call_step<S>(&mut self, step: S) -> &mut ScenarioWorld
where S: AsMut<ScCallStep>,

👎Deprecated since 0.42.0: Renamed to sc_call.
Source

pub fn sc_query_step<S>(&mut self, step: S) -> &mut ScenarioWorld
where S: AsMut<ScQueryStep>,

👎Deprecated since 0.42.0: Renamed to sc_query.
Source

pub fn sc_deploy_step<S>(&mut self, step: S) -> &mut ScenarioWorld
where S: AsMut<ScDeployStep>,

👎Deprecated since 0.42.0: Renamed to sc_deploy.
Source

pub fn mandos_set_state(&mut self, step: SetStateStep) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use set_state_step instead.
Source

pub fn mandos_sc_call(&mut self, step: ScCallStep) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use sc_call_step instead.
Source

pub fn mandos_sc_query(&mut self, step: ScQueryStep) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use sc_query_step instead.
Source

pub fn mandos_sc_deploy(&mut self, step: ScDeployStep) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use sc_deploy_step instead.
Source

pub fn mandos_transfer(&mut self, step: TransferStep) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use transfer_step instead.
Source

pub fn mandos_validator_reward( &mut self, step: ValidatorRewardStep, ) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use validator_reward_step instead.
Source

pub fn mandos_check_state(&mut self, step: CheckStateStep) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use check_state_step instead.
Source

pub fn mandos_dump_state(&mut self) -> &mut ScenarioWorld

👎Deprecated since 0.39.0: Renamed, use dump_state_step instead.
Source§

impl ScenarioWorld

Source

pub fn whitebox_query<ContractObj, F>( &mut self, whitebox_contract: &WhiteboxContract<ContractObj>, f: F, ) -> &mut ScenarioWorld
where ContractObj: ContractBase<Api = VMHooksApi<DebugApiBackend>> + CallableContract + 'static, F: FnOnce(ContractObj),

👎Deprecated since 0.53.0: Please use method whitebox, as part of the unified transaction syntax.
Source

pub fn whitebox_query_check<ContractObj, F, C>( &mut self, whitebox_contract: &WhiteboxContract<ContractObj>, f: F, check_result: C, ) -> &mut ScenarioWorld
where ContractObj: ContractBase<Api = VMHooksApi<DebugApiBackend>> + CallableContract + 'static, F: FnOnce(ContractObj), C: FnOnce(TxResult),

👎Deprecated since 0.53.0: Please use method whitebox, as part of the unified transaction syntax.
Source

pub fn whitebox_call<ContractObj, F>( &mut self, whitebox_contract: &WhiteboxContract<ContractObj>, sc_call_step: ScCallStep, f: F, ) -> &mut ScenarioWorld
where ContractObj: ContractBase<Api = VMHooksApi<DebugApiBackend>> + CallableContract + 'static, F: FnOnce(ContractObj),

👎Deprecated since 0.53.0: Please use method whitebox, as part of the unified transaction syntax.
Source

pub fn whitebox_call_check<ContractObj, F, C>( &mut self, whitebox_contract: &WhiteboxContract<ContractObj>, sc_call_step: ScCallStep, f: F, check_result: C, ) -> &mut ScenarioWorld
where ContractObj: ContractBase<Api = VMHooksApi<DebugApiBackend>> + CallableContract + 'static, F: FnOnce(ContractObj), C: FnOnce(TxResult),

👎Deprecated since 0.53.0: Please use method whitebox, as part of the unified transaction syntax.
Source

pub fn whitebox_deploy<ContractObj, F>( &mut self, whitebox_contract: &WhiteboxContract<ContractObj>, sc_deploy_step: ScDeployStep, f: F, ) -> &mut ScenarioWorld
where ContractObj: ContractBase<Api = VMHooksApi<DebugApiBackend>> + CallableContract + 'static, F: FnOnce(ContractObj),

👎Deprecated since 0.53.0: Please use method whitebox, as part of the unified transaction syntax.
Source

pub fn whitebox_deploy_check<ContractObj, F, C>( &mut self, whitebox_contract: &WhiteboxContract<ContractObj>, sc_deploy_step: ScDeployStep, f: F, check_result: C, ) -> &mut ScenarioWorld
where ContractObj: ContractBase<Api = VMHooksApi<DebugApiBackend>> + CallableContract + 'static, F: FnOnce(ContractObj), C: FnOnce(TxResult),

👎Deprecated since 0.53.0: Please use method whitebox, as part of the unified transaction syntax.
Source§

impl ScenarioWorld

Source

pub fn check_account<A>(&mut self, address: A) -> CheckStateBuilder<'_>

Source§

impl ScenarioWorld

Source

pub fn tx(&mut self) -> Tx<ScenarioEnvExec<'_>, (), (), (), (), (), ()>

Source

pub fn chain_call<From, To, Payment, Gas, RH, F>( &mut self, f: F, ) -> &mut ScenarioWorld

Source§

impl ScenarioWorld

Source

pub fn chain_deploy<From, Payment, Gas, CodeValue, RH, F>( &mut self, f: F, ) -> &mut ScenarioWorld

Source§

impl ScenarioWorld

Source

pub fn query(&mut self) -> Tx<ScenarioEnvQuery<'_>, (), (), (), (), (), ()>

Source

pub fn chain_query<To, Payment, RH, F>(&mut self, f: F) -> &mut ScenarioWorld
where To: TxToSpecified<ScenarioTxEnvData>, Payment: TxNoPayment<ScenarioTxEnvData>, RH: RHListExec<TxResponse, ScenarioTxEnvData, ListReturns = ()>, F: FnOnce(Tx<ScenarioTxEnvData, (), (), (), (), (), ()>) -> Tx<ScenarioTxEnvData, (), To, Payment, (), FunctionCall<VMHooksApi<StaticApiBackend>>, RH>,

Source§

impl ScenarioWorld

Source

pub fn account<A>( &mut self, address_expr: A, ) -> SetStateBuilder<'_, AccountItem>

Source

pub fn new_address<CA, CN, NA>( &mut self, creator_address_expr: CA, creator_nonce_expr: CN, new_address_expr: NA, ) -> SetStateBuilder<'_, NewAddressItem>

Source

pub fn create_account_raw<A, V>( &mut self, address: A, egld_balance: V, ) -> SetStateBuilder<'_, AccountItem>

Source

pub fn set_egld_balance<A, V>(&mut self, address: A, balance: V)

Source

pub fn set_esdt_balance<A, V>( &mut self, address: A, token_id: &[u8], balance: V, )

Source

pub fn set_nft_balance_all_properties<A, B, N, T, R, C>( &mut self, address: A, token_id: &[u8], nonce: N, balance: B, attributes: T, royalties: R, creator: Option<C>, name: Option<&[u8]>, hash: Option<&[u8]>, uris: &[Vec<u8>], )

Source

pub fn set_developer_rewards<A, V>(&mut self, address: A, developer_rewards: V)
where A: Copy, V: Copy, AddressKey: From<A>, BigUintValue: From<V>,

Source

pub fn set_esdt_local_roles<A>( &mut self, address: A, token_id: &[u8], roles: &[EsdtLocalRole], )

Source

pub fn current_block(&mut self) -> SetStateBuilder<'_, BlockItem>

Source

pub fn previous_block(&mut self) -> SetStateBuilder<'_, BlockItem>

Trait Implementations§

Source§

impl Default for ScenarioWorld

Source§

fn default() -> ScenarioWorld

Returns the “default value” for a type. Read more
Source§

impl ScenarioRunner for ScenarioWorld

Source§

fn run_external_steps(&mut self, step: &ExternalStepsStep)

Source§

fn run_set_state_step(&mut self, step: &SetStateStep)

Source§

fn run_sc_call_step(&mut self, step: &mut ScCallStep)

Source§

fn run_multi_sc_call_step(&mut self, steps: &mut [ScCallStep])

Source§

fn run_multi_sc_deploy_step(&mut self, steps: &mut [ScDeployStep])

Source§

fn run_sc_query_step(&mut self, step: &mut ScQueryStep)

Source§

fn run_sc_deploy_step(&mut self, step: &mut ScDeployStep)

Source§

fn run_transfer_step(&mut self, step: &TransferStep)

Source§

fn run_validator_reward_step(&mut self, step: &ValidatorRewardStep)

Source§

fn run_check_state_step(&mut self, step: &CheckStateStep)

Source§

fn run_dump_state_step(&mut self)

Source§

fn run_scenario(&mut self, scenario: &Scenario)

Utility method for running all steps in a scenario.
Source§

impl TypedScCallExecutor for ScenarioWorld

Source§

fn execute_typed_sc_call<OriginalResult, RequestedResult>( &mut self, typed_sc_call: TypedScCall<OriginalResult>, ) -> RequestedResult
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,

👎Deprecated since 0.49.0: Please use the unified transaction syntax instead.
Source§

impl TypedScDeployExecutor for ScenarioWorld

Source§

fn execute_typed_sc_deploy<OriginalResult, RequestedResult>( &mut self, typed_sc_call: TypedScDeploy<OriginalResult>, ) -> (Address, RequestedResult)
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,

Source§

impl TypedScQueryExecutor for ScenarioWorld

Source§

fn execute_typed_sc_query<OriginalResult, RequestedResult>( &mut self, typed_sc_query: TypedScQuery<OriginalResult>, ) -> RequestedResult
where OriginalResult: TopEncodeMulti, RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,

Adds a SC query step, but sets the contract call data and returns the result.

It also sets in the trace the expected result to be the actual returned result.

It is the duty of the test developer to check that the result is actually correct after the call.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> InterpretableFrom<T> for T

Source§

fn interpret_from(from: T, _context: &InterpreterContext) -> T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ReconstructableFrom<T> for T

Source§

fn reconstruct_from(from: T, _builder: &ReconstructorContext) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T