Macro near_sdk::testing_env
source · macro_rules! testing_env { ($context:expr, $config:expr, $fee_config:expr, $validators:expr, $promise_results:expr $(,)?) => { ... }; ($context:expr, $config:expr, $fee_config:expr, $validators:expr $(,)?) => { ... }; ($context:expr, $config:expr, $fee_config:expr $(,)?) => { ... }; ($context:expr, $config:expr $(,)?) => { ... }; ($context:expr) => { ... }; }
Expand description
Initializes a testing environment to mock interactions which would otherwise go through a
validator node. This macro will initialize or overwrite the MockedBlockchain
instance for interactions from a smart contract.
There are five parameters that can be accepted to configure the interface with a
MockedBlockchain
, in this order:
context
:VMContext
which contains some core information about the blockchain and message data which can be used from the smart contract.config
(optional):vm::Config
which contains some additional information about the VM to configure parameters not directly related to the transaction being executed.fee_config
(optional):RuntimeFeesConfig
which configures the fees for execution and storage of transactions.validators
(optional): aHashMap
<AccountId
,Balance
> mocking the current validators of the blockchain.promise_results
(optional): aVec
ofPromiseResult
which mocks the results of callback calls during the execution.
Any argument not included will use the default implementation of each.
§Example use
use near_sdk::{testing_env, test_vm_config};
use near_sdk::test_utils::{accounts, VMContextBuilder};
use near_parameters::RuntimeFeesConfig;
use std::collections::HashMap;
// Initializing some context is required
let context = VMContextBuilder::new().signer_account_id(accounts(0)).build();
// Build with just the base context
testing_env!(context.clone());
// Or include arguments up to the five optional
testing_env!(
context,
test_vm_config(),
RuntimeFeesConfig::test(),
HashMap::default(),
Vec::default(),
);