Struct TestEnvironment

Source
pub struct TestEnvironment<D>(/* private fields */)
where
    D: SubstateDatabase + CommittableSubstateDatabase + 'static;
Expand description

The environment that all tests of this testing framework are run against.

This struct may be thought of as the main struct in this testing framework which encapsulates a a self-contained instance of the Radix Engine ([EncapsulatedRadixEngine]). The functionality of the Radix Engine is exposed through the SystemApi which makes this testing environment no less capable than Scrypto code.

§Introduction

This testing framework is designed to allow you to write Scrypto-like code and use that to test your packages and blueprints and follows a different approach from the LedgerSimulator class. The test-runner is an in-memory ledger simulator which you can interact with as a user that submits transactions to the network. The approach followed by this testing framework is different, instead of submitting transactions, you’re making invocations to the Radix Engine, getting results back, and then writing assertions against what you got back.

Both the LedgerSimulator and this testing framework will prove to be useful throughout your blueprint development journey. As an example, this testing framework allows you to disable some of kernel modules that may get in your way when writing tests so it may be an optimal framework to use to ensure that the “math checks out” in your blueprint code without needing to think about costing or auth. However, when you’re reaching the final stages of developing a blueprint you may want tests that check that interactions with your blueprint will succeed in a simulated setting that is close to the real setting, which is when the LedgerSimulator comes in. Overall, we may put these two frameworks into two categories: This framework (named scrypto-test) is a framework for unit testing your blueprints and is a good framework to use to check that your DeFi logic is correct. The LedgerSimulator is an integration testing or an end-to-end testing framework to test that your blueprints work in a simulated ledger with all of the costing limits, substate limits, and other limits applied.

§Features

This framework has many new features that developers may find useful when testing their packages some of those features are:

  • The ability to create mock Buckets and Proofs through two main ways: by creating them out of thin air, and by disabling the auth module and minting them. This functionality can be found in the BucketFactory and ProofFactory structs and the CreationStrategy.
  • The ability to query the contents of Buckets and Proofs for the purpose of writing assertions against them. Not only that, but this testing framework allows you to call any method you wish on these nodes. As an example, in a test, you can get a Bucket and then create a proof out of it in manner similar to Scrypto.
  • The ability to enable and disable kernel modules at runtime. The Radix Engine kernel is quite modular with concepts such as auth, costing, and limits being implemented as kernel modules. Disabling or enabling kernel modules at runtime can prove to be quite useful when writing DeFi tests. As an example, you may want to not think about costing at all when writing tests and thus you may opt to disable the costing module entirely and continue your test without it. This can be done through TestEnvironment::disable_costing_module.
  • This testing framework uses test bindings to provide a higher-level API for calling methods and functions on a blueprint without the need to do raw TestEnvironment::call_method_typed or TestEnvironment::call_function_typed. The test bindings are generated by the blueprint macro and are feature gated behind a test feature.

§Getting Started

The following example shows a very simple test that gets XRD from the faucet and then asserts that the amount is equal to what we expect.

use scrypto_test::prelude::*;

fn my_test() -> Result<(), RuntimeError> {
    // Arrange
    let mut env = TestEnvironment::new();

    // Act
    let bucket = env.call_method_typed::<_, _, Bucket>(
        FAUCET,
        "free",
        &(),
    )?;

    // Assert
    let amount = bucket.amount(&mut env)?;
    assert_eq!(amount, dec!("10000"));

    Ok(())
}

A few things to note about the code you see above:

  • There is no transactions, worktop, receipt, manifests or anything of that sort! This part is “not just hidden” from this testing framework but is actually non existent! The approach that framework of wrapping a self-contained Radix Engine means that there is no need for manifests or other transaction concepts.
  • Methods such as Bucket::amount can be called to get the amount of resources in a bucket and then assert against that.

§Manipulating Kernel Modules

At runtime, the kernel modules can be enabled or disabled. For each kernel module there are four methods on the TestEnvironment:

