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
impl MockTransactionHandler
Sourcepub fn new(env: Rc<TestEnvironment>) -> MockTransactionHandler
pub fn new(env: Rc<TestEnvironment>) -> MockTransactionHandler
Create a mock transaction handler with the default configuration
(see MockTransactionConfig).
Use TestEnvironment::transaction to customize the configuration
before creating the handler.
Sourcepub fn new_with_config(
env: Rc<TestEnvironment>,
config: MockTransactionConfig,
) -> MockTransactionHandler
pub fn new_with_config( env: Rc<TestEnvironment>, config: MockTransactionConfig, ) -> MockTransactionHandler
Create a mock transaction handler from an explicit
MockTransactionConfig, letting a test configure the context of the
mocked transaction.
Sourcepub fn abort_transaction(&mut self)
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.
Sourcepub fn try_commit_transaction(&mut self) -> TryCommitResult
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.
Sourcepub fn call(&mut self, addr: &ContractAddress) -> FrameBuilder<'_>
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.
Sourcepub fn open_root_frame(
&mut self,
contract_address: ContractAddress,
) -> MockInvocationFrameConfig<'_>
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.