pub struct Mock { /* private fields */ }
Expand description
Mock ethereum node.
This struct implements a virtual ethereum node with a limited number
of supported RPC calls. You can interact with it via the standard
transport from web3
.
The main feature of this struct is deploying mocked contracts
and interacting with them. Create new mocked contract with a call
to deploy
function. Then use the returned struct to set up
expectations on contract methods, get deployed contract’s address
and Instance
and make actual calls to it.
Deploying contracts with an RPC call is not supported at the moment.
Implementations§
Source§impl Mock
impl Mock
Sourcepub fn web3(&self) -> DynWeb3
pub fn web3(&self) -> DynWeb3
Creates a Web3
object that can be used to interact with
the mocked chain.
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 deploy(&self, abi: Abi) -> Contract
pub fn deploy(&self, abi: Abi) -> Contract
Deploys a new mocked contract and returns an object that allows configuring expectations for contract methods.
Sourcepub fn deploy_with_address(&self, abi: Abi, address: Address) -> Contract
pub fn deploy_with_address(&self, abi: Abi, address: Address) -> Contract
Deploys a new mocked contract with specified address and returns an object that allows configuring expectations for contract methods.
Sourcepub fn update_gas_price(&self, gas_price: u64)
pub fn update_gas_price(&self, gas_price: u64)
Updates gas price that is returned by RPC call eth_gasPrice
.
Mock node does not simulate gas consumption, so this value does not
affect anything if you don’t call eth_gasPrice
.
Sourcepub fn checkpoint(&self)
pub fn checkpoint(&self)
Verifies that all expectations on all contracts 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 Contract::expect
method
become invalid after checkpoint. Modifying them will result in panic.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mock
impl RefUnwindSafe for Mock
impl Send for Mock
impl Sync for Mock
impl Unpin for Mock
impl UnwindSafe for Mock
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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