The simple enable and disable methods are quite straightforward: call them to enable or disable a kernel module. The with_* methods are a little bit more intricate, they allow you to perform some actions with a specific kernel either enabled or disabled and then resets the state of the kernel modules afterwards. As an example:

use scrypto_test::prelude::*;

// Arrange
let mut env = TestEnvironment::new();

// Act
let bucket = env.with_auth_module_disabled(|env| {
    /* Auth Module is disabled just before this point */
    ResourceManager(XRD).mint_fungible(100.into(), env)
    /* Kernel modules are reset just after this point. */
})?;

// Assert
let amount = bucket.amount(&mut env)?;
assert_eq!(amount, dec!("100"));

§Common Arranges or Teardowns

There are cases where you may have many tests that all share a large portion of your arrange or teardown logic. While this framework does not specifically provide solutions for this, there are many useful Rust patterns that may be employed here to allow you to do this: the simplest and the most elegant is probably by using callback functions.

Imagine this, you’re building a Dex and many of the tests you write require you to have two resources with a very large supply so you can write your tests with. You can achieve this by doing something like:

use scrypto_test::prelude::*;

pub fn two_resource_environment<F>(func: F)
where
    F: FnOnce(DefaultTestEnvironment, FungibleBucket, FungibleBucket),
{
    let mut env = TestEnvironment::new();
    let bucket1 = ResourceBuilder::new_fungible(OwnerRole::None)
        .mint_initial_supply(dec!("100000000000"), &mut env)
        .unwrap();
    let bucket2 = ResourceBuilder::new_fungible(OwnerRole::None)
        .mint_initial_supply(dec!("100000000000"), &mut env)
        .unwrap();
    func(env, bucket1, bucket2)

    /* Potential teardown happens here */
}

#[test]
fn contribution_provides_expected_amount_of_pool_units() {
    two_resource_environment(|mut env, bucket1, bucket2| {
        /* Your test goes here */
    })
}

You may have a function like two_resource_environment seen above which sets up the environment and then some callback and potentially then executes some teardown code. Another way to do this would be through simple factory and destructor methods.

Implementations§

Source§

impl TestEnvironment<InMemorySubstateDatabase>

Source

pub fn new() -> Self

Source§

impl<D> TestEnvironment<D>

Source

pub fn call_function_typed<I, O>( &mut self, package_address: PackageAddress, blueprint_name: &str, function_name: &str, args: &I, ) -> Result<O, RuntimeError>

Invokes a function on the provided blueprint and package with the given arguments.

This method is a typed version of the SystemBlueprintApi::call_function which Scrypto encodes the arguments and Scrypto decodes the returns on behalf of the caller. This method assumes that the caller is correct about the argument and return types and panics if the encoding or decoding fails.

§Arguments
  • package_address: PackageAddress - The address of the package that contains the blueprint.
  • blueprint_name: &str - The name of the blueprint.
  • function_name: &str - The nae of the function.
  • args: &I - The arguments to invoke the method with. This is a generic arguments that is fulfilled by any type that implements ScryptoEncode.
§Returns
§Panics

This method panics in the following two cases:

  • Through an unwrap when calling scrypto_encode on the method arguments. Please consult the SBOR documentation on more information on why SBOR encoding may fail.
  • Through an unwrap when calling scrypto_decode on the returns. This panics if the type could be decoded as the desired output type.
Source

pub fn call_method_typed<N, I, O>( &mut self, node_id: N, method_name: &str, args: &I, ) -> Result<O, RuntimeError>

Invokes a method on the main module of a node with the provided typed arguments.

This method is a typed version of the SystemObjectApi::call_method which Scrypto encodes the arguments and Scrypto decodes the returns on behalf of the caller. This method assumes that the caller is correct about the argument and return types and panics if the encoding or decoding fails.

