How to Write Tests with Mocks
The following is an example of a test that uses a mock, written to test the increment-with-pause contract. The contract has anincrement function that increases a counter value by one on every invocation. The contract depends on another contract that controls whether the increment functionality is paused.
The following tests set up the increment-with-pause contract, as well as a mock pause contract, and invokes the increment contract’s function several times under different conditions the pause contract is expected to be in.
The following test checks that when the pause contract is not paused, the increment contract functions.
- Create an environment, the
Env. - Register the contract(s) to be tested.
- Invoke functions using the generated client.
- Assert the outcome.