Test Snapshots
The Soroban Rust SDK generates test snapshots on every test involving anEnv. Test snapshots are enabled by default. At the end of the test the Env writes a JSON file to the test_snapshots directory with a full snapshot of all the events published, and the final ledger storage state.
Most tests have a single Env and will result in a single test snapshot. Tests that have multiple Envs will write multiple test snapshots, one for each Env. Test snapshot files are named with a incrementing number on the end to separate the test snapshots for each Env.
How to Use Test Snapshots
-
Write tests using the default
Env. For example: -
Run the tests and see that the test snapshots have been written to
test_snapshots/. - Commit the test snapshots to source control.
- On future updates look out for changes to test snapshots in tests that are unexpected. For example, when changing one part of a contract if the test snapshots for other parts of the contract or unrelated end-to-end tests change, that could signal that side-effects have occurred.
- Diff test snapshots as needed to look for hints to why an unexpected change has occurred.
Test snapshots files are verbose. Test snapshots are most useful when changes appear and can be diffed, such as a new event being published, or storage changing.