§Arguments
  • node_id: T - The node to invoke the method on. This is a generic argument that’s fulfilled by any type that implements Into<NodeId>, thus, any address type can be used.
  • method_name: &str - The name of the method to invoke.
  • args: &I - The arguments to invoke the method with. This is a generic arguments that is fulfilled by any type that implements ScryptoEncode.
§Returns
§Panics

This method panics in the following two cases:

  • Through an unwrap when calling scrypto_encode on the method arguments. Please consult the SBOR documentation on more information on why SBOR encoding may fail.
  • Through an unwrap when calling scrypto_decode on the returns. This panics if the type could be decoded as the desired output type.
Source

pub fn call_direct_access_method_typed<N, I, O>( &mut self, node_id: N, method_name: &str, args: &I, ) -> Result<O, RuntimeError>

Invokes a method on the main module of a node with the provided typed arguments.

This method is a typed version of the SystemObjectApi::call_method which Scrypto encodes the arguments and Scrypto decodes the returns on behalf of the caller. This method assumes that the caller is correct about the argument and return types and panics if the encoding or decoding fails.

§Arguments
  • node_id: T - The node to invoke the method on. This is a generic argument that’s fulfilled by any type that implements Into<NodeId>, thus, any address type can be used.
  • method_name: &str - The name of the method to invoke.
  • args: &I - The arguments to invoke the method with. This is a generic arguments that is fulfilled by any type that implements ScryptoEncode.
§Returns
§Panics

This method panics in the following two cases:

  • Through an unwrap when calling scrypto_encode on the method arguments. Please consult the SBOR documentation on more information on why SBOR encoding may fail.
  • Through an unwrap when calling scrypto_decode on the returns. This panics if the type could be decoded as the desired output type.
Source

pub fn call_module_method_typed<N, I, O>( &mut self, node_id: N, module: AttachedModuleId, method_name: &str, args: &I, ) -> Result<O, RuntimeError>

Invokes a method on a module of a node with the provided typed arguments.

This method is a typed version of the SystemObjectApi::call_method which Scrypto encodes the arguments and Scrypto decodes the returns on behalf of the caller. This method assumes that the caller is correct about the argument and return types and panics if the encoding or decoding fails.

§Arguments
  • node_id: T - The node to invoke the method on. This is a generic argument that’s fulfilled by any type that implements Into<NodeId>, thus, any address type can be used.
  • module: AttachedModuleId - The module id.
  • method_name: &str - The name of the method to invoke.
  • args: &I - The arguments to invoke the method with. This is a generic arguments that is fulfilled by any type that implements ScryptoEncode.
§Returns
§Panics

This method panics in the following two cases:

  • Through an unwrap when calling scrypto_encode on the method arguments. Please consult the SBOR documentation on more information on why SBOR encoding may fail.
  • Through an unwrap when calling scrypto_decode on the returns. This panics if the type could be decoded as the desired output type.
Source

pub fn with_kernel<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&TestKernel<'_, D>) -> O,

Source

pub fn with_kernel_mut<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut TestKernel<'_, D>) -> O,

Source

pub fn enable_kernel_trace_module(&mut self)

Enables the kernel trace kernel module of the Radix Engine.

Source

pub fn enable_limits_module(&mut self)

Enables the limits kernel module of the Radix Engine.

Source

pub fn enable_costing_module(&mut self)

Enables the costing kernel module of the Radix Engine.

Source

pub fn enable_auth_module(&mut self)

Enables the auth kernel module of the Radix Engine.

Source

pub fn enable_transaction_runtime_module(&mut self)

Enables the transaction env kernel module of the Radix Engine.

Source

pub fn enable_execution_trace_module(&mut self)

Enables the execution trace kernel module of the Radix Engine.

Source

pub fn disable_kernel_trace_module(&mut self)

Disables the kernel trace kernel module of the Radix Engine.

Source

pub fn disable_limits_module(&mut self)

Disables the limits kernel module of the Radix Engine.

Source

pub fn disable_costing_module(&mut self)

Disables the costing kernel module of the Radix Engine.

Source

pub fn disable_auth_module(&mut self)

