Type Alias TestExternalities
pub type TestExternalities = TestExternalities<Blake2Hasher>;
Expand description
Type alias for Externalities implementation used in tests.
Aliased Type§
struct TestExternalities {
pub backend: TrieBackend<MemoryDB<Blake2Hasher, PrefixedKey<Blake2Hasher>, Vec<u8>>, Blake2Hasher>,
pub extensions: Extensions,
pub state_version: StateVersion,
/* private fields */
}
Fields§
§backend: TrieBackend<MemoryDB<Blake2Hasher, PrefixedKey<Blake2Hasher>, Vec<u8>>, Blake2Hasher>
Storage backend.
extensions: Extensions
Extensions.
state_version: StateVersion
State version to use during tests.
Implementations
§impl<H> TestExternalities<H>where
H: Hasher + 'static,
<H as Hasher>::Out: Ord + 'static + Codec,
impl<H> TestExternalities<H>where
H: Hasher + 'static,
<H as Hasher>::Out: Ord + 'static + Codec,
pub fn ext(
&mut self,
) -> Ext<'_, H, TrieBackend<MemoryDB<H, PrefixedKey<H>, Vec<u8>>, H>>
pub fn ext( &mut self, ) -> Ext<'_, H, TrieBackend<MemoryDB<H, PrefixedKey<H>, Vec<u8>>, H>>
Get externalities implementation.
pub fn new(storage: Storage) -> TestExternalities<H>
pub fn new(storage: Storage) -> TestExternalities<H>
Create a new instance of TestExternalities
with storage.
pub fn new_with_state_version(
storage: Storage,
state_version: StateVersion,
) -> TestExternalities<H>
pub fn new_with_state_version( storage: Storage, state_version: StateVersion, ) -> TestExternalities<H>
Create a new instance of TestExternalities
with storage for a given state version.
pub fn new_empty() -> TestExternalities<H>
pub fn new_empty() -> TestExternalities<H>
New empty test externalities.
pub fn new_with_code(code: &[u8], storage: Storage) -> TestExternalities<H>
pub fn new_with_code(code: &[u8], storage: Storage) -> TestExternalities<H>
Create a new instance of TestExternalities
with code and storage.
pub fn new_with_code_and_state(
code: &[u8],
storage: Storage,
state_version: StateVersion,
) -> TestExternalities<H>
pub fn new_with_code_and_state( code: &[u8], storage: Storage, state_version: StateVersion, ) -> TestExternalities<H>
Create a new instance of TestExternalities
with code and storage for a given state
version.
pub fn overlayed_changes(&self) -> &OverlayedChanges<H>
pub fn overlayed_changes(&self) -> &OverlayedChanges<H>
Returns the overlayed changes.
pub fn persist_offchain_overlay(&mut self)
pub fn persist_offchain_overlay(&mut self)
Move offchain changes from overlay to the persistent store.
pub fn offchain_db(&self) -> TestPersistentOffchainDB
pub fn offchain_db(&self) -> TestPersistentOffchainDB
A shared reference type around the offchain worker storage.
pub fn batch_insert<I>(&mut self, kvs: I)
pub fn batch_insert<I>(&mut self, kvs: I)
Batch insert key/values into backend
pub fn insert_child(&mut self, c: ChildInfo, k: Vec<u8>, v: Vec<u8>)
pub fn insert_child(&mut self, c: ChildInfo, k: Vec<u8>, v: Vec<u8>)
Insert key/value into backend.
This only supports inserting keys in child tries.
pub fn register_extension<E>(&mut self, ext: E)where
E: Any + Extension,
pub fn register_extension<E>(&mut self, ext: E)where
E: Any + Extension,
Registers the given extension for this instance.
pub fn from_raw_snapshot(
raw_storage: Vec<(Vec<u8>, (Vec<u8>, i32))>,
storage_root: <H as Hasher>::Out,
state_version: StateVersion,
) -> TestExternalities<H>
pub fn from_raw_snapshot( raw_storage: Vec<(Vec<u8>, (Vec<u8>, i32))>, storage_root: <H as Hasher>::Out, state_version: StateVersion, ) -> TestExternalities<H>
Sets raw storage key/values and a root.
This can be used as a fast way to restore the storage state from a backup because the trie does not need to be computed.
pub fn into_raw_snapshot(
self,
) -> (Vec<(Vec<u8>, (Vec<u8>, i32))>, <H as Hasher>::Out)
pub fn into_raw_snapshot( self, ) -> (Vec<(Vec<u8>, (Vec<u8>, i32))>, <H as Hasher>::Out)
Drains the underlying raw storage key/values and returns the root hash.
Useful for backing up the storage in a format that can be quickly re-loaded.
pub fn as_backend(
&mut self,
) -> TrieBackend<MemoryDB<H, PrefixedKey<H>, Vec<u8>>, H>
pub fn as_backend( &mut self, ) -> TrieBackend<MemoryDB<H, PrefixedKey<H>, Vec<u8>>, H>
Return a new backend with all pending changes.
In contrast to commit_all
this will not panic if there are open
transactions.
pub fn commit_all(&mut self) -> Result<(), String>
pub fn commit_all(&mut self) -> Result<(), String>
Commit all pending changes to the underlying backend.
§Panic
This will panic if there are still open transactions.
pub fn execute_with<R>(&mut self, execute: impl FnOnce() -> R) -> R
pub fn execute_with<R>(&mut self, execute: impl FnOnce() -> R) -> R
Execute the given closure while self
is set as externalities.
Returns the result of the given closure.
pub fn execute_and_prove<R>(
&mut self,
execute: impl FnOnce() -> R,
) -> (R, StorageProof)
pub fn execute_and_prove<R>( &mut self, execute: impl FnOnce() -> R, ) -> (R, StorageProof)
Execute the given closure while self
, with proving_backend
as backend, is set as
externalities.
This implementation will wipe the proof recorded in between calls. Consecutive calls will get their own proof from scratch.
pub fn execute_with_safe<R>(
&mut self,
f: impl FnOnce() -> R + UnwindSafe,
) -> Result<R, String>
pub fn execute_with_safe<R>( &mut self, f: impl FnOnce() -> R + UnwindSafe, ) -> Result<R, String>
Execute the given closure while self
is set as externalities.
Returns the result of the given closure, if no panics occurred.
Otherwise, returns Err
.
Trait Implementations
§impl<H> Default for TestExternalities<H>where
H: Hasher,
<H as Hasher>::Out: Ord + 'static + Codec,
impl<H> Default for TestExternalities<H>where
H: Hasher,
<H as Hasher>::Out: Ord + 'static + Codec,
§impl<H> ExtensionStore for TestExternalities<H>where
H: Hasher,
<H as Hasher>::Out: Ord + Codec,
impl<H> ExtensionStore for TestExternalities<H>where
H: Hasher,
<H as Hasher>::Out: Ord + Codec,
§fn extension_by_type_id(
&mut self,
type_id: TypeId,
) -> Option<&mut (dyn Any + 'static)>
fn extension_by_type_id( &mut self, type_id: TypeId, ) -> Option<&mut (dyn Any + 'static)>
type_id
and returns it as a &mut dyn Any
. Read more§impl<H> ExternalitiesExt for TestExternalities<H>where
H: Hasher,
<H as Hasher>::Out: Ord + Codec,
impl<H> ExternalitiesExt for TestExternalities<H>where
H: Hasher,
<H as Hasher>::Out: Ord + Codec,
§fn extension<T>(&mut self) -> Option<&mut T>where
T: Any + Extension,
fn extension<T>(&mut self) -> Option<&mut T>where
T: Any + Extension,
§fn register_extension<T>(&mut self, ext: T) -> Result<(), Error>where
T: Extension,
fn register_extension<T>(&mut self, ext: T) -> Result<(), Error>where
T: Extension,
ext
. Read more§fn deregister_extension<T>(&mut self) -> Result<(), Error>where
T: Extension,
fn deregister_extension<T>(&mut self) -> Result<(), Error>where
T: Extension,
T
type. Read more