Struct multiversx_chain_vm::world_mock::BlockchainMock
source · pub struct BlockchainMock {
pub accounts: HashMap<Address, AccountData>,
pub builtin_functions: Rc<BuiltinFunctionMap>,
pub addr_to_pretty_string_map: HashMap<Address, String>,
pub new_addresses: HashMap<(Address, u64), Address>,
pub previous_block_info: BlockInfo,
pub current_block_info: BlockInfo,
pub contract_map: ContractMap,
pub current_dir: PathBuf,
pub scenario_trace: Scenario,
}
Fields§
§accounts: HashMap<Address, AccountData>
§builtin_functions: Rc<BuiltinFunctionMap>
§addr_to_pretty_string_map: HashMap<Address, String>
§new_addresses: HashMap<(Address, u64), Address>
§previous_block_info: BlockInfo
§current_block_info: BlockInfo
§contract_map: ContractMap
§current_dir: PathBuf
§scenario_trace: Scenario
Implementations§
source§impl BlockchainMock
impl BlockchainMock
pub fn perform_check_state( &mut self, check_state_step: CheckStateStep ) -> &mut Self
pub fn perform_dump_state(&mut self) -> &mut Self
source§impl BlockchainMock
impl BlockchainMock
sourcepub fn perform_sc_call(&mut self, sc_call_step: ScCallStep) -> &mut Self
pub fn perform_sc_call(&mut self, sc_call_step: ScCallStep) -> &mut Self
Adds a SC call step, as specified in the sc_call_step
argument, then executes it.
sourcepub fn perform_sc_call_get_result<OriginalResult, RequestedResult>(
&mut self,
typed_sc_call: TypedScCall<OriginalResult>
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: CodecFrom<OriginalResult>,
pub fn perform_sc_call_get_result<OriginalResult, RequestedResult>( &mut self, typed_sc_call: TypedScCall<OriginalResult> ) -> RequestedResultwhere OriginalResult: TopEncodeMulti, RequestedResult: CodecFrom<OriginalResult>,
Adds a SC call step, executes it and retrieves the transaction result (“out” field).
The transaction is expected to complete successfully.
It takes the contract_call
argument separately from the SC call step,
so we can benefit from type inference in the result.
source§impl BlockchainMock
impl BlockchainMock
sourcepub fn perform_sc_deploy(&mut self, sc_deploy_step: ScDeployStep) -> &mut Self
pub fn perform_sc_deploy(&mut self, sc_deploy_step: ScDeployStep) -> &mut Self
Adds a SC deploy step, as specified in the sc_deploy_step
argument, then executes it.
sourcepub fn perform_sc_deploy_get_result<OriginalResult, RequestedResult>(
&mut self,
typed_sc_deploy: TypedScDeploy<OriginalResult>
) -> (Address, RequestedResult)where
OriginalResult: TopEncodeMulti,
RequestedResult: CodecFrom<OriginalResult>,
pub fn perform_sc_deploy_get_result<OriginalResult, RequestedResult>( &mut self, typed_sc_deploy: TypedScDeploy<OriginalResult> ) -> (Address, RequestedResult)where OriginalResult: TopEncodeMulti, RequestedResult: CodecFrom<OriginalResult>,
Adds a SC deploy step, executes it and retrieves the transaction result (“out” field).
The transaction is expected to complete successfully.
It takes the contract_call
argument separately from the SC call step,
so we can benefit from type inference in the result.
source§impl BlockchainMock
impl BlockchainMock
sourcepub fn perform_sc_query(&mut self, sc_query_step: ScQueryStep) -> &mut Self
pub fn perform_sc_query(&mut self, sc_query_step: ScQueryStep) -> &mut Self
Adds a SC query step, as specified in the sc_query_step
argument, then executes it.
sourcepub fn perform_sc_query_expect_result<OriginalResult, RequestedResult>(
&mut self,
typed_sc_query: TypedScQuery<OriginalResult>
) -> RequestedResultwhere
OriginalResult: TopEncodeMulti,
RequestedResult: CodecFrom<OriginalResult>,
pub fn perform_sc_query_expect_result<OriginalResult, RequestedResult>( &mut self, typed_sc_query: TypedScQuery<OriginalResult> ) -> RequestedResultwhere OriginalResult: TopEncodeMulti, RequestedResult: CodecFrom<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.
source§impl BlockchainMock
impl BlockchainMock
sourcepub fn quick_query<CC, RequestedResult>(
&mut self,
contract_call: CC
) -> RequestedResultwhere
CC: ContractCall<DebugApi>,
RequestedResult: CodecFrom<CC::OriginalResult>,
pub fn quick_query<CC, RequestedResult>( &mut self, contract_call: CC ) -> RequestedResultwhere CC: ContractCall<DebugApi>, RequestedResult: CodecFrom<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.
source§impl BlockchainMock
impl BlockchainMock
pub fn perform_set_state(&mut self, set_state_step: SetStateStep) -> &mut Self
source§impl BlockchainMock
impl BlockchainMock
pub fn perform_transfer(&mut self, transfer_step: TransferStep) -> &mut Self
pub fn perform_validator_reward( &mut self, validator_rewards_step: ValidatorRewardStep ) -> &mut Self
source§impl BlockchainMock
impl BlockchainMock
pub fn account_exists(&self, address: &Address) -> bool
pub fn contains_contract(&self, contract_path_expr: &str) -> bool
pub fn commit_updates(&mut self, updates: BlockchainUpdate)
pub fn increase_account_nonce(&mut self, address: &Address)
pub fn subtract_tx_gas( &mut self, address: &Address, gas_limit: u64, gas_price: u64 )
pub fn increase_validator_reward(&mut self, address: &Address, amount: &BigUint)
pub fn with_borrowed<F, R>(&mut self, f: F) -> Rwhere F: FnOnce(Self) -> (R, Self),
source§impl BlockchainMock
impl BlockchainMock
pub fn add_account(&mut self, acct: AccountData)
pub fn add_addr_scenario_string(&mut self, address: Address)
pub fn validate_and_add_account(&mut self, acct: AccountData)
pub fn update_accounts(&mut self, accounts: HashMap<Address, AccountData>)
pub fn print_accounts(&self)
pub fn put_new_address( &mut self, creator_address: Address, creator_nonce: u64, new_address: Address )
pub fn get_new_address( &self, creator_address: Address, creator_nonce: u64 ) -> Option<Address>
pub fn validate_account(&self, account: &AccountData)
pub fn check_account_has_code(&self, account: &AccountData) -> bool
source§impl BlockchainMock
impl BlockchainMock
pub fn interpreter_context(&self) -> InterpreterContext
pub fn register_contract_container( &mut self, expression: &str, contract_container: ContractContainer )
sourcepub fn register_contract<B: CallableContractBuilder>(
&mut self,
expression: &str,
contract_builder: B
)
pub fn register_contract<B: CallableContractBuilder>( &mut self, expression: &str, contract_builder: B )
Links a contract path in a test to a contract implementation.
sourcepub fn register_partial_contract<Abi, B>(
&mut self,
expression: &str,
contract_builder: B,
sub_contract_name: &str
)where
Abi: ContractAbiProvider,
B: CallableContractBuilder,
pub fn register_partial_contract<Abi, B>( &mut self, expression: &str, 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.
source§impl BlockchainMock
impl BlockchainMock
pub fn write_scenario_trace<P: AsRef<Path>>(&mut self, file_path: P)
source§impl BlockchainMock
impl BlockchainMock
pub fn create_tx_info(&self, contract_address: &Address) -> BlockchainTxInfo
Trait Implementations§
source§impl Debug for BlockchainMock
impl Debug for BlockchainMock
source§impl Default for BlockchainMock
impl Default for BlockchainMock
source§impl StepHandler for BlockchainMock
impl StepHandler for BlockchainMock
source§fn sc_call_step(&mut self, step: ScCallStep) -> &mut Self
fn sc_call_step(&mut self, step: ScCallStep) -> &mut Self
Adds a SC call step, as specified in the sc_call_step
argument, then executes it.
source§fn sc_query_step(&mut self, step: ScQueryStep) -> &mut Self
fn sc_query_step(&mut self, step: ScQueryStep) -> &mut Self
Adds a SC query step, as specified in the sc_query_step
argument, then executes it.
source§fn sc_deploy_step(&mut self, step: ScDeployStep) -> &mut Self
fn sc_deploy_step(&mut self, step: ScDeployStep) -> &mut Self
Adds a SC deploy step, as specified in the sc_deploy_step
argument, then executes it.
source§fn set_state_step(&mut self, step: SetStateStep) -> &mut Self
fn set_state_step(&mut self, step: SetStateStep) -> &mut Self
source§fn transfer_step(&mut self, step: TransferStep) -> &mut Self
fn transfer_step(&mut self, step: TransferStep) -> &mut Self
source§fn validator_reward_step(&mut self, step: ValidatorRewardStep) -> &mut Self
fn validator_reward_step(&mut self, step: ValidatorRewardStep) -> &mut Self
source§fn check_state_step(&mut self, step: CheckStateStep) -> &mut Self
fn check_state_step(&mut self, step: CheckStateStep) -> &mut Self
source§fn dump_state_step(&mut self) -> &mut Self
fn dump_state_step(&mut self) -> &mut Self
source§fn mandos_set_state(&mut self, step: SetStateStep) -> &mut Self
fn mandos_set_state(&mut self, step: SetStateStep) -> &mut Self
set_state_step
instead.source§fn mandos_sc_call(&mut self, step: ScCallStep) -> &mut Self
fn mandos_sc_call(&mut self, step: ScCallStep) -> &mut Self
sc_call_step
instead.source§fn mandos_sc_query(&mut self, step: ScQueryStep) -> &mut Self
fn mandos_sc_query(&mut self, step: ScQueryStep) -> &mut Self
sc_query_step
instead.source§fn mandos_sc_deploy(&mut self, step: ScDeployStep) -> &mut Self
fn mandos_sc_deploy(&mut self, step: ScDeployStep) -> &mut Self
sc_deploy_step
instead.source§fn mandos_transfer(&mut self, step: TransferStep) -> &mut Self
fn mandos_transfer(&mut self, step: TransferStep) -> &mut Self
transfer_step
instead.source§fn mandos_validator_reward(&mut self, step: ValidatorRewardStep) -> &mut Self
fn mandos_validator_reward(&mut self, step: ValidatorRewardStep) -> &mut Self
validator_reward_step
instead.source§fn mandos_check_state(&mut self, step: CheckStateStep) -> &mut Self
fn mandos_check_state(&mut self, step: CheckStateStep) -> &mut Self
check_state_step
instead.source§fn mandos_dump_state(&mut self) -> &mut Self
fn mandos_dump_state(&mut self) -> &mut Self
dump_state_step
instead.