Disables the auth kernel module of the Radix Engine.

Source

pub fn disable_transaction_runtime_module(&mut self)

Disables the transaction env kernel module of the Radix Engine.

Source

pub fn disable_execution_trace_module(&mut self)

Disables the execution trace kernel module of the Radix Engine.

Source

pub fn with_kernel_trace_module_enabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the kernel trace kernel module enabled and then resets the state of the kernel modules.

Source

pub fn with_limits_module_enabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the limits kernel module enabled and then resets the state of the kernel modules.

Source

pub fn with_costing_module_enabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the costing kernel module enabled and then resets the state of the kernel modules.

Source

pub fn with_auth_module_enabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the auth kernel module enabled and then resets the state of the kernel modules.

Source

pub fn with_transaction_runtime_module_enabled<F, O>( &mut self, callback: F, ) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the transaction env kernel module enabled and then resets the state of the kernel modules.

Source

pub fn with_execution_trace_module_enabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the execution trace kernel module enabled and then resets the state of the kernel modules.

Source

pub fn with_kernel_trace_module_disabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the kernel trace kernel module disabled and then resets the state of the kernel modules.

Source

pub fn with_limits_module_disabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the limits kernel module disabled and then resets the state of the kernel modules.

Source

pub fn with_costing_module_disabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the costing kernel module disabled and then resets the state of the kernel modules.

Source

pub fn with_auth_module_disabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the auth kernel module disabled and then resets the state of the kernel modules.

Source

pub fn with_transaction_runtime_module_disabled<F, O>( &mut self, callback: F, ) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the transaction env kernel module disabled and then resets the state of the kernel modules.

Source

pub fn with_execution_trace_module_disabled<F, O>(&mut self, callback: F) -> O
where F: FnOnce(&mut Self) -> O,

Calls the passed callback with the execution trace kernel module disabled and then resets the state of the kernel modules.

Source

pub fn enabled_modules(&self) -> EnabledModules

Returns the bit flags representing the currently enabled kernel modules.

Source

pub fn set_enabled_modules(&mut self, enabled_modules: EnabledModules)

Sets the bit flags representing the enabled kernel modules.

Source

pub fn enable_module(&mut self, module: EnabledModules)

Enables specific kernel module(s).

Source

pub fn disable_module(&mut self, module: EnabledModules)

Disables specific kernel module(s).

Source

pub fn with_component_state<S, N, F, O>( &mut self, node_id: N, callback: F, ) -> Result<O, RuntimeError>
where S: ScryptoDecode, N: Into<NodeId>, F: FnMut(&mut S, &mut Self) -> O,

Reads the state of a component and allows for a callback to be executed over the decoded state.

This method performs the steps needed to read the state of a component and then perform the various steps needed before the state can be read or used such as the locking, reading, and decoding of the substate and the various steps that need to be performed after the state is read such as unlocking the substate.

Users of this method are expected to pass in a callback function to operate over the state as this is the main way that this method ensures that references do not escape out of this method after the substate is closed.

§Arguments
  • node_id: [N] - The address of the component to read the state of. This is a generic type parameter that’s satisfied by any type that implements Into<NodeId>.
  • callback: [F] - A callback function to call after the component state has been read and decoded into the type specified by the generic parameter [S]. Anything returned from this callback is returned from this method unless an error happens after the callback is executed.
§Returns
  • Result<O, RuntimeError> - The output of the callback function passed in or a runtime error if one of the steps failed.
§Panics

This method panics if the component state can not be decoded as the generic type parameter [S].

Source

pub fn get_current_epoch(&mut self) -> Epoch

Gets the current epoch from the Consensus Manager.

Source

pub fn set_current_epoch(&mut self, epoch: Epoch)

Sets the current epoch.

Source

pub fn get_current_time(&mut self) -> Instant

Gets the current time stamp from the Consensus Manager.

Source

pub fn set_current_time(&mut self, instant: Instant)

Trait Implementations§

Source§

