Skip to main content

TransactionBuilder

Struct TransactionBuilder 

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

Builder for configuring a mocked transaction before executing it.

Obtain one from TestEnvironment::transaction, chain with_* methods to configure it, then finish with transact, transact_manual, or build:

ⓘ
env.transaction()
    .with_auth_claim(my_claim)
    .transact(|tx| tx.call(&addr).run(|| { /* ... */ }));

env.transact(f) and env.transact_manual(f) are shorthand for env.transaction().transact(f) / .transact_manual(f) with the default configuration.

Implementations§

Source§

impl TransactionBuilder

Source

pub fn new(env: TestEnvironmentHandle) -> Self

Start a builder with the default MockTransactionConfig.

Source

pub fn with_auth_claim(self, auth_claim: AuthClaim) -> Self

Attach auth_claim to the mocked transaction instead of the default source-address claim, controlling the auth-claim the contract under test observes (e.g. via get_auth_claim).

Source

pub fn build(self) -> MockTransactionHandler

Create the configured MockTransactionHandler for manual orchestration. Prefer transact or transact_manual unless you need the handler directly.

Source

pub fn transact( self, f: impl FnOnce(&mut MockTransactionHandler) -> FrameResult, ) -> TransactResult

Execute a transaction with auto-commit. See TestEnvironment::transact.

Source

pub fn transact_manual<R>( self, f: impl FnOnce(&mut MockTransactionHandler) -> R, ) -> R

Execute a transaction with manual commit/abort control. See TestEnvironment::transact_manual.

The closure must call tx.try_commit_transaction() or tx.abort_transaction() before returning; forgetting panics here (a dropped handler would abort silently).

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.