Struct concordium_std::test_infrastructure::MockFn
source · [−]pub struct MockFn<State> { /* private fields */ }
Expand description
Holds a function used for mocking invocations of contracts with
invoke_contract
.
Implementations
sourceimpl<State> MockFn<State>
impl<State> MockFn<State>
sourcepub fn new<R, F>(mock_fn_return: F) -> Self where
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> CallContractResult<R> + 'static,
pub fn new<R, F>(mock_fn_return: F) -> Self where
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> CallContractResult<R> + 'static,
Create a mock function which has access to parameter
, amount
,
balance
, and state
.
parameter
and amount
correspond to the values used in
invoke_contract(.., parameter, .., amount)
.
balance
and state
correspond to the values from the contract you are
testing. They are used to simulate calls to the contract itself,
which can change the balance and state of the contract.
The function should return a pair (state_modified, return_value), where
state_modified should be set to true
, if the function modifies the
state parameter. It should modify the balance
and state
in way
desired in the test, or in a way that the called contract is
intended to behave.
See also returning_ok
and returning_err
for when you need simple
mocks.
sourcepub fn new_v1<R, F>(mock_fn_return: F) -> Self where
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> Result<(bool, R), CallContractError<R>> + 'static,
pub fn new_v1<R, F>(mock_fn_return: F) -> Self where
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> Result<(bool, R), CallContractError<R>> + 'static,
A helper that assumes that a V1 contract is invoked. This means that the return value will always be present in case of success.
sourcepub fn new_v0<R, F>(mock_fn_return: F) -> Self where
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> Result<bool, CallContractError<R>> + 'static,
pub fn new_v0<R, F>(mock_fn_return: F) -> Self where
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> Result<bool, CallContractError<R>> + 'static,
A helper that assumes that a V0 contract is invoked. This means that the return value will never be present in case of success, and hence does not have to be provided by the caller.
sourcepub fn returning_ok<R: Clone + Serial + 'static>(return_value: R) -> Self
pub fn returning_ok<R: Clone + Serial + 'static>(return_value: R) -> Self
Create a simple mock function that returns Ok
with the same
value every time, and signals the state is not changed.
sourcepub fn returning_err<R: Clone + Serial + 'static>(
error: CallContractError<R>
) -> Self
pub fn returning_err<R: Clone + Serial + 'static>(
error: CallContractError<R>
) -> Self
Create a simple mock function that returns Err
with same error every
time.
Auto Trait Implementations
impl<State> !RefUnwindSafe for MockFn<State>
impl<State> !Send for MockFn<State>
impl<State> !Sync for MockFn<State>
impl<State> Unpin for MockFn<State>
impl<State> !UnwindSafe for MockFn<State>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more