Skip to content
smol-ninja edited this page Jan 29, 2025 · 9 revisions

Tests are organized into four categories:

  1. Unit: simple tests that check the behavior of individual functions against a local EVM.
  2. Integration: similar to the unit tests but with more complex scenarios that involve multiple contracts.
  3. Invariant: conditional expressions that must always hold true.
  4. Fork: complex tests that run against an Ethereum Mainnet fork, which ensure that the protocol works with deployed ERC-20 tokens.

Unit and integration tests are further divided into two sub-categories:

  1. Concrete: standard deterministic tests that take no inputs and run the exact same test every time
  2. Fuzz: non-deterministic tests with random inputs fuzzed by Foundry

Running

You can run all tests with this command:

bun run test

By default, the tests are not run against the optimized version of the contracts (i.e. the version that gets deployed to the blockchain). To do this, use the following command:

bun run test:optimized

Filtering

To selectively filter test by name, use the --match-test flag (or its shorthand --mt). For instance, to run only testFuzz_CreateWithTimestampsLL test, run the following command:

bun run test --match-test testFuzz_CreateWithTimestampsLL

Additionally, you can filter tests by contract name with the --match-contract flag (shorthand --mc). The following example demonstrates how to run all the tests defined in CreateWithTimestampsLL_Integration_Fuzz_Test contract:

forge test --match-contract CreateWithTimestampsLL_Integration_Fuzz_Test

Branching Tree Technique (BTT)

You may notice that some test files are accompanied by .tree files. The goal is to structure the tests within a tree in which the parent nodes represent specific state conditions that govern the smart contract's behavior, while the leaves represent the conditions being tested.

To mirror the tree in Solidity, we use modifiers following the naming pattern when<Condition> and given<Condition>

The Branching Tree Technique is explained in detail here:

Bulloak

We use Bulloak to implement BTT for all our contracts.

Clone this wiki locally