Struct scrypto_test::environment::env::TestEnvironment
source · 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
Bucket
s andProof
s 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 theBucketFactory
andProofFactory
structs and theCreationStrategy
. - The ability to query the contents of
Bucket
s andProof
s 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 aBucket
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
orTestEnvironment::call_function_typed
. The test bindings are generated by the blueprint macro and are feature gated behind atest
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
:
- A method to enable the kernel module (e.g.,
TestEnvironment::enable_costing_module
). - A method to disable the kernel module (e.g.,
TestEnvironment::disable_costing_module
). - A method to perform some action in a callback with the module enabled (e.g.,
TestEnvironment::with_costing_module_enabled
). - A method to perform some action in a callback with the module disabled (e.g.,
TestEnvironment::with_costing_module_disabled
).
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
impl TestEnvironment
pub fn new() -> Self
sourcepub fn call_function_typed<I, O>(
&mut self,
package_address: PackageAddress,
blueprint_name: &str,
function_name: &str,
args: &I
) -> Result<O, RuntimeError>where
I: ScryptoEncode,
O: ScryptoDecode,
pub fn call_function_typed<I, O>(
&mut self,
package_address: PackageAddress,
blueprint_name: &str,
function_name: &str,
args: &I
) -> Result<O, RuntimeError>where
I: ScryptoEncode,
O: ScryptoDecode,
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 implementsScryptoEncode
.
§Returns
Result<O, RuntimeError>
- The returns from the method invocation. If the invocation was successful aResult::Ok
is returned, otherwise aResult::Err
is returned. TheResult::Ok
variant is a generic that’s fulfilled by any type that implementsScryptoDecode
.
§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.
sourcepub fn call_method_typed<N, I, O>(
&mut self,
node_id: N,
method_name: &str,
args: &I
) -> Result<O, RuntimeError>
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 implementsInto<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 implementsScryptoEncode
.
§Returns
Result<O, RuntimeError>
- The returns from the method invocation. If the invocation was successful aResult::Ok
is returned, otherwise aResult::Err
is returned. TheResult::Ok
variant is a generic that’s fulfilled by any type that implementsScryptoDecode
.
§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.
sourcepub fn call_direct_access_method_typed<N, I, O>(
&mut self,
node_id: N,
method_name: &str,
args: &I
) -> Result<O, RuntimeError>
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 implementsInto<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 implementsScryptoEncode
.
§Returns
Result<O, RuntimeError>
- The returns from the method invocation. If the invocation was successful aResult::Ok
is returned, otherwise aResult::Err
is returned. TheResult::Ok
variant is a generic that’s fulfilled by any type that implementsScryptoDecode
.
§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.
sourcepub fn call_module_method_typed<N, I, O>(
&mut self,
node_id: N,
module: AttachedModuleId,
method_name: &str,
args: &I
) -> Result<O, RuntimeError>
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 implementsInto<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 implementsScryptoEncode
.
§Returns
Result<O, RuntimeError>
- The returns from the method invocation. If the invocation was successful aResult::Ok
is returned, otherwise aResult::Err
is returned. TheResult::Ok
variant is a generic that’s fulfilled by any type that implementsScryptoDecode
.
§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.
sourcepub fn enable_kernel_trace_module(&mut self)
pub fn enable_kernel_trace_module(&mut self)
Enables the kernel trace kernel module of the Radix Engine.
sourcepub fn enable_limits_module(&mut self)
pub fn enable_limits_module(&mut self)
Enables the limits kernel module of the Radix Engine.
sourcepub fn enable_costing_module(&mut self)
pub fn enable_costing_module(&mut self)
Enables the costing kernel module of the Radix Engine.
sourcepub fn enable_auth_module(&mut self)
pub fn enable_auth_module(&mut self)
Enables the auth kernel module of the Radix Engine.
sourcepub fn enable_transaction_runtime_module(&mut self)
pub fn enable_transaction_runtime_module(&mut self)
Enables the transaction env kernel module of the Radix Engine.
sourcepub fn enable_execution_trace_module(&mut self)
pub fn enable_execution_trace_module(&mut self)
Enables the execution trace kernel module of the Radix Engine.
sourcepub fn disable_kernel_trace_module(&mut self)
pub fn disable_kernel_trace_module(&mut self)
Disables the kernel trace kernel module of the Radix Engine.
sourcepub fn disable_limits_module(&mut self)
pub fn disable_limits_module(&mut self)
Disables the limits kernel module of the Radix Engine.
sourcepub fn disable_costing_module(&mut self)
pub fn disable_costing_module(&mut self)
Disables the costing kernel module of the Radix Engine.
sourcepub fn disable_auth_module(&mut self)
pub fn disable_auth_module(&mut self)
Disables the auth kernel module of the Radix Engine.
sourcepub fn disable_transaction_runtime_module(&mut self)
pub fn disable_transaction_runtime_module(&mut self)
Disables the transaction env kernel module of the Radix Engine.
sourcepub fn disable_execution_trace_module(&mut self)
pub fn disable_execution_trace_module(&mut self)
Disables the execution trace kernel module of the Radix Engine.
sourcepub fn with_kernel_trace_module_enabled<F, O>(&mut self, callback: F) -> O
pub fn with_kernel_trace_module_enabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the kernel trace kernel module enabled and then resets the
state of the kernel modules.
sourcepub fn with_limits_module_enabled<F, O>(&mut self, callback: F) -> O
pub fn with_limits_module_enabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the limits kernel module enabled and then resets the state
of the kernel modules.
sourcepub fn with_costing_module_enabled<F, O>(&mut self, callback: F) -> O
pub fn with_costing_module_enabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the costing kernel module enabled and then resets the state
of the kernel modules.
sourcepub fn with_auth_module_enabled<F, O>(&mut self, callback: F) -> O
pub fn with_auth_module_enabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the auth kernel module enabled and then resets the state of
the kernel modules.
sourcepub fn with_transaction_runtime_module_enabled<F, O>(
&mut self,
callback: F
) -> O
pub fn with_transaction_runtime_module_enabled<F, O>( &mut self, callback: F ) -> O
Calls the passed callback
with the transaction env kernel module enabled and then
resets the state of the kernel modules.
sourcepub fn with_execution_trace_module_enabled<F, O>(&mut self, callback: F) -> O
pub fn with_execution_trace_module_enabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the execution trace kernel module enabled and then resets
the state of the kernel modules.
sourcepub fn with_kernel_trace_module_disabled<F, O>(&mut self, callback: F) -> O
pub fn with_kernel_trace_module_disabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the kernel trace kernel module disabled and then resets the
state of the kernel modules.
sourcepub fn with_limits_module_disabled<F, O>(&mut self, callback: F) -> O
pub fn with_limits_module_disabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the limits kernel module disabled and then resets the state
of the kernel modules.
sourcepub fn with_costing_module_disabled<F, O>(&mut self, callback: F) -> O
pub fn with_costing_module_disabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the costing kernel module disabled and then resets the
state of the kernel modules.
sourcepub fn with_auth_module_disabled<F, O>(&mut self, callback: F) -> O
pub fn with_auth_module_disabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the auth kernel module disabled and then resets the state
of the kernel modules.
sourcepub fn with_transaction_runtime_module_disabled<F, O>(
&mut self,
callback: F
) -> O
pub fn with_transaction_runtime_module_disabled<F, O>( &mut self, callback: F ) -> O
Calls the passed callback
with the transaction env kernel module disabled and then
resets the state of the kernel modules.
sourcepub fn with_execution_trace_module_disabled<F, O>(&mut self, callback: F) -> O
pub fn with_execution_trace_module_disabled<F, O>(&mut self, callback: F) -> O
Calls the passed callback
with the execution trace kernel module disabled and then resets
the state of the kernel modules.
sourcepub fn enabled_modules(&self) -> EnabledModules
pub fn enabled_modules(&self) -> EnabledModules
Returns the bit flags representing the currently enabled kernel modules.
sourcepub fn set_enabled_modules(&mut self, enabled_modules: EnabledModules)
pub fn set_enabled_modules(&mut self, enabled_modules: EnabledModules)
Sets the bit flags representing the enabled kernel modules.
sourcepub fn enable_module(&mut self, module: EnabledModules)
pub fn enable_module(&mut self, module: EnabledModules)
Enables specific kernel module(s).
sourcepub fn disable_module(&mut self, module: EnabledModules)
pub fn disable_module(&mut self, module: EnabledModules)
Disables specific kernel module(s).
sourcepub fn read_component_state<S, N>(
&mut self,
node_id: N
) -> Result<S, RuntimeError>
pub fn read_component_state<S, N>( &mut self, node_id: N ) -> Result<S, RuntimeError>
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 implementsInto<NodeId>
.
§Returns
Result<S, RuntimeError>
- If the component state could be read successfully then anOk
is returned, otherwise anErr
is returned.
§Panics
This method panics if the component state can not be decoded as the generic type parameter
[S
].
sourcepub fn get_current_epoch(&mut self) -> Epoch
pub fn get_current_epoch(&mut self) -> Epoch
Gets the current epoch from the Consensus Manager.
sourcepub fn set_current_epoch(&mut self, epoch: Epoch)
pub fn set_current_epoch(&mut self, epoch: Epoch)
Sets the current epoch.
sourcepub fn get_current_time(&mut self) -> Instant
pub fn get_current_time(&mut self) -> Instant
Gets the current time stamp from the Consensus Manager.
pub fn set_current_time(&mut self, instant: Instant)
sourcepub(crate) fn as_method_actor<N, F, O>(
&mut self,
node_id: N,
module_id: ModuleId,
method_ident: &str,
callback: F
) -> Result<O, RuntimeError>
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>
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.
sourcepub(crate) fn as_actor<F, O>(
&mut self,
actor: Actor,
callback: F
) -> Result<O, RuntimeError>
pub(crate) fn as_actor<F, O>( &mut self, actor: Actor, callback: F ) -> Result<O, RuntimeError>
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
impl ClientActorApi<RuntimeError> for TestEnvironment
source§fn actor_get_blueprint_id(&mut self) -> Result<BlueprintId, RuntimeError>
fn actor_get_blueprint_id(&mut self) -> Result<BlueprintId, RuntimeError>
source§fn actor_open_field(
&mut self,
object_handle: ActorStateHandle,
field: FieldIndex,
flags: LockFlags
) -> Result<FieldHandle, RuntimeError>
fn actor_open_field( &mut self, object_handle: ActorStateHandle, field: FieldIndex, flags: LockFlags ) -> Result<FieldHandle, RuntimeError>
source§fn actor_is_feature_enabled(
&mut self,
object_handle: ActorStateHandle,
feature: &str
) -> Result<bool, RuntimeError>
fn actor_is_feature_enabled( &mut self, object_handle: ActorStateHandle, feature: &str ) -> Result<bool, RuntimeError>
source§fn actor_get_node_id(
&mut self,
ref_handle: ActorRefHandle
) -> Result<NodeId, RuntimeError>
fn actor_get_node_id( &mut self, ref_handle: ActorRefHandle ) -> Result<NodeId, RuntimeError>
source§fn actor_emit_event(
&mut self,
event_name: String,
event_data: Vec<u8>,
event_flags: EventFlags
) -> Result<(), RuntimeError>
fn actor_emit_event( &mut self, event_name: String, event_data: Vec<u8>, event_flags: EventFlags ) -> Result<(), RuntimeError>
source§impl ClientActorIndexApi<RuntimeError> for TestEnvironment
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>
fn actor_index_insert( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: Vec<u8>, buffer: Vec<u8> ) -> Result<(), RuntimeError>
source§fn actor_index_remove(
&mut self,
object_handle: ActorStateHandle,
collection_index: CollectionIndex,
key: Vec<u8>
) -> Result<Option<Vec<u8>>, RuntimeError>
fn actor_index_remove( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: Vec<u8> ) -> Result<Option<Vec<u8>>, RuntimeError>
source§fn actor_index_scan_keys(
&mut self,
object_handle: ActorStateHandle,
collection_index: CollectionIndex,
limit: u32
) -> Result<Vec<Vec<u8>>, RuntimeError>
fn actor_index_scan_keys( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, limit: u32 ) -> Result<Vec<Vec<u8>>, RuntimeError>
source§fn actor_index_drain(
&mut self,
object_handle: ActorStateHandle,
collection_index: CollectionIndex,
limit: u32
) -> Result<Vec<(Vec<u8>, Vec<u8>)>, RuntimeError>
fn actor_index_drain( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, limit: u32 ) -> Result<Vec<(Vec<u8>, Vec<u8>)>, RuntimeError>
source§fn actor_index_insert_typed<K, V>(
&mut self,
object_handle: u32,
collection_index: u8,
key: K,
value: V
) -> Result<(), E>where
K: ScryptoEncode,
V: ScryptoEncode,
fn actor_index_insert_typed<K, V>(
&mut self,
object_handle: u32,
collection_index: u8,
key: K,
value: V
) -> Result<(), E>where
K: ScryptoEncode,
V: ScryptoEncode,
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,
fn actor_index_remove_typed<V>(
&mut self,
object_handle: u32,
collection_index: u8,
key: Vec<u8>
) -> Result<Option<V>, E>where
V: ScryptoDecode,
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,
fn actor_index_scan_keys_typed<K>(
&mut self,
object_handle: u32,
collection_index: u8,
limit: u32
) -> Result<Vec<K>, E>where
K: ScryptoDecode,
source§fn actor_index_drain_typed<K, V>(
&mut self,
object_handle: u32,
collection_index: u8,
limit: u32
) -> Result<Vec<(K, V)>, E>where
K: ScryptoDecode,
V: ScryptoDecode,
fn actor_index_drain_typed<K, V>(
&mut self,
object_handle: u32,
collection_index: u8,
limit: u32
) -> Result<Vec<(K, V)>, E>where
K: ScryptoDecode,
V: ScryptoDecode,
source§impl ClientActorKeyValueEntryApi<RuntimeError> for TestEnvironment
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>
fn actor_open_key_value_entry( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: &Vec<u8>, flags: LockFlags ) -> Result<KeyValueEntryHandle, RuntimeError>
fn actor_remove_key_value_entry( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, key: &Vec<u8> ) -> Result<Vec<u8>, RuntimeError>
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
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>
fn actor_sorted_index_insert( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, sorted_key: SortedKey, buffer: Vec<u8> ) -> Result<(), RuntimeError>
source§fn actor_sorted_index_remove(
&mut self,
object_handle: ActorStateHandle,
collection_index: CollectionIndex,
sorted_key: &SortedKey
) -> Result<Option<Vec<u8>>, RuntimeError>
fn actor_sorted_index_remove( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, sorted_key: &SortedKey ) -> Result<Option<Vec<u8>>, RuntimeError>
source§fn actor_sorted_index_scan(
&mut self,
object_handle: ActorStateHandle,
collection_index: CollectionIndex,
count: u32
) -> Result<Vec<(SortedKey, Vec<u8>)>, RuntimeError>
fn actor_sorted_index_scan( &mut self, object_handle: ActorStateHandle, collection_index: CollectionIndex, count: u32 ) -> Result<Vec<(SortedKey, Vec<u8>)>, RuntimeError>
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,
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,
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,
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,
source§fn actor_sorted_index_scan_typed<K, V>(
&mut self,
object_handle: u32,
collection_index: u8,
count: u32
) -> Result<Vec<(K, V)>, E>where
K: ScryptoDecode,
V: ScryptoDecode,
fn actor_sorted_index_scan_typed<K, V>(
&mut self,
object_handle: u32,
collection_index: u8,
count: u32
) -> Result<Vec<(K, V)>, E>where
K: ScryptoDecode,
V: ScryptoDecode,
source§impl ClientBlueprintApi<RuntimeError> for TestEnvironment
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>
fn call_function( &mut self, package_address: PackageAddress, blueprint_name: &str, function_name: &str, args: Vec<u8> ) -> Result<Vec<u8>, RuntimeError>
fn resolve_blueprint_type( &mut self, blueprint_type_id: &BlueprintTypeIdentifier ) -> Result<(Rc<VersionedScryptoSchema>, ScopedTypeId), RuntimeError>
source§impl ClientCostingApi<RuntimeError> for TestEnvironment
impl ClientCostingApi<RuntimeError> for TestEnvironment
source§fn start_lock_fee(&mut self, amount: Decimal) -> Result<bool, RuntimeError>
fn start_lock_fee(&mut self, amount: Decimal) -> Result<bool, RuntimeError>
source§fn lock_fee(&mut self, locked_fee: LiquidFungibleResource, contingent: bool)
fn lock_fee(&mut self, locked_fee: LiquidFungibleResource, contingent: bool)
fn consume_cost_units( &mut self, costing_entry: ClientCostingEntry<'_> ) -> Result<(), RuntimeError>
fn execution_cost_unit_limit(&mut self) -> Result<u32, RuntimeError>
fn execution_cost_unit_price(&mut self) -> Result<Decimal, RuntimeError>
fn finalization_cost_unit_limit(&mut self) -> Result<u32, RuntimeError>
fn finalization_cost_unit_price(&mut self) -> Result<Decimal, RuntimeError>
fn usd_price(&mut self) -> Result<Decimal, RuntimeError>
fn max_per_function_royalty_in_xrd(&mut self) -> Result<Decimal, RuntimeError>
fn tip_percentage(&mut self) -> Result<u32, RuntimeError>
fn fee_balance(&mut self) -> Result<Decimal, RuntimeError>
source§impl ClientCryptoUtilsApi<RuntimeError> for TestEnvironment
impl ClientCryptoUtilsApi<RuntimeError> for TestEnvironment
fn bls12381_v1_verify( &mut self, message: &[u8], public_key: &Bls12381G1PublicKey, signature: &Bls12381G2Signature ) -> Result<u32, RuntimeError>
fn bls12381_v1_aggregate_verify( &mut self, pub_keys_and_msgs: &[(Bls12381G1PublicKey, Vec<u8>)], signature: &Bls12381G2Signature ) -> Result<u32, RuntimeError>
fn bls12381_v1_fast_aggregate_verify( &mut self, message: &[u8], public_keys: &[Bls12381G1PublicKey], signature: &Bls12381G2Signature ) -> Result<u32, RuntimeError>
fn bls12381_g2_signature_aggregate( &mut self, signatures: &[Bls12381G2Signature] ) -> Result<Bls12381G2Signature, RuntimeError>
fn keccak256_hash(&mut self, data: &[u8]) -> Result<Hash, RuntimeError>
source§impl ClientExecutionTraceApi<RuntimeError> for TestEnvironment
impl ClientExecutionTraceApi<RuntimeError> for TestEnvironment
fn update_instruction_index( &mut self, new_index: usize ) -> Result<(), RuntimeError>
source§impl ClientFieldApi<RuntimeError> for TestEnvironment
impl ClientFieldApi<RuntimeError> for TestEnvironment
fn field_read(&mut self, handle: FieldHandle) -> Result<Vec<u8>, RuntimeError>
fn field_write( &mut self, handle: FieldHandle, buffer: Vec<u8> ) -> Result<(), RuntimeError>
fn field_lock(&mut self, handle: FieldHandle) -> Result<(), RuntimeError>
fn field_close(&mut self, handle: FieldHandle) -> Result<(), RuntimeError>
fn field_read_typed<S>(&mut self, handle: u32) -> Result<S, E>where
S: ScryptoDecode,
fn field_write_typed<S>(&mut self, handle: u32, substate: &S) -> Result<(), E>where
S: ScryptoEncode,
source§impl ClientKeyValueEntryApi<RuntimeError> for TestEnvironment
impl ClientKeyValueEntryApi<RuntimeError> for TestEnvironment
fn key_value_entry_get( &mut self, handle: KeyValueEntryHandle ) -> Result<Vec<u8>, RuntimeError>
fn key_value_entry_set( &mut self, handle: KeyValueEntryHandle, buffer: Vec<u8> ) -> Result<(), RuntimeError>
fn key_value_entry_remove( &mut self, handle: KeyValueEntryHandle ) -> Result<Vec<u8>, RuntimeError>
fn key_value_entry_lock( &mut self, handle: KeyValueEntryHandle ) -> Result<(), RuntimeError>
fn key_value_entry_close( &mut self, handle: KeyValueEntryHandle ) -> Result<(), RuntimeError>
fn key_value_entry_get_typed<S>(&mut self, handle: u32) -> Result<Option<S>, E>where
S: ScryptoDecode,
fn key_value_entry_set_typed<S>(
&mut self,
handle: u32,
value: S
) -> Result<(), E>where
S: ScryptoEncode,
source§impl ClientKeyValueStoreApi<RuntimeError> for TestEnvironment
impl ClientKeyValueStoreApi<RuntimeError> for TestEnvironment
source§fn key_value_store_new(
&mut self,
data_schema: KeyValueStoreDataSchema
) -> Result<NodeId, RuntimeError>
fn key_value_store_new( &mut self, data_schema: KeyValueStoreDataSchema ) -> Result<NodeId, RuntimeError>
source§fn key_value_store_open_entry(
&mut self,
node_id: &NodeId,
key: &Vec<u8>,
flags: LockFlags
) -> Result<KeyValueEntryHandle, RuntimeError>
fn key_value_store_open_entry( &mut self, node_id: &NodeId, key: &Vec<u8>, flags: LockFlags ) -> Result<KeyValueEntryHandle, RuntimeError>
fn key_value_store_remove_entry( &mut self, node_id: &NodeId, key: &Vec<u8> ) -> Result<Vec<u8>, RuntimeError>
source§impl ClientObjectApi<RuntimeError> for TestEnvironment
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>
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>
source§fn drop_object(
&mut self,
node_id: &NodeId
) -> Result<Vec<Vec<u8>>, RuntimeError>
fn drop_object( &mut self, node_id: &NodeId ) -> Result<Vec<Vec<u8>>, RuntimeError>
source§fn get_blueprint_id(
&mut self,
node_id: &NodeId
) -> Result<BlueprintId, RuntimeError>
fn get_blueprint_id( &mut self, node_id: &NodeId ) -> Result<BlueprintId, RuntimeError>
source§fn get_outer_object(
&mut self,
node_id: &NodeId
) -> Result<GlobalAddress, RuntimeError>
fn get_outer_object( &mut self, node_id: &NodeId ) -> Result<GlobalAddress, RuntimeError>
source§fn allocate_global_address(
&mut self,
blueprint_id: BlueprintId
) -> Result<(GlobalAddressReservation, GlobalAddress), RuntimeError>
fn allocate_global_address( &mut self, blueprint_id: BlueprintId ) -> Result<(GlobalAddressReservation, GlobalAddress), RuntimeError>
fn allocate_virtual_global_address( &mut self, blueprint_id: BlueprintId, global_address: GlobalAddress ) -> Result<GlobalAddressReservation, RuntimeError>
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>
fn globalize( &mut self, node_id: NodeId, modules: IndexMap<AttachedModuleId, NodeId>, address_reservation: Option<GlobalAddressReservation> ) -> Result<GlobalAddress, RuntimeError>
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>
fn call_method( &mut self, receiver: &NodeId, method_name: &str, args: Vec<u8> ) -> Result<Vec<u8>, RuntimeError>
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>
fn call_module_method( &mut self, receiver: &NodeId, module_id: AttachedModuleId, method_name: &str, args: Vec<u8> ) -> Result<Vec<u8>, RuntimeError>
source§fn new_simple_object(
&mut self,
blueprint_ident: &str,
fields: IndexMap<u8, FieldValue>
) -> Result<NodeId, E>
fn new_simple_object( &mut self, blueprint_ident: &str, fields: IndexMap<u8, FieldValue> ) -> Result<NodeId, E>
source§impl ClientTransactionRuntimeApi<RuntimeError> for TestEnvironment
impl ClientTransactionRuntimeApi<RuntimeError> for TestEnvironment
fn bech32_encode_address( &mut self, address: GlobalAddress ) -> Result<String, RuntimeError>
fn get_transaction_hash(&mut self) -> Result<Hash, RuntimeError>
fn generate_ruid(&mut self) -> Result<[u8; 32], RuntimeError>
fn emit_log( &mut self, level: Level, message: String ) -> Result<(), RuntimeError>
fn panic(&mut self, message: String) -> Result<(), RuntimeError>
impl ClientApi<RuntimeError> for TestEnvironment
Auto Trait Implementations§
impl !RefUnwindSafe for TestEnvironment
impl !Send for TestEnvironment
impl !Sync for TestEnvironment
impl Unpin for TestEnvironment
impl !UnwindSafe for TestEnvironment
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.