Struct scrypto_unit::TestRunner
source · pub struct TestRunner<E: NativeVmExtension, D: TestDatabase> {
scrypto_vm: ScryptoVm<DefaultWasmEngine>,
native_vm: NativeVm<E>,
database: D,
next_private_key: u64,
next_transaction_nonce: u32,
trace: bool,
collected_events: Vec<Vec<(EventTypeIdentifier, Vec<u8>)>>,
xrd_free_credits_used: bool,
skip_receipt_check: bool,
}
Fields§
§scrypto_vm: ScryptoVm<DefaultWasmEngine>
§native_vm: NativeVm<E>
§database: D
§next_private_key: u64
§next_transaction_nonce: u32
§trace: bool
§collected_events: Vec<Vec<(EventTypeIdentifier, Vec<u8>)>>
§xrd_free_credits_used: bool
§skip_receipt_check: bool
Implementations§
source§impl<E: NativeVmExtension> TestRunner<E, InMemorySubstateDatabase>
impl<E: NativeVmExtension> TestRunner<E, InMemorySubstateDatabase>
pub fn create_snapshot(&self) -> TestRunnerSnapshot
pub fn restore_snapshot(&mut self, snapshot: TestRunnerSnapshot)
source§impl<E: NativeVmExtension, D: TestDatabase> TestRunner<E, D>
impl<E: NativeVmExtension, D: TestDatabase> TestRunner<E, D>
pub fn faucet_component(&self) -> GlobalAddress
pub fn substate_db(&self) -> &D
pub fn substate_db_mut(&mut self) -> &mut D
pub fn collected_events(&self) -> &Vec<Vec<(EventTypeIdentifier, Vec<u8>)>>
pub fn next_private_key(&mut self) -> u64
pub fn next_transaction_nonce(&mut self) -> u32
pub fn new_key_pair(&mut self) -> (Secp256k1PublicKey, Secp256k1PrivateKey)
pub fn new_ed25519_key_pair(&mut self) -> (Ed25519PublicKey, Ed25519PrivateKey)
pub fn new_key_pair_with_auth_address( &mut self ) -> (Secp256k1PublicKey, Secp256k1PrivateKey, NonFungibleGlobalId)
pub fn set_metadata( &mut self, address: GlobalAddress, key: &str, value: &str, proof: NonFungibleGlobalId )
pub fn get_metadata( &mut self, address: GlobalAddress, key: &str ) -> Option<MetadataValue>
pub fn inspect_component_royalty( &mut self, component_address: ComponentAddress ) -> Decimal
pub fn inspect_package_royalty( &mut self, package_address: PackageAddress ) -> Option<Decimal>
pub fn find_all_nodes(&self) -> IndexSet<NodeId>
pub fn find_all_components(&self) -> Vec<ComponentAddress>
pub fn find_all_packages(&self) -> Vec<PackageAddress>
pub fn find_all_resources(&self) -> Vec<ResourceAddress>
pub fn get_package_scrypto_schemas( &self, package_address: &PackageAddress ) -> IndexMap<SchemaHash, VersionedScryptoSchema>
pub fn get_package_blueprint_definitions( &self, package_address: &PackageAddress ) -> IndexMap<BlueprintVersionKey, BlueprintDefinition>
pub fn sum_descendant_balance_changes( &mut self, commit: &CommitResult, node_id: &NodeId ) -> IndexMap<ResourceAddress, BalanceChange>
pub fn get_component_vaults( &mut self, component_address: ComponentAddress, resource_address: ResourceAddress ) -> Vec<NodeId>
pub fn get_component_balance( &mut self, account_address: ComponentAddress, resource_address: ResourceAddress ) -> Decimal
pub fn inspect_vault_balance(&mut self, vault_id: NodeId) -> Option<Decimal>
pub fn inspect_fungible_vault(&mut self, vault_id: NodeId) -> Option<Decimal>
pub fn inspect_non_fungible_vault( &mut self, vault_id: NodeId ) -> Option<(Decimal, Box<dyn Iterator<Item = NonFungibleLocalId> + '_>)>
pub fn get_component_resources( &mut self, component_address: ComponentAddress ) -> HashMap<ResourceAddress, Decimal>
pub fn component_state<T: ScryptoDecode>( &self, component_address: ComponentAddress ) -> T
pub fn get_non_fungible_data<T: NonFungibleData>( &self, resource: ResourceAddress, non_fungible_id: NonFungibleLocalId ) -> T
pub fn get_kv_store_entry<K: ScryptoEncode, V: ScryptoEncode + ScryptoDecode>( &self, kv_store_id: Own, key: &K ) -> Option<V>
pub fn load_account_from_faucet(&mut self, account_address: ComponentAddress)
pub fn new_account_advanced( &mut self, owner_role: OwnerRole ) -> ComponentAddress
pub fn new_virtual_account( &mut self ) -> (Secp256k1PublicKey, Secp256k1PrivateKey, ComponentAddress)
pub fn new_ed25519_virtual_account( &mut self ) -> (Ed25519PublicKey, Ed25519PrivateKey, ComponentAddress)
pub fn get_active_validator_info_by_key( &self, key: &Secp256k1PublicKey ) -> ValidatorSubstate
pub fn get_validator_info(&self, address: ComponentAddress) -> ValidatorSubstate
pub fn get_active_validator_with_key( &self, key: &Secp256k1PublicKey ) -> ComponentAddress
pub fn new_allocated_account( &mut self ) -> (Secp256k1PublicKey, Secp256k1PrivateKey, ComponentAddress)
pub fn new_ed25519_virtual_account_with_access_controller( &mut self, n_out_of_4: u8 ) -> (Ed25519PublicKey, Ed25519PrivateKey, Ed25519PublicKey, Ed25519PrivateKey, Ed25519PublicKey, Ed25519PrivateKey, Ed25519PublicKey, Ed25519PrivateKey, ComponentAddress, ComponentAddress)
pub fn new_account( &mut self, is_virtual: bool ) -> (Secp256k1PublicKey, Secp256k1PrivateKey, ComponentAddress)
pub fn new_identity<P: Into<PublicKey> + Clone + HasPublicKeyHash>( &mut self, pk: P, is_virtual: bool ) -> ComponentAddress
pub fn new_securified_identity( &mut self, account: ComponentAddress ) -> ComponentAddress
pub fn new_validator_with_pub_key( &mut self, pub_key: Secp256k1PublicKey, account: ComponentAddress ) -> ComponentAddress
pub fn new_staked_validator_with_pub_key( &mut self, pub_key: Secp256k1PublicKey, account: ComponentAddress ) -> ComponentAddress
pub fn publish_native_package( &mut self, native_package_code_id: u64, definition: PackageDefinition ) -> PackageAddress
pub fn publish_package_at_address<P: Into<PackagePublishingSource>>( &mut self, source: P, address: PackageAddress )
pub fn publish_package<P: Into<PackagePublishingSource>>( &mut self, source: P, metadata: BTreeMap<String, MetadataValue>, owner_role: OwnerRole ) -> PackageAddress
pub fn try_publish_package<P: Into<PackagePublishingSource>>( &mut self, source: P ) -> TransactionReceipt
pub fn publish_package_simple<P: Into<PackagePublishingSource>>( &mut self, source: P ) -> PackageAddress
pub fn publish_package_with_owner<P: Into<PackagePublishingSource>>( &mut self, source: P, owner_badge: NonFungibleGlobalId ) -> PackageAddress
pub fn compile<P: AsRef<Path>>( &mut self, package_dir: P ) -> (Vec<u8>, PackageDefinition)
pub fn compile_and_publish<P: AsRef<Path>>( &mut self, package_dir: P ) -> PackageAddress
pub fn compile_and_publish_at_address<P: AsRef<Path>>( &mut self, package_dir: P, address: PackageAddress )
pub fn publish_retain_blueprints<P: Into<PackagePublishingSource>, F: FnMut(&String, &mut BlueprintDefinitionInit) -> bool>( &mut self, source: P, retain: F ) -> PackageAddress
pub fn compile_and_publish_with_owner<P: AsRef<Path>>( &mut self, package_dir: P, owner_badge: NonFungibleGlobalId ) -> PackageAddress
pub fn execute_unsigned_built_manifest_with_faucet_lock_fee( &mut self, create_manifest: impl FnOnce(ManifestBuilder) -> ManifestBuilder ) -> TransactionReceipt
pub fn execute_unsigned_built_manifest( &mut self, create_manifest: impl FnOnce(ManifestBuilder) -> ManifestBuilder ) -> TransactionReceipt
pub fn execute_built_manifest_with_faucet_lock_fee( &mut self, create_manifest: impl FnOnce(ManifestBuilder) -> ManifestBuilder, signatures: impl ResolvableTransactionSignatures ) -> TransactionReceipt
pub fn execute_built_manifest( &mut self, create_manifest: impl FnOnce(ManifestBuilder) -> ManifestBuilder, signatures: impl ResolvableTransactionSignatures ) -> TransactionReceipt
pub fn execute_manifest_with_fee_from_faucet<T>(
&mut self,
manifest: TransactionManifestV1,
amount: Decimal,
initial_proofs: T
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_manifest_with_fee_from_faucet_with_system<'a, T, R: WrappedSystem<Vm<'a, DefaultWasmEngine, E>>>(
&'a mut self,
manifest: TransactionManifestV1,
amount: Decimal,
initial_proofs: T,
init: R::Init
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_manifest_ignoring_fee<T>(
&mut self,
manifest: TransactionManifestV1,
initial_proofs: T
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_raw_transaction( &mut self, network: &NetworkDefinition, raw_transaction: &RawNotarizedTransaction ) -> TransactionReceipt
pub fn execute_manifest<T>(
&mut self,
manifest: TransactionManifestV1,
initial_proofs: T
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_manifest_with_system<'a, T, R: WrappedSystem<Vm<'a, DefaultWasmEngine, E>>>(
&'a mut self,
manifest: TransactionManifestV1,
initial_proofs: T,
init: R::Init
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_manifest_with_costing_params<T>(
&mut self,
manifest: TransactionManifestV1,
initial_proofs: T,
costing_parameters: CostingParameters
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_manifest_with_execution_cost_unit_limit<T>(
&mut self,
manifest: TransactionManifestV1,
initial_proofs: T,
execution_cost_unit_limit: u32
) -> TransactionReceiptwhere
T: IntoIterator<Item = NonFungibleGlobalId>,
pub fn execute_transaction( &mut self, executable: Executable<'_>, costing_parameters: CostingParameters, execution_config: ExecutionConfig ) -> TransactionReceipt
pub fn execute_transaction_with_system<'a, T: WrappedSystem<Vm<'a, DefaultWasmEngine, E>>>( &'a mut self, executable: Executable<'_>, costing_parameters: CostingParameters, execution_config: ExecutionConfig, init: T::Init ) -> TransactionReceipt
pub fn preview( &mut self, preview_intent: PreviewIntentV1, network: &NetworkDefinition ) -> Result<TransactionReceipt, PreviewError>
pub fn preview_manifest( &mut self, manifest: TransactionManifestV1, signer_public_keys: Vec<PublicKey>, tip_percentage: u16, flags: PreviewFlags ) -> TransactionReceipt
sourcepub fn call_function(
&mut self,
package_address: impl ResolvablePackageAddress,
blueprint_name: impl Into<String>,
function_name: impl Into<String>,
arguments: impl ResolvableArguments
) -> TransactionReceipt
pub fn call_function( &mut self, package_address: impl ResolvablePackageAddress, blueprint_name: impl Into<String>, function_name: impl Into<String>, arguments: impl ResolvableArguments ) -> TransactionReceipt
Calls a package blueprint function with the given arguments, paying the fee from the faucet.
The arguments should be one of:
- A tuple, such as
()
,(x,)
or(x, y, z)
- IMPORTANT: If calling with a single argument, you must include a trailing comma in the tuple declaration. This ensures that the rust compiler knows it’s a singleton tuple, rather than just some brackets around the inner value.
- A struct which implements
ManifestEncode
representing the arguments manifest_args!(x, y, z)
Notes:
- Buckets and signatures are not supported - instead use
execute_manifest_ignoring_fee
andManifestBuilder
directly. - Call
.expect_commit_success()
on the receipt to get access to receipt details.
sourcepub fn construct_new(
&mut self,
package_address: impl ResolvablePackageAddress,
blueprint_name: impl Into<String>,
function_name: impl Into<String>,
arguments: impl ResolvableArguments
) -> ComponentAddress
pub fn construct_new( &mut self, package_address: impl ResolvablePackageAddress, blueprint_name: impl Into<String>, function_name: impl Into<String>, arguments: impl ResolvableArguments ) -> ComponentAddress
Calls a package blueprint function with the given arguments, and assumes it constructs a single component successfully. It returns the address of the first created component.
The arguments should be one of:
- A tuple, such as
()
,(x,)
or(x, y, z)
- IMPORTANT: If calling with a single argument, you must include a trailing comma in the tuple declaration. This ensures that the rust compiler knows it’s a singleton tuple, rather than just some brackets around the inner value.
- A struct which implements
ManifestEncode
representing the arguments manifest_args!(x, y, z)
Notes:
- Buckets and signatures are not supported - instead use
execute_manifest_ignoring_fee
andManifestBuilder
directly.
sourcepub fn call_method(
&mut self,
address: impl ResolvableGlobalAddress,
method_name: impl Into<String>,
args: impl ResolvableArguments
) -> TransactionReceipt
pub fn call_method( &mut self, address: impl ResolvableGlobalAddress, method_name: impl Into<String>, args: impl ResolvableArguments ) -> TransactionReceipt
Calls a component method with the given arguments, paying the fee from the faucet.
The arguments should be one of:
- A tuple, such as
()
,(x,)
or(x, y, z)
- IMPORTANT: If calling with a single argument, you must include a trailing comma in the tuple declaration. This ensures that the rust compiler knows it’s a singleton tuple, rather than just some brackets around the inner value.
- A struct which implements
ManifestEncode
representing the arguments manifest_args!(x, y, z)
Notes:
- Buckets and signatures are not supported - instead use
execute_manifest_ignoring_fee
andManifestBuilder
directly. - Call
.expect_commit_success()
on the receipt to get access to receipt details.
fn create_fungible_resource_and_deposit( &mut self, owner_role: OwnerRole, resource_roles: FungibleResourceRoles, to: ComponentAddress ) -> ResourceAddress
pub fn create_restricted_token( &mut self, account: ComponentAddress ) -> (ResourceAddress, ResourceAddress, ResourceAddress, ResourceAddress, ResourceAddress, ResourceAddress, ResourceAddress, ResourceAddress)
pub fn create_everything_allowed_non_fungible_resource( &mut self, owner_role: OwnerRole ) -> ResourceAddress
pub fn create_freezeable_token( &mut self, account: ComponentAddress ) -> ResourceAddress
pub fn create_freezeable_non_fungible( &mut self, account: ComponentAddress ) -> ResourceAddress
pub fn create_recallable_token( &mut self, account: ComponentAddress ) -> ResourceAddress
pub fn create_restricted_burn_token( &mut self, account: ComponentAddress ) -> (ResourceAddress, ResourceAddress)
pub fn create_restricted_transfer_token( &mut self, account: ComponentAddress ) -> (ResourceAddress, ResourceAddress)
pub fn create_non_fungible_resource( &mut self, account: ComponentAddress ) -> ResourceAddress
pub fn create_non_fungible_resource_with_roles( &mut self, resource_roles: NonFungibleResourceRoles, account: ComponentAddress ) -> ResourceAddress
pub fn create_non_fungible_resource_advanced( &mut self, resource_roles: NonFungibleResourceRoles, account: ComponentAddress, n: usize ) -> ResourceAddress
pub fn create_fungible_resource( &mut self, amount: Decimal, divisibility: u8, account: ComponentAddress ) -> ResourceAddress
pub fn create_mintable_burnable_fungible_resource( &mut self, account: ComponentAddress ) -> (ResourceAddress, ResourceAddress)
pub fn create_freely_mintable_fungible_resource( &mut self, owner_role: OwnerRole, amount: Option<Decimal>, divisibility: u8, account: ComponentAddress ) -> ResourceAddress
pub fn create_freely_mintable_and_burnable_fungible_resource( &mut self, owner_role: OwnerRole, amount: Option<Decimal>, divisibility: u8, account: ComponentAddress ) -> ResourceAddress
pub fn create_freely_mintable_and_burnable_non_fungible_resource<T, V>( &mut self, owner_role: OwnerRole, id_type: NonFungibleIdType, initial_supply: Option<T>, account: ComponentAddress ) -> ResourceAddress
pub fn create_one_resource_pool( &mut self, resource_address: ResourceAddress, pool_manager_rule: AccessRule ) -> (ComponentAddress, ResourceAddress)
pub fn new_component<F>(
&mut self,
initial_proofs: BTreeSet<NonFungibleGlobalId>,
handler: F
) -> ComponentAddresswhere
F: FnOnce(ManifestBuilder) -> ManifestBuilder,
pub fn set_current_epoch(&mut self, epoch: Epoch)
pub fn get_current_epoch(&mut self) -> Epoch
pub fn execute_system_transaction_with_preallocation( &mut self, instructions: Vec<InstructionV1>, proofs: BTreeSet<NonFungibleGlobalId>, pre_allocated_addresses: Vec<PreAllocatedAddress> ) -> TransactionReceipt
pub fn execute_validator_transaction( &mut self, instructions: Vec<InstructionV1> ) -> TransactionReceipt
pub fn execute_system_transaction_with_preallocated_addresses( &mut self, instructions: Vec<InstructionV1>, pre_allocated_addresses: Vec<PreAllocatedAddress>, proofs: BTreeSet<NonFungibleGlobalId> ) -> TransactionReceipt
pub fn execute_system_transaction( &mut self, instructions: Vec<InstructionV1>, proofs: BTreeSet<NonFungibleGlobalId> ) -> TransactionReceipt
sourcepub fn advance_to_round_at_timestamp(
&mut self,
round: Round,
proposer_timestamp_ms: i64
) -> TransactionReceipt
pub fn advance_to_round_at_timestamp( &mut self, round: Round, proposer_timestamp_ms: i64 ) -> TransactionReceipt
Executes a “start round number round
at timestamp timestamp_ms
” system transaction, as
if it was proposed by the first validator from the validator set, after round - 1
missed
rounds by that validator.
sourcepub fn advance_to_round(&mut self, round: Round) -> TransactionReceipt
pub fn advance_to_round(&mut self, round: Round) -> TransactionReceipt
Performs an [advance_to_round_at_timestamp()
] with an unchanged timestamp.
sourcepub fn get_current_proposer_timestamp_ms(&mut self) -> i64
pub fn get_current_proposer_timestamp_ms(&mut self) -> i64
Reads out the substate holding the “epoch milli” timestamp reported by the proposer on the most recent round change.
pub fn get_consensus_manager_state(&mut self) -> ConsensusManagerSubstate
pub fn get_current_time(&mut self, precision: TimePrecision) -> Instant
pub fn event_schema( &self, event_type_identifier: &EventTypeIdentifier ) -> (LocalTypeId, VersionedScryptoSchema)
pub fn event_name(&self, event_type_identifier: &EventTypeIdentifier) -> String
pub fn is_event_name_equal<T: ScryptoDescribe>( &self, event_type_identifier: &EventTypeIdentifier ) -> bool
pub fn extract_events_of_type<T: ScryptoEvent>( &self, result: &CommitResult ) -> Vec<T>
pub fn check_db<A: ApplicationChecker + Default>( &self ) -> Result<(SystemDatabaseCheckerResults, A::ApplicationCheckerResults), SystemDatabaseCheckError>
pub fn check_events<A: ApplicationEventChecker>( &self ) -> Result<A::ApplicationEventCheckerResults, SystemEventCheckerError>
pub fn check_database(&self)
source§impl<E: NativeVmExtension, D: TestDatabase> TestRunner<E, HashTreeUpdatingDatabase<D>>
impl<E: NativeVmExtension, D: TestDatabase> TestRunner<E, HashTreeUpdatingDatabase<D>>
pub fn get_state_hash(&self) -> Hash
pub fn assert_state_hash_tree_matches_substate_store(&mut self)
Auto Trait Implementations§
impl<E, D> !RefUnwindSafe for TestRunner<E, D>
impl<E, D> Send for TestRunner<E, D>
impl<E, D> Sync for TestRunner<E, D>
impl<E, D> Unpin for TestRunner<E, D>
impl<E, D> !UnwindSafe for TestRunner<E, D>
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read moresource§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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.