impl Default for TestEnvironment<InMemorySubstateDatabase>

Source§

fn default() -> Self

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

impl<D> SystemActorApi<RuntimeError> for TestEnvironment<D>

Source§

fn actor_get_blueprint_id(&mut self) -> Result<BlueprintId, RuntimeError>

Retrieve the current blueprint id
Source§

fn actor_open_field( &mut self, object_handle: ActorStateHandle, field: FieldIndex, flags: LockFlags, ) -> Result<FieldHandle, RuntimeError>

Open a field in a given object for reading/writing
Source§

fn actor_is_feature_enabled( &mut self, object_handle: ActorStateHandle, feature: &str, ) -> Result<bool, RuntimeError>

Check if a feature is enabled for a given object
Source§

fn actor_get_node_id( &mut self, ref_handle: ActorRefHandle, ) -> Result<NodeId, RuntimeError>

Retrieve the current method actor’s node id
Source§

fn actor_emit_event( &mut self, event_name: String, event_data: Vec<u8>, event_flags: EventFlags, ) -> Result<(), RuntimeError>

Emits an event of the current actor
Source§

impl<D> SystemActorIndexApi<RuntimeError> for TestEnvironment<D>

Source§

fn actor_index_insert( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: Vec<u8>, buffer: Vec<u8>, ) -> Result<(), RuntimeError>

Inserts an entry into an index
Source§

fn actor_index_remove( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: Vec<u8>, ) -> Result<Option<Vec<u8>>, RuntimeError>

Removes an entry from an index
Source§

fn actor_index_scan_keys( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, limit: u32, ) -> Result<Vec<Vec<u8>>, RuntimeError>

Scans arbitrary elements of count from an index
Source§

