pub struct MockFn<State> { /* private fields */ }Expand description
Holds a function used for mocking invocations of contracts with
invoke_contract.
Implementations§
Source§impl<State> MockFn<State>
impl<State> MockFn<State>
Sourcepub fn new<R, F>(mock_fn_return: F) -> Selfwhere
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> CallContractResult<R> + 'static,
👎Deprecated since 8.1.0: Deprecated in favor of concordium-smart-contract-testing.
pub fn new<R, F>(mock_fn_return: F) -> Selfwhere
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) -> Selfwhere
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> Result<(bool, R), CallContractError<R>> + 'static,
👎Deprecated since 8.1.0: Deprecated in favor of concordium-smart-contract-testing.
pub fn new_v1<R, F>(mock_fn_return: F) -> Selfwhere
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) -> Selfwhere
R: Serial,
F: Fn(Parameter<'_>, Amount, &mut Amount, &mut State) -> Result<bool, CallContractError<R>> + 'static,
👎Deprecated since 8.1.0: Deprecated in favor of concordium-smart-contract-testing.
pub fn new_v0<R, F>(mock_fn_return: F) -> Selfwhere
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
👎Deprecated since 8.1.0: Deprecated in favor of concordium-smart-contract-testing.
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
👎Deprecated since 8.1.0: Deprecated in favor of concordium-smart-contract-testing.
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.