-
Notifications
You must be signed in to change notification settings - Fork 50
Tests
Tests are organized into four categories:
- Unit: simple tests that check the behavior of individual functions against a local EVM.
- Integration: similar to the unit tests but with more complex scenarios that involve multiple contracts.
- Invariant: conditional expressions that must always hold true.
- 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:
- Concrete: standard deterministic tests that take no inputs and run the exact same test every time
- Fuzz: non-deterministic tests with random inputs fuzzed by Foundry
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
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
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:
We use Bulloak to implement BTT for all our contracts.