Skip to main content

MockTransactionHandler

Struct MockTransactionHandler 

Source
pub struct MockTransactionHandler { /* private fields */ }
Expand description

A mocked transaction context: runs one, and only one, transaction, with exactly one root frame (call / open_root_frame panic on a second invocation). Nest further calls as child frames, or use a second transaction.

Implementations§

Source§

impl MockTransactionHandler

Source

pub fn new(env: Rc<TestEnvironment>) -> Self

Create a mock transaction handler with the default configuration (see MockTransactionConfig).

Use TestEnvironment::transaction to customize the configuration before creating the handler.

Source

pub fn new_with_config( env: Rc<TestEnvironment>, config: MockTransactionConfig, ) -> Self

Create a mock transaction handler from an explicit MockTransactionConfig, letting a test configure the context of the mocked transaction.

Source

pub fn abort_transaction(&mut self)

Abort the running transaction, discarding its writes.

Panics unless the transaction is running and its root frame is closed.

Source

pub fn try_commit_transaction(&mut self) -> TryCommitResult

Attempt the two-phase commit of the running transaction.

Panics unless the transaction is running and its root frame is closed.

Source

pub fn call(&mut self, addr: &ContractAddress) -> FrameBuilder<'_>

Convenience: open a root frame targeting the given contract address. Returns a FrameBuilder for configuring and executing the frame.

A transaction has exactly one root frame, so a second call panics; call further contracts via child frames (FrameHandle::child_call, MockInvocationFrame::open_child_frame) or a separate transaction.

Source

pub fn open_root_frame( &mut self, contract_address: ContractAddress, ) -> MockInvocationFrameConfig<'_>

Configure this transaction’s root frame, invoking contract_address.

A transaction has exactly one root frame: calling this (or call) a second time on the same handler panics.

Child frames opened underneath it must name different addresses; see MockInvocationFrame::open_child_frame.

Trait Implementations§

Source§

impl Drop for MockTransactionHandler

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.