use core::any::Any;
pub mod api;
pub mod macros;
pub use frame_metadata::RuntimeMetadataPrefixed;
pub use frame_support::weights::Weight;
use frame_support::{
sp_runtime::traits::Dispatchable,
traits::fungible::Inspect,
};
use frame_system::{
pallet_prelude::BlockNumberFor,
EventRecord,
};
pub use macros::{
BlockBuilder,
DefaultSandbox,
};
use pallet_contracts::{
ContractExecResult,
ContractInstantiateResult,
};
pub use {
frame_support::sp_runtime::testing::H256,
frame_support::{
self,
sp_runtime::{
AccountId32,
DispatchError,
},
},
frame_system,
pallet_balances,
pallet_contracts,
pallet_timestamp,
paste,
sp_core::crypto::Ss58Codec,
sp_externalities::{
self,
Extension,
},
sp_io::TestExternalities,
};
#[derive(Clone, Debug)]
pub struct Snapshot {
pub storage: RawStorage,
pub storage_root: StorageRoot,
}
pub type RawStorage = Vec<(Vec<u8>, (Vec<u8>, i32))>;
pub type StorageRoot = H256;
type BalanceOf<R> =
<<R as pallet_contracts::Config>::Currency as Inspect<AccountIdFor<R>>>::Balance;
pub type AccountIdFor<R> = <R as frame_system::Config>::AccountId;
pub type RuntimeCall<R> = <R as frame_system::Config>::RuntimeCall;
pub type EventRecordOf<Runtime> = EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
<Runtime as frame_system::Config>::Hash,
>;
pub type ContractInstantiateResultFor<Runtime> = ContractInstantiateResult<
AccountIdFor<Runtime>,
BalanceOf<Runtime>,
EventRecordOf<Runtime>,
>;
pub type ContractExecResultFor<Runtime> =
ContractExecResult<BalanceOf<Runtime>, EventRecordOf<Runtime>>;
pub type RuntimeOf<S> = <S as Sandbox>::Runtime;
pub type RuntimeEventOf<S> = <RuntimeOf<S> as frame_system::Config>::RuntimeEvent;
pub trait Sandbox {
type Runtime: frame_system::Config;
fn execute_with<T>(&mut self, execute: impl FnOnce() -> T) -> T;
fn dry_run<T>(&mut self, action: impl FnOnce(&mut Self) -> T) -> T;
fn register_extension<E: Any + Extension>(&mut self, ext: E);
fn initialize_block(
_height: BlockNumberFor<Self::Runtime>,
_parent_hash: <Self::Runtime as frame_system::Config>::Hash,
) {
}
fn finalize_block(
_height: BlockNumberFor<Self::Runtime>,
) -> <Self::Runtime as frame_system::Config>::Hash {
Default::default()
}
fn default_actor() -> AccountIdFor<Self::Runtime>;
fn default_gas_limit() -> Weight {
Weight::from_parts(100_000_000_000, 3 * 1024 * 1024)
}
fn get_metadata() -> RuntimeMetadataPrefixed;
fn convert_account_to_origin(
account: AccountIdFor<Self::Runtime>,
) -> <<Self::Runtime as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin;
fn take_snapshot(&mut self) -> Snapshot;
fn restore_snapshot(&mut self, snapshot: Snapshot);
}