Struct Contract

Source
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

Source

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.

Source

pub fn transport(&self) -> DynTransport

Creates a Transport object that can be used to interact with the mocked chain.

Source

pub fn instance(&self) -> DynInstance

Creates a contract Instance that can be used to interact with this contract.

Source

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.

Source

pub fn abi(&self) -> &Abi

Returns a reference to the contract’s ABI.

Source

pub fn address(&self) -> Address

Returns contract’s address.

Source

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.

Source

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).

Source

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).

Source

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§

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V