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
impl ScenarioWorld
pub fn debugger() -> Self
pub fn vm_go() -> Self
Sourcepub fn run<P: AsRef<Path>>(self, relative_path: P)
pub fn run<P: AsRef<Path>>(self, relative_path: P)
Runs a scenario file (.scen.json
) with the configured backend.
Will crash and produce an output if the test failed for any reason.
pub fn start_trace(&mut self) -> &mut Self
Sourcepub fn set_current_dir_from_workspace(
&mut self,
relative_path: &str,
) -> &mut Self
pub fn set_current_dir_from_workspace( &mut self, relative_path: &str, ) -> &mut Self
Tells the tests where the crate lies relative to the workspace. This ensures that the paths are set correctly, including in debug mode.
pub fn current_dir(&self) -> &PathBuf
Sourcepub fn write_scenario_trace<P: AsRef<Path>>(&mut self, file_path: P)
pub fn write_scenario_trace<P: AsRef<Path>>(&mut self, file_path: P)
Exports current scenario to a JSON file, as created.
pub fn write_mandos_trace<P: AsRef<Path>>(&mut self, file_path: P)
write_scenario_trace
instead.Source§impl ScenarioWorld
impl ScenarioWorld
pub fn interpreter_context(&self) -> InterpreterContext
Sourcepub fn code_expression(&self, path: &str) -> BytesValue
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).
pub fn register_contract_container( &mut self, expression: impl RegisterCodeSource, contract_container: ContractContainer, )
Sourcepub fn register_contract<B: CallableContractBuilder>(
&mut self,
expression: impl RegisterCodeSource,
contract_builder: B,
)
pub fn register_contract<B: CallableContractBuilder>( &mut self, expression: impl RegisterCodeSource, contract_builder: B, )
Links a contract path in a test to a contract implementation.
pub fn register_contract_builder<B: CallableContractBuilder>( &mut self, expression: &str, contract_builder: B, )
register_contract
, but not completely removed, in order to ease test migration. Please replace with register_contract
.Sourcepub fn register_partial_contract<Abi, B>(
&mut self,
expression: impl RegisterCodeSource,
contract_builder: B,
sub_contract_name: &str,
)where
Abi: ContractAbiProvider,
B: CallableContractBuilder,
pub fn register_partial_contract<Abi, B>(
&mut self,
expression: impl RegisterCodeSource,
contract_builder: B,
sub_contract_name: &str,
)where
Abi: ContractAbiProvider,
B: CallableContractBuilder,
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.
Sourcepub fn register_contract_variant<B>(
&mut self,
expression: impl RegisterCodeSource,
contract_builder: B,
contract_variant: &ContractVariant,
)where
B: CallableContractBuilder,
pub fn register_contract_variant<B>(
&mut self,
expression: impl RegisterCodeSource,
contract_builder: B,
contract_variant: &ContractVariant,
)where
B: CallableContractBuilder,
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
impl ScenarioWorld
pub fn for_each_runner_mut<F: FnMut(&mut dyn ScenarioRunner)>(&mut self, f: F)
Source§impl ScenarioWorld
impl ScenarioWorld
Sourcepub fn external_steps(&mut self, step: ExternalStepsStep) -> &mut Self
pub fn external_steps(&mut self, step: ExternalStepsStep) -> &mut Self
Imports and processes steps from an external scenario file.
Sourcepub fn set_state_step(&mut self, step: SetStateStep) -> &mut Self
pub fn set_state_step(&mut self, step: SetStateStep) -> &mut Self
Adds a SC call step, then executes it.
Sourcepub fn sc_call<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScCallStep>,
pub fn sc_call<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScCallStep>,
Adds a SC call step, then executes it.
pub fn sc_call_use_raw_response<S, F>( &mut self, step: S, use_raw_response: F, ) -> &mut Self
pub fn sc_call_use_result<OriginalResult, RequestedResult, F>(
&mut self,
step: TypedScCall<OriginalResult>,
use_result: F,
) -> &mut Selfwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
F: FnOnce(TypedResponse<RequestedResult>),
pub fn sc_call_get_result<OriginalResult, RequestedResult>(
&mut self,
step: TypedScCall<OriginalResult>,
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
Sourcepub fn sc_query<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScQueryStep>,
pub fn sc_query<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScQueryStep>,
Adds a SC query step, then executes it.
pub fn sc_query_use_raw_response<S, F>( &mut self, step: S, use_raw_response: F, ) -> &mut Self
pub fn sc_query_use_result<OriginalResult, RequestedResult, F>(
&mut self,
step: TypedScQuery<OriginalResult>,
use_result: F,
) -> &mut Selfwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
F: FnOnce(TypedResponse<RequestedResult>),
pub fn sc_query_get_result<OriginalResult, RequestedResult>(
&mut self,
step: TypedScQuery<OriginalResult>,
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
Sourcepub fn quick_query<CC, RequestedResult>(
&mut self,
contract_call: CC,
) -> RequestedResultwhere
CC: ContractCall<StaticApi>,
RequestedResult: TopDecodeMulti + TypeAbiFrom<CC::OriginalResult>,
pub fn quick_query<CC, RequestedResult>(
&mut self,
contract_call: CC,
) -> RequestedResultwhere
CC: ContractCall<StaticApi>,
RequestedResult: TopDecodeMulti + TypeAbiFrom<CC::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.
Sourcepub fn sc_deploy<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScDeployStep>,
pub fn sc_deploy<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScDeployStep>,
Adds a SC deploy step, then executes it.
pub fn sc_deploy_use_raw_response<S, F>( &mut self, step: S, use_raw_response: F, ) -> &mut Self
pub fn sc_deploy_use_result<OriginalResult, RequestedResult, F>(
&mut self,
step: TypedScDeploy<OriginalResult>,
use_result: F,
) -> &mut Selfwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
F: FnOnce(Address, TypedResponse<RequestedResult>),
pub fn sc_deploy_get_result<OriginalResult, RequestedResult>(
&mut self,
step: TypedScDeploy<OriginalResult>,
) -> (Address, RequestedResult)where
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
Sourcepub fn transfer_step(&mut self, step: TransferStep) -> &mut Self
pub fn transfer_step(&mut self, step: TransferStep) -> &mut Self
Adds a simple transfer step, then executes it.
Sourcepub fn validator_reward_step(&mut self, step: ValidatorRewardStep) -> &mut Self
pub fn validator_reward_step(&mut self, step: ValidatorRewardStep) -> &mut Self
Adds a validator reward step, then executes it.
Sourcepub fn check_state_step(&mut self, step: CheckStateStep) -> &mut Self
pub fn check_state_step(&mut self, step: CheckStateStep) -> &mut Self
Adds a check state step, then executes it.
Sourcepub fn dump_state_step(&mut self) -> &mut Self
pub fn dump_state_step(&mut self) -> &mut Self
Adds a dump state step, then executes it.
Source§impl ScenarioWorld
impl ScenarioWorld
pub fn sc_call_step<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScCallStep>,
sc_call
.pub fn sc_query_step<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScQueryStep>,
sc_query
.pub fn sc_deploy_step<S>(&mut self, step: S) -> &mut Selfwhere
S: AsMut<ScDeployStep>,
sc_deploy
.pub fn mandos_set_state(&mut self, step: SetStateStep) -> &mut Self
set_state_step
instead.pub fn mandos_sc_call(&mut self, step: ScCallStep) -> &mut Self
sc_call_step
instead.pub fn mandos_sc_query(&mut self, step: ScQueryStep) -> &mut Self
sc_query_step
instead.pub fn mandos_sc_deploy(&mut self, step: ScDeployStep) -> &mut Self
sc_deploy_step
instead.pub fn mandos_transfer(&mut self, step: TransferStep) -> &mut Self
transfer_step
instead.pub fn mandos_validator_reward( &mut self, step: ValidatorRewardStep, ) -> &mut Self
validator_reward_step
instead.pub fn mandos_check_state(&mut self, step: CheckStateStep) -> &mut Self
check_state_step
instead.pub fn mandos_dump_state(&mut self) -> &mut Self
dump_state_step
instead.Source§impl ScenarioWorld
impl ScenarioWorld
pub fn whitebox_query<ContractObj, F>(
&mut self,
whitebox_contract: &WhiteboxContract<ContractObj>,
f: F,
) -> &mut Selfwhere
ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
F: FnOnce(ContractObj),
whitebox
, as part of the unified transaction syntax.pub fn whitebox_query_check<ContractObj, F, C>(
&mut self,
whitebox_contract: &WhiteboxContract<ContractObj>,
f: F,
check_result: C,
) -> &mut Selfwhere
ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
F: FnOnce(ContractObj),
C: FnOnce(TxResult),
whitebox
, as part of the unified transaction syntax.pub fn whitebox_call<ContractObj, F>(
&mut self,
whitebox_contract: &WhiteboxContract<ContractObj>,
sc_call_step: ScCallStep,
f: F,
) -> &mut Selfwhere
ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
F: FnOnce(ContractObj),
whitebox
, as part of the unified transaction syntax.pub fn whitebox_call_check<ContractObj, F, C>(
&mut self,
whitebox_contract: &WhiteboxContract<ContractObj>,
sc_call_step: ScCallStep,
f: F,
check_result: C,
) -> &mut Selfwhere
ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
F: FnOnce(ContractObj),
C: FnOnce(TxResult),
whitebox
, as part of the unified transaction syntax.pub fn whitebox_deploy<ContractObj, F>(
&mut self,
whitebox_contract: &WhiteboxContract<ContractObj>,
sc_deploy_step: ScDeployStep,
f: F,
) -> &mut Selfwhere
ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
F: FnOnce(ContractObj),
whitebox
, as part of the unified transaction syntax.pub fn whitebox_deploy_check<ContractObj, F, C>(
&mut self,
whitebox_contract: &WhiteboxContract<ContractObj>,
sc_deploy_step: ScDeployStep,
f: F,
check_result: C,
) -> &mut Selfwhere
ContractObj: ContractBase<Api = DebugApi> + CallableContract + 'static,
F: FnOnce(ContractObj),
C: FnOnce(TxResult),
whitebox
, as part of the unified transaction syntax.Source§impl ScenarioWorld
impl ScenarioWorld
pub fn check_account<A>(&mut self, address: A) -> CheckStateBuilder<'_>
Source§impl ScenarioWorld
impl ScenarioWorld
pub fn tx(&mut self) -> TxBaseWithEnv<ScenarioEnvExec<'_>>
pub fn chain_call<From, To, Payment, Gas, RH, F>(&mut self, f: F) -> &mut Selfwhere
From: TxFromSpecified<ScenarioTxEnvData>,
To: TxToSpecified<ScenarioTxEnvData>,
Payment: TxPayment<ScenarioTxEnvData>,
Gas: TxGas<ScenarioTxEnvData>,
RH: RHListExec<TxResponse, ScenarioTxEnvData, ListReturns = ()>,
F: FnOnce(TxBaseWithEnv<ScenarioTxEnvData>) -> Tx<ScenarioTxEnvData, From, To, Payment, Gas, FunctionCall<StaticApi>, RH>,
Source§impl ScenarioWorld
impl ScenarioWorld
pub fn chain_deploy<From, Payment, Gas, CodeValue, RH, F>(
&mut self,
f: F,
) -> &mut Selfwhere
From: TxFromSpecified<ScenarioTxEnvData>,
Payment: TxPayment<ScenarioTxEnvData>,
Gas: TxGas<ScenarioTxEnvData>,
CodeValue: TxCodeValue<ScenarioTxEnvData>,
RH: RHListExec<TxResponse, ScenarioTxEnvData, ListReturns = ()>,
F: FnOnce(TxBaseWithEnv<ScenarioTxEnvData>) -> Tx<ScenarioTxEnvData, From, (), Payment, Gas, DeployCall<ScenarioTxEnvData, Code<CodeValue>>, RH>,
Source§impl ScenarioWorld
impl ScenarioWorld
pub fn query(&mut self) -> TxBaseWithEnv<ScenarioEnvQuery<'_>>
pub fn chain_query<To, Payment, RH, F>(&mut self, f: F) -> &mut Selfwhere
To: TxToSpecified<ScenarioTxEnvData>,
Payment: TxNoPayment<ScenarioTxEnvData>,
RH: RHListExec<TxResponse, ScenarioTxEnvData, ListReturns = ()>,
F: FnOnce(TxBaseWithEnv<ScenarioTxEnvData>) -> Tx<ScenarioTxEnvData, (), To, Payment, (), FunctionCall<StaticApi>, RH>,
Source§impl ScenarioWorld
impl ScenarioWorld
pub fn account<A>( &mut self, address_expr: A, ) -> SetStateBuilder<'_, AccountItem>
pub fn new_address<CA, CN, NA>(
&mut self,
creator_address_expr: CA,
creator_nonce_expr: CN,
new_address_expr: NA,
) -> SetStateBuilder<'_, NewAddressItem>where
CA: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
CN: AnnotatedValue<ScenarioTxEnvData, u64>,
NA: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
pub fn create_account_raw<A, V>(
&mut self,
address: A,
egld_balance: V,
) -> SetStateBuilder<'_, AccountItem>where
A: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
V: AnnotatedValue<ScenarioTxEnvData, BigUint<StaticApi>>,
pub fn set_egld_balance<A, V>(&mut self, address: A, balance: V)where
A: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
V: AnnotatedValue<ScenarioTxEnvData, BigUint<StaticApi>>,
pub fn set_esdt_balance<A, V>(
&mut self,
address: A,
token_id: &[u8],
balance: V,
)where
A: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
V: AnnotatedValue<ScenarioTxEnvData, BigUint<StaticApi>>,
pub fn set_nft_balance_all_properties<A, B, N, T: TopEncode, 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>],
)where
A: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
B: AnnotatedValue<ScenarioTxEnvData, BigUint<StaticApi>>,
N: AnnotatedValue<ScenarioTxEnvData, u64>,
R: AnnotatedValue<ScenarioTxEnvData, u64>,
C: AnnotatedValue<ScenarioTxEnvData, ManagedAddress<StaticApi>>,
pub fn set_developer_rewards<A: Copy, V: Copy>( &mut self, address: A, developer_rewards: V, )
pub fn set_esdt_local_roles<A>( &mut self, address: A, token_id: &[u8], roles: &[EsdtLocalRole], )
pub fn current_block(&mut self) -> SetStateBuilder<'_, BlockItem>
pub fn previous_block(&mut self) -> SetStateBuilder<'_, BlockItem>
Trait Implementations§
Source§impl Default for ScenarioWorld
impl Default for ScenarioWorld
Source§impl ScenarioRunner for ScenarioWorld
impl ScenarioRunner for ScenarioWorld
fn run_external_steps(&mut self, step: &ExternalStepsStep)
fn run_set_state_step(&mut self, step: &SetStateStep)
fn run_sc_call_step(&mut self, step: &mut ScCallStep)
fn run_multi_sc_call_step(&mut self, steps: &mut [ScCallStep])
fn run_multi_sc_deploy_step(&mut self, steps: &mut [ScDeployStep])
fn run_sc_query_step(&mut self, step: &mut ScQueryStep)
fn run_sc_deploy_step(&mut self, step: &mut ScDeployStep)
fn run_transfer_step(&mut self, step: &TransferStep)
fn run_validator_reward_step(&mut self, step: &ValidatorRewardStep)
fn run_check_state_step(&mut self, step: &CheckStateStep)
fn run_dump_state_step(&mut self)
Source§fn run_scenario(&mut self, scenario: &Scenario)
fn run_scenario(&mut self, scenario: &Scenario)
Source§impl TypedScCallExecutor for ScenarioWorld
impl TypedScCallExecutor for ScenarioWorld
Source§fn execute_typed_sc_call<OriginalResult, RequestedResult>(
&mut self,
typed_sc_call: TypedScCall<OriginalResult>,
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
fn execute_typed_sc_call<OriginalResult, RequestedResult>(
&mut self,
typed_sc_call: TypedScCall<OriginalResult>,
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
Source§impl TypedScDeployExecutor for ScenarioWorld
impl TypedScDeployExecutor for ScenarioWorld
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
impl TypedScQueryExecutor for ScenarioWorld
Source§fn execute_typed_sc_query<OriginalResult, RequestedResult>(
&mut self,
typed_sc_query: TypedScQuery<OriginalResult>,
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: TopDecodeMulti + TypeAbiFrom<OriginalResult>,
fn execute_typed_sc_query<OriginalResult, RequestedResult>(
&mut self,
typed_sc_query: TypedScQuery<OriginalResult>,
) -> RequestedResultwhere
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§
impl Freeze for ScenarioWorld
impl !RefUnwindSafe for ScenarioWorld
impl Send for ScenarioWorld
impl Sync for ScenarioWorld
impl Unpin for ScenarioWorld
impl !UnwindSafe for ScenarioWorld
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> InterpretableFrom<T> for T
impl<T> InterpretableFrom<T> for T
fn interpret_from(from: T, _context: &InterpreterContext) -> T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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