pub struct Contract { /* private fields */ }
Expand description
A mocked contract deployed by the mock node.
This struct allows setting up expectations on which contract methods will be called, with what arguments, in what order, etc.
Implementations§
Source§impl Contract
impl Contract
Sourcepub fn web3(&self) -> DynWeb3
pub fn web3(&self) -> DynWeb3
Creates a Web3
object that can be used to interact with
the mocked chain on which this contract is deployed.
Sourcepub fn transport(&self) -> DynTransport
pub fn transport(&self) -> DynTransport
Creates a Transport
object that can be used to interact with
the mocked chain.
Sourcepub fn instance(&self) -> DynInstance
pub fn instance(&self) -> DynInstance
Creates a contract Instance
that can be used to interact with
this contract.
Sourcepub fn into_instance(self) -> DynInstance
pub fn into_instance(self) -> DynInstance
Consumes this object and transforms it into a contract Instance
that can be used to interact with this contract.
Sourcepub fn expect<P: Tokenize + Send + 'static, R: Tokenize + Send + 'static>(
&self,
signature: impl Into<Signature<P, R>>,
) -> Expectation<P, R>
pub fn expect<P: Tokenize + Send + 'static, R: Tokenize + Send + 'static>( &self, signature: impl Into<Signature<P, R>>, ) -> Expectation<P, R>
Adds a new expectation for contract method. See Expectation
.
Generic parameters are used to specify which rust types should be used to encode and decode method’s arguments and return value. If you’re using generated contracts, they will be inferred automatically. If not, you may have to specify them manually.
§Notes
Expectations generated by this method will allow both view calls
and transactions. This is usually undesired, so prefer using
expect_call
and expect_transaction
instead.
Sourcepub fn expect_call<P: Tokenize + Send + 'static, R: Tokenize + Send + 'static>(
&self,
signature: impl Into<Signature<P, R>>,
) -> Expectation<P, R>
pub fn expect_call<P: Tokenize + Send + 'static, R: Tokenize + Send + 'static>( &self, signature: impl Into<Signature<P, R>>, ) -> Expectation<P, R>
Adds a new expectation for contract method that only matches view calls.
This is an equivalent of expect
followed by allow_transactions
(false)
.
Sourcepub fn expect_transaction<P: Tokenize + Send + 'static, R: Tokenize + Send + 'static>(
&self,
signature: impl Into<Signature<P, R>>,
) -> Expectation<P, R>
pub fn expect_transaction<P: Tokenize + Send + 'static, R: Tokenize + Send + 'static>( &self, signature: impl Into<Signature<P, R>>, ) -> Expectation<P, R>
Adds a new expectation for contract method that only matches transactions.
This is an equivalent of expect
followed by allow_calls
(false)
.
Sourcepub fn checkpoint(&self)
pub fn checkpoint(&self)
Verifies that all expectations on this contract have been met, then clears all expectations.
Sometimes its useful to validate all expectations mid-test, throw them away, and add new ones. That’s what checkpoints do. See mockall documentation for more info.
Note that all expectations returned from expect
method
become invalid after checkpoint. Modifying them will result in panic.
Auto Trait Implementations§
impl Freeze for Contract
impl RefUnwindSafe for Contract
impl Send for Contract
impl Sync for Contract
impl Unpin for Contract
impl UnwindSafe for Contract
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more