pub struct TestExternalities<H: Hasher, N: ChangesTrieBlockNumber = u64>{ /* private fields */ }Expand description
Simple HashMap-based Externalities impl.
Implementations§
Source§impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
Sourcepub fn ext(&mut self) -> Ext<'_, H, N, InMemoryBackend<H>>
pub fn ext(&mut self) -> Ext<'_, H, N, InMemoryBackend<H>>
Get externalities implementation.
Sourcepub fn new_with_code(code: &[u8], storage: Storage) -> Self
pub fn new_with_code(code: &[u8], storage: Storage) -> Self
Create a new instance of TestExternalities with code and storage.
Sourcepub fn overlayed_changes(&self) -> &OverlayedChanges
pub fn overlayed_changes(&self) -> &OverlayedChanges
Returns the overlayed changes.
Sourcepub fn persist_offchain_overlay(&mut self)
pub fn persist_offchain_overlay(&mut self)
Move offchain changes from overlay to the persistent store.
Sourcepub fn offchain_db(&self) -> TestPersistentOffchainDB
pub fn offchain_db(&self) -> TestPersistentOffchainDB
A shared reference type around the offchain worker storage.
Sourcepub fn insert(&mut self, k: StorageKey, v: StorageValue)
pub fn insert(&mut self, k: StorageKey, v: StorageValue)
Insert key/value into backend
Sourcepub fn register_extension<E: Any + Extension>(&mut self, ext: E)
pub fn register_extension<E: Any + Extension>(&mut self, ext: E)
Registers the given extension for this instance.
Sourcepub fn changes_trie_storage(&mut self) -> &mut ChangesTrieInMemoryStorage<H, N>
pub fn changes_trie_storage(&mut self) -> &mut ChangesTrieInMemoryStorage<H, N>
Get mutable reference to changes trie storage.
Sourcepub 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.
Sourcepub 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.
Sourcepub 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 occured.
Otherwise, returns Err.
Trait Implementations§
Source§impl<H: Hasher, N: ChangesTrieBlockNumber> Debug for TestExternalities<H, N>
impl<H: Hasher, N: ChangesTrieBlockNumber> Debug for TestExternalities<H, N>
Source§impl<H: Hasher, N: ChangesTrieBlockNumber> Default for TestExternalities<H, N>
impl<H: Hasher, N: ChangesTrieBlockNumber> Default for TestExternalities<H, N>
Source§impl<H, N> ExtensionStore for TestExternalities<H, N>
impl<H, N> ExtensionStore for TestExternalities<H, N>
Source§fn extension_by_type_id(&mut self, type_id: TypeId) -> Option<&mut dyn Any>
fn extension_by_type_id(&mut self, type_id: TypeId) -> Option<&mut dyn Any>
type_id and returns it as a &mut dyn Any. Read moreSource§impl<H: Hasher, N: ChangesTrieBlockNumber> From<Storage> for TestExternalities<H, N>
impl<H: Hasher, N: ChangesTrieBlockNumber> From<Storage> for TestExternalities<H, N>
Source§impl<H: Hasher, N: ChangesTrieBlockNumber> PartialEq for TestExternalities<H, N>
impl<H: Hasher, N: ChangesTrieBlockNumber> PartialEq for TestExternalities<H, N>
Source§fn eq(&self, other: &TestExternalities<H, N>) -> bool
fn eq(&self, other: &TestExternalities<H, N>) -> bool
This doesn’t test if they are in the same state, only if they contains the same data at this state
Auto Trait Implementations§
impl<H, N = u64> !Freeze for TestExternalities<H, N>
impl<H, N = u64> !RefUnwindSafe for TestExternalities<H, N>
impl<H, N> Send for TestExternalities<H, N>
impl<H, N = u64> !Sync for TestExternalities<H, N>
impl<H, N> Unpin for TestExternalities<H, N>
impl<H, N = u64> !UnwindSafe for TestExternalities<H, N>
Blanket Implementations§
Source§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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
Source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.