Skip to main content

End-to-end tests

There are three main levels of software testing: unit tests, integration tests, and end-to-end tests.

Protostar provides an environment to write unit tests for Starknet smart contracts in Cairo language itself. With the help of cheatcodes like deploy_contract it is also easy to write integration tests, deploying single or multiple contracts and examining the internal behavior of such small systems.

In end-to-end testing, the goal is to examine interactions not only within a system of contracts deployed on the blockchain, but also to examine interactions triggered by external services, like web frontends, and observing effects happening within these services themselves.

note

As an example, an end-to-end test of a voting application could trigger a click on a Vote button, causing a transaction to be executed on the blockchain. The test waits for the transaction to be accepted, then examines changes of the publicly available state of the voting contract, e.g. the final result of the voting.

End-to-end testing should focus on the bigger picture of the whole system, not only the smart contracts. Modifications and readings of the on-chain state should be done through exposed interfaces of contracts. Therefore, it is recommended to include end-to-end tests in test suites of client applications, implemented in their technologies. The following tools are suggested to set up the described testing environment:

  1. Starknet Devnet for running a local Starknet network,
  2. Starknet SDKs like Starknet.js or Starknet.py for interacting with Starknet from tests' code,
  3. Protostar CLI for building contracts and deploying in tests' setup phases and CI.

Testing standalone contracts

In case the smart contracts are standalone and supposed to be used by independent clients, one could write the test suite as an independent project using SDKs in general purpose languages, for example, in Jest and Starknet.js or pytest and Starknet.py.