fn actor_index_drain( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, limit: u32, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>, RuntimeError>

Removes and returns arbitrary elements of count from an index
Source§

fn actor_index_insert_typed<K, V>( &mut self, object_handle: u32, collection_index: u8, key: K, value: V, ) -> Result<(), E>

Inserts an entry into an index
Source§

fn actor_index_remove_typed<V>( &mut self, object_handle: u32, collection_index: u8, key: Vec<u8>, ) -> Result<Option<V>, E>
where V: ScryptoDecode,

Removes an entry from an index
Source§

fn actor_index_scan_keys_typed<K>( &mut self, object_handle: u32, collection_index: u8, limit: u32, ) -> Result<Vec<K>, E>
where K: ScryptoDecode,

Scans arbitrary elements of count from an index
Source§

fn actor_index_drain_typed<K, V>( &mut self, object_handle: u32, collection_index: u8, limit: u32, ) -> Result<Vec<(K, V)>, E>

Removes and returns arbitrary elements of count from an index
Source§

impl<D> SystemActorKeyValueEntryApi<RuntimeError> for TestEnvironment<D>

Source§

fn actor_open_key_value_entry( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: &Vec<u8>, flags: LockFlags, ) -> Result<KeyValueEntryHandle, RuntimeError>

Returns a handle for a specified key value entry in a collection. If an invalid collection index or key is passed an error is returned.
Source§

fn actor_remove_key_value_entry( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: &Vec<u8>, ) -> Result<Vec<u8>, RuntimeError>

Removes an entry from a collection. If an invalid collection index or key is passed an error is returned, otherwise the encoding of a value of the entry is returned.
Source§

fn actor_remove_key_value_entry_typed<V>( &mut self, object_handle: u32, collection_index: u8, key: &Vec<u8>, ) -> Result<Option<V>, E>
where V: ScryptoDecode,

Removes an entry from a collection. If an invalid collection index or key is passed an error is returned, otherwise the value of the entry is returned.
Source§

impl<D> SystemActorSortedIndexApi<RuntimeError> for TestEnvironment<D>

Source§

fn actor_sorted_index_insert( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, sorted_key: SortedKey, buffer: Vec<u8>, ) -> Result<(), RuntimeError>

Inserts an entry into a sorted index
Source§

fn actor_sorted_index_remove( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, sorted_key: &SortedKey, ) -> Result<Option<Vec<u8>>, RuntimeError>

Removes an entry from a sorted index
Source§

fn actor_sorted_index_scan( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, count: u32, ) -> Result<Vec<(SortedKey, Vec<u8>)>, RuntimeError>

Scans the first elements of count from a sorted index
Source§

fn actor_sorted_index_insert_typed<V>( &mut self, object_handle: u32, collection_index: u8, sorted_key: ([u8; 2], Vec<u8>), value: V, ) -> Result<(), E>
where V: ScryptoEncode,

Inserts an entry into a sorted index
Source§

fn actor_sorted_index_remove_typed<V>( &mut self, object_handle: u32, collection_index: u8, sorted_key: &([u8; 2], Vec<u8>), ) -> Result<Option<V>, E>
where V: ScryptoDecode,

Removes an entry from a sorted index
Source§

fn actor_sorted_index_scan_typed<K, V>( &mut self, object_handle: u32, collection_index: u8, count: u32, ) -> Result<Vec<(K, V)>, E>

Scans the first elements of count from a sorted index
Source§

impl<D> SystemBlueprintApi<RuntimeError> for TestEnvironment<D>

Source§

fn call_function( &mut self, package_address: PackageAddress, blueprint_name: &str, function_name: &str, args: Vec<u8>, ) -> Result<Vec<u8>, RuntimeError>

Calls a function on a blueprint
Source§

fn resolve_blueprint_type( &mut self, blueprint_type_id: &BlueprintTypeIdentifier, ) -> Result<(Rc<VersionedScryptoSchema>, ScopedTypeId), RuntimeError>

Retrieves the schema of type under a blueprint
Source§

impl<D> SystemCostingApi<RuntimeError> for TestEnvironment<D>

Source§

fn start_lock_fee( &mut self, amount: Decimal, contingent: bool, ) -> Result<bool, RuntimeError>

Check if costing is enabled.
Source§

fn lock_fee(&mut self, locked_fee: LiquidFungibleResource, contingent: bool)

Add cost units to the reserve. This should never fail.
Source§

fn consume_cost_units( &mut self, costing_entry: ClientCostingEntry<'_>, ) -> Result<(), RuntimeError>

Consume an amount of cost units.
Source§

fn execution_cost_unit_limit(&mut self) -> Result<u32, RuntimeError>

Retrieve the cost unit limit for the transaction
Source§

fn execution_cost_unit_price(&mut self) -> Result<Decimal, RuntimeError>

Retrieve the cost unit price in XRD
Source§

fn finalization_cost_unit_limit(&mut self) -> Result<u32, RuntimeError>

Retrieve the finalization cost unit limit
Source§

fn finalization_cost_unit_price(&mut self) -> Result<Decimal, RuntimeError>

Retrieve the finalization cost unit price in XRD
Source§

fn usd_price(&mut self) -> Result<Decimal, RuntimeError>

Retrieve the usd price of XRD
Source§

fn max_per_function_royalty_in_xrd(&mut self) -> Result<Decimal, RuntimeError>

Retrieve the maximum allowable royalty per function
Source§

fn tip_percentage_truncated(&mut self) -> Result<u32, RuntimeError>

Retrieve the tip percentage of the transaction
Source§

fn fee_balance(&mut self) -> Result<Decimal, RuntimeError>

Retrieve the current fee balance in XRD
Source§

impl<D> SystemExecutionTraceApi<RuntimeError> for TestEnvironment<D>

Source§

fn update_instruction_index( &mut self, new_index: usize, ) -> Result<(), RuntimeError>

Source§

impl<D> SystemFieldApi<RuntimeError> for TestEnvironment<D>

Source§

fn field_read(&mut self, handle: FieldHandle) -> Result<Vec<u8>, RuntimeError>

Retrieve the value of a field
Source§

fn field_write( &mut self, handle: FieldHandle, buffer: Vec<u8>, ) -> Result<(), RuntimeError>

Write a value to a field
Source§

fn field_lock(&mut self, handle: FieldHandle) -> Result<(), RuntimeError>

Lock a field such that it becomes immutable
Source§

fn field_close(&mut self, handle: FieldHandle) -> Result<(), RuntimeError>

Close a field handle so that it is no longer usable
Source§

fn field_read_typed<S>(&mut self, handle: u32) -> Result<S, E>
where S: ScryptoDecode,

Retrieve the value of a field
Source§

fn field_write_typed<S>(&mut self, handle: u32, substate: &S) -> Result<(), E>
where S: ScryptoEncode,

Write a value to a field
Source§

impl<D> SystemKeyValueEntryApi<RuntimeError> for TestEnvironment<D>

Source§

fn key_value_entry_get( &mut self, handle: KeyValueEntryHandle, ) -> Result<Vec<u8>, RuntimeError>

Reads the value of a key value entry
Source§

fn key_value_entry_set( &mut self, handle: KeyValueEntryHandle, buffer: Vec<u8>, ) -> Result<(), RuntimeError>

Set the value of a key value entry
Source§

fn key_value_entry_remove( &mut self, handle: KeyValueEntryHandle, ) -> Result<Vec<u8>, RuntimeError>

Remove the value of a key value entry
Source§

fn key_value_entry_lock( &mut self, handle: KeyValueEntryHandle, ) -> Result<(), RuntimeError>

Lock the value of a key value entry making the value immutable
Source§

fn key_value_entry_close( &mut self, handle: KeyValueEntryHandle, ) -> Result<(), RuntimeError>

Close the handle into the key value entry rendering it unusable after close
Source§

fn key_value_entry_get_typed<S>(&mut self, handle: u32) -> Result<Option<S>, E>
where S: ScryptoDecode,

Reads the value of a key value entry and decodes it into a specific type
Source§

fn key_value_entry_set_typed<S>( &mut self, handle: u32, value: S, ) -> Result<(), E>
where S: ScryptoEncode,

Set the value of a key value entry
Source§

impl<D> SystemKeyValueStoreApi<RuntimeError> for TestEnvironment<D>

Source§

fn key_value_store_new( &mut self, data_schema: KeyValueStoreDataSchema, ) -> Result<NodeId, RuntimeError>

Creates a new key value store with a given schema
Source§

fn key_value_store_open_entry( &mut self, node_id: &NodeId, key: &Vec<u8>, flags: LockFlags, ) -> Result<KeyValueEntryHandle, RuntimeError>

Open a key value store entry for reading/writing
Source§

fn key_value_store_remove_entry( &mut self, node_id: &NodeId, key: &Vec<u8>, ) -> Result<Vec<u8>, RuntimeError>

Removes an entry from a key value store
Source§

impl<D> SystemObjectApi<RuntimeError> for TestEnvironment<D>

Source§

fn new_object( &mut self, blueprint_ident: &str, features: Vec<&str>, generic_args: GenericArgs, fields: IndexMap<FieldIndex, FieldValue>, kv_entries: IndexMap<u8, IndexMap<Vec<u8>, KVEntry>>, ) -> Result<NodeId, RuntimeError>

Creates a new object of a given blueprint type
Source§

fn drop_object( &mut self, node_id: &NodeId, ) -> Result<Vec<Vec<u8>>, RuntimeError>

Drops an owned object, returns the fields of the object
Source§

fn get_blueprint_id( &mut self, node_id: &NodeId, ) -> Result<BlueprintId, RuntimeError>

Get the blueprint id of a visible object
Source§

fn get_outer_object( &mut self, node_id: &NodeId, ) -> Result<GlobalAddress, RuntimeError>

Get the outer object of a visible object
Source§

fn allocate_global_address( &mut self, blueprint_id: BlueprintId, ) -> Result<(GlobalAddressReservation, GlobalAddress), RuntimeError>

Allocates a global address, for a future globalization.
Source§

fn allocate_virtual_global_address( &mut self, blueprint_id: BlueprintId, global_address: GlobalAddress, ) -> Result<GlobalAddressReservation, RuntimeError>

Allocates a specific virtual global address
Source§

fn get_reservation_address( &mut self, node_id: &NodeId, ) -> Result<GlobalAddress, RuntimeError>

Retrieve the global address of a given address reservation
Source§

fn globalize( &mut self, node_id: NodeId, modules: IndexMap<AttachedModuleId, NodeId>, address_reservation: Option<GlobalAddressReservation>, ) -> Result<GlobalAddress, RuntimeError>

Moves an object currently in the heap into the global space making it accessible to all with the provided global address.
Source§

fn globalize_with_address_and_create_inner_object_and_emit_event( &mut self, node_id: NodeId, modules: IndexMap<AttachedModuleId, NodeId>, address_reservation: GlobalAddressReservation, inner_object_blueprint: &str, inner_object_fields: IndexMap<u8, FieldValue>, event_name: &str, event_data: Vec<u8>, ) -> Result<(GlobalAddress, NodeId), RuntimeError>

Globalizes with a new inner object and emits an event
Source§

fn call_method( &mut self, receiver: &NodeId, method_name: &str, args: Vec<u8>, ) -> Result<Vec<u8>, RuntimeError>

Calls a method on an object
Source§

fn call_direct_access_method( &mut self, receiver: &NodeId, method_name: &str, args: Vec<u8>, ) -> Result<Vec<u8>, RuntimeError>

Calls a direct access method on an object
Source§

fn call_module_method( &mut self, receiver: &NodeId, module_id: AttachedModuleId, method_name: &str, args: Vec<u8>, ) -> Result<Vec<u8>, RuntimeError>

Calls a method on an object module
Source§

fn new_simple_object( &mut self, blueprint_ident: &str, fields: IndexMap<u8, FieldValue>, ) -> Result<NodeId, E>

Creates a new simple blueprint object of a given blueprint type
Source§

impl<D> SystemTransactionRuntimeApi<RuntimeError> for TestEnvironment<D>

Source§

fn bech32_encode_address( &mut self, address: GlobalAddress, ) -> Result<String, RuntimeError>

Encode an address into Bech32. The HRP part is dependent on the network which is running.
Source§

fn get_transaction_hash(&mut self) -> Result<Hash, RuntimeError>

Retrieve the hash of the current transaction which is running.
Source§

fn generate_ruid(&mut self) -> Result<[u8; 32], RuntimeError>

Generate a unique id
Source§

fn emit_log( &mut self, level: Level, message: String, ) -> Result<(), RuntimeError>

Emit a log message which will be available in the transaction receipt
Source§

fn panic(&mut self, message: String) -> Result<(), RuntimeError>

End the transaction immediately with a given message to be included in the transaction receipt
Source§

impl<D> SystemApi<RuntimeError> for TestEnvironment<D>

Auto Trait Implementations§

§

impl<D> Freeze for TestEnvironment<D>

§

impl<D> !RefUnwindSafe for TestEnvironment<D>

§

impl<D> !Send for TestEnvironment<D>

§

impl<D> !Sync for TestEnvironment<D>

§

impl<D> Unpin for TestEnvironment<D>

§

impl<D> !UnwindSafe for TestEnvironment<D>

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts 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 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, U> ContextualTryInto<U> for T
where U: ContextualTryFrom<T>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromBits<T> for T

Source§

fn from_bits(other: T) -> T

Convert other to Self, preserving bitwise representation
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<X, Y> LabelledResolve<Y> for X
where Y: LabelledResolveFrom<X>,

Source§

fn labelled_resolve( self, resolver: &impl LabelResolver<<Y as LabelledResolvable>::ResolverOutput>, ) -> Y

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<X, Y> Resolve<Y> for X
where Y: ResolveFrom<X>,

Source§

fn resolve(self) -> Y

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.