Testing should help developers move faster and not break things. When building indexers, that often feels different. That's why we decided to add a built-in tool to Apibara to quickly test your indexers.
If you want to start testing your indexers, update the Apibara CLI to the latest version with:
curl -sL https://install.apibara.com | bash
apibara test command implements snapshot testing for Apibara indexers.
The first time you run a test, it will fetch actual data from a DNA stream and
run your indexer on this data, storing all relevant data (configuration, input
stream, and output data) to a snapshot file. You can inspect this file with any
text editor and check that the output matches your expectations (pro tip: you
can manually edit the result to your liking). Now, you can rerun the test
command, and it will replay the stream data from the snapshot file and compare
the output of the indexer with what is stored in the snapshot. If the output
matches, the test is considered a success. If it fails, the CLI will print an
error message showing a difference between the expected and actual results.
The test command provides some options to customize the input stream by
specifying a specific block range for replaying data, among other
customizations. You can also decide to overwrite an existing snapshot file. We
will publish a more detailed testing tutorial in the upcoming days. You can read
more by running
apibara test --help.