pub struct TestEnvironment(pub(super) EncapsulatedRadixEngine);
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 ClientApi 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 TestRunner 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 TestRunner 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 TestRunner 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 TestRunner 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::*;

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

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

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

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).unwrap()
    /* Kernel modules are reset just after this point. */
});

// Assert
let amount = bucket.amount(&mut env).unwrap();
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(TestEnvironment, Bucket, Bucket),
{
    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.

§Full Examples

use radiswap::test_bindings::*;
use scrypto::*;
use scrypto_test::prelude::*;

#[test]
fn simple_radiswap_test() -> Result<(), RuntimeError> {
    // Arrange
    let mut env = TestEnvironment::new();
    let package_address = Package::compile_and_publish(this_package!(), &mut env)?;

    let bucket1 = ResourceBuilder::new_fungible(OwnerRole::None)
        .divisibility(18)
        .mint_initial_supply(100, &mut env)?;
    let bucket2 = ResourceBuilder::new_fungible(OwnerRole::None)
        .divisibility(18)
        .mint_initial_supply(100, &mut env)?;

    let resource_address1 = bucket1.resource_address(&mut env)?;
    let resource_address2 = bucket2.resource_address(&mut env)?;

    let mut radiswap = Radiswap::new(
        OwnerRole::None,
        resource_address1,
        resource_address2,
        package_address,
        &mut env,
    )?;

    // Act
    let (pool_units, _change) = radiswap.add_liquidity(bucket1, bucket2, &mut env)?;

    // Assert
    assert_eq!(pool_units.amount(&mut env)?, dec!("100"));
    Ok(())
}

#[test]
fn reading_and_asserting_against_radiswap_pool_state() -> Result<(), RuntimeError> {
    // Arrange
    let mut env = TestEnvironment::new();
    let package_address = Package::compile_and_publish(this_package!(), &mut env)?;

    let bucket1 = ResourceBuilder::new_fungible(OwnerRole::None)
        .divisibility(18)
        .mint_initial_supply(100, &mut env)?;
    let bucket2 = ResourceBuilder::new_fungible(OwnerRole::None)
        .divisibility(18)
        .mint_initial_supply(100, &mut env)?;

    let resource_address1 = bucket1.resource_address(&mut env)?;
    let resource_address2 = bucket2.resource_address(&mut env)?;

    let mut radiswap = Radiswap::new(
        OwnerRole::None,
        resource_address1,
        resource_address2,
        package_address,
        &mut env,
    )?;

    // Act
    let _ = radiswap.add_liquidity(bucket1, bucket2, &mut env)?;
    let radiswap_state = env.read_component_state::<RadiswapState, _>(radiswap)?;

    let VersionedTwoResourcePoolState::V1(TwoResourcePoolSubstate {
        vaults: [(_, vault1), (_, vault2)],
        ..
    }) = env.read_component_state(radiswap_state.pool_component)?;

    // Assert
    let amount1 = vault1.amount(&mut env)?;
    let amount2 = vault2.amount(&mut env)?;
    assert_eq!(amount1, dec!("100"));
    assert_eq!(amount2, dec!("100"));

    Ok(())
}

Tuple Fields§

§0: EncapsulatedRadixEngine

Implementations§

source§

impl TestEnvironment

source

pub fn new() -> Self

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 ClientBlueprintApi::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 ClientObjectApi::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 ClientObjectApi::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 ClientObjectApi::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 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 read_component_state<S, N>( &mut self, node_id: N ) -> Result<S, RuntimeError>
where S: ScryptoDecode, N: Into<NodeId>,

Reads the state of a component and SBOR decodes it to the specified generic.

This method reads the state of a component and returns it as an instance of [S]. Owned nodes encountered in the component state are added as transient references to the test call frame and references are added as references to the test call frame. This means that all nodes in the component state become visible to the tests.

§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>.
§Returns
§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)

source

pub(crate) fn as_method_actor<N, F, O>( &mut self, node_id: N, module_id: ModuleId, method_ident: &str, callback: F ) -> Result<O, RuntimeError>
where N: Into<NodeId> + Copy, F: FnOnce(&mut Self) -> O, O: ScryptoEncode,

Allows us to perform some action as another actor.

This function pushes a new call-frame onto the stack with the actor information we desire, performs the call-back, and then pops the call-frame off.

source

pub(crate) fn as_actor<F, O>( &mut self, actor: Actor, callback: F ) -> Result<O, RuntimeError>
where F: FnOnce(&mut Self) -> O, O: ScryptoEncode,

Allows us to perform some action as another actor.

This function pushes a new call-frame onto the stack with the actor information we desire, performs the call-back, and then pops the call-frame off.

Trait Implementations§

source§

impl ClientActorApi<RuntimeError> for TestEnvironment

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 ClientActorIndexApi<RuntimeError> for TestEnvironment

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 ClientActorKeyValueEntryApi<RuntimeError> for TestEnvironment

source§

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

If the key value entry doesn’t exist, it uses the default “Option::None”
source§

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

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,

source§

impl ClientActorSortedIndexApi<RuntimeError> for TestEnvironment

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 ClientBlueprintApi<RuntimeError> for TestEnvironment

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>

source§

impl ClientCostingApi<RuntimeError> for TestEnvironment

source§

impl ClientCryptoUtilsApi<RuntimeError> for TestEnvironment

source§

impl ClientExecutionTraceApi<RuntimeError> for TestEnvironment

source§

impl ClientFieldApi<RuntimeError> for TestEnvironment

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl ClientKeyValueEntryApi<RuntimeError> for TestEnvironment

source§

impl ClientKeyValueStoreApi<RuntimeError> for TestEnvironment

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>

Lock 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>

source§

impl ClientObjectApi<RuntimeError> for TestEnvironment

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>

Pre-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>

source§

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

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>

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>

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 ClientTransactionRuntimeApi<RuntimeError> for TestEnvironment

source§

impl ClientApi<RuntimeError> for TestEnvironment

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
§

impl<U> As for U

§

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
§

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

§

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

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

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

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, 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

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

§

fn vzip(self) -> V