How to Write Integration Tests
The following is an example of a test that includes a dependency contract into the test, rather than mock it. The test is written to test the increment-with-pause contract and the pause contract. The contract has anincrement function that increases a counter value by one on every invocation. The contract depends on the pause contract to control whether the increment functionality is paused.
The following tests set up the increment-with-pause contract, as well as import and register the real pause contract using its wasm file.
-
Use the [stellar contract fetch] command to fetch the dependency contract that’s already deployed on testnet or mainnet.
-
Import the contract into the tests with the
contractimport!macro. -
Write a test similar to the following that registers not only the increment-with-pause contract, but also the pause contract that was imported. The test checks that when the pause contract is not paused that the increment contract operates as expected. When it is paused, the increment function errors. Once it’s unpaused the function operates as expected.
- Create an environment, the
Env. - Register the contract(s) to be tested.
- Invoke functions using the generated client.
- Assert the outcome.