Struct ethcontract_mock::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
sourceimpl 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.