Write bulloak tree specifications (.tree files) for smart contract integration tests...
Write bulloak tree specifications for smart contract tests.
| Reference | Content | When to Read |
|---|---|---|
./references/examples.md |
Complete tree and generated test examples | When learning BTT syntax |
./references/sablier-conventions.md |
Sablier-specific terminology and examples | When working in Sablier repos |
Bulloak is a Solidity test generator that creates test scaffolds from .tree specification files. It offers a
structured approach to test case design that ensures comprehensive coverage of all possible scenarios and edge cases in
your smart contract tests.
cargo install bulloak
bulloak scaffold -wf --skip-modifiers --format-descriptions <path/to/file.tree>
where:
--format-descriptions capitalizes the first letter of the branch in the test contract and add a period at the end of
it.--skip-modifiers skips the generation of modifiers. We do this because we put all the modifiers in a separate
Modifiers.sol file.bulloak check --skip-modifiers <path/to/file.tree>
FunctionName_ContractName_Integration_Test
āāā condition1
ā āāā outcome1
āāā condition2
āāā outcome2
| Keyword | Purpose |
|---|---|
when |
Conditional branch (user input or timestamp) |
given |
Pre-condition contract state branch |
it |
Action/assertion (leaf node) |
when and given become modifiers if they have nested branches._Integration_Concrete_Test.Contract::function, using :: as a separator, and
all roots must share the same contract name (e.g., Foo::hashPair, Foo::min).when or given, it is a condition. when and given are interchangeable.it, it is an action. Any child branch an action has is called an action description.For examples, see ./references/examples.md.
tests/integration/concrete/{function} directory.- format. For example, if the function name is createFlowStream, the corrresponding
test tree and test file must be placed in the tests/integration/concrete/create-flow-stream directory.{function}.tree.{function}.t.sol.{FunctionName}_Integration_Concrete_Test.Location for tree file: tests/integration/concrete/{function-name}/{functionName}.tree
Note: Your repo's agent will provide the exact directory structure.
bulloak scaffold -wf --skip-modifiers --format-descriptions <path/to/file.tree>
This generates a .t.sol file.
bulloak check --skip-modifiers <path/to/file.tree>
If it returns false, your repo agent will look into it and fix the issues.
Start with guard conditions that cause early reverts:
āāā when delegate call // First: delegation check
ā āāā it should revert.
āāā when no delegate call
āāā given null // Second: existence check
ā āāā it should revert.
āāā given not null
āāā when amount zero // Third: input validation
ā āāā it should revert.
āāā when amount not zero
āāā ... // Finally: business logic
Some examples below:
| Concept | Convention |
|---|---|
| Resource doesn't exist | given null |
| Resource exists | given not null |
| Caller check | when caller {role} |
| Amount check | when amount {condition} |
Whenever possible, try to use less words and more concise language for the branches.
āāā when withdrawal address not zero
āāā when withdrawal address not owner // Non-owner cases
ā āāā when caller sender
ā āāā when caller unknown
ā āāā when caller recipient
āāā when withdrawal address owner // Owner cases
āāā ...
For success cases, enumerate all side effects:
āāā it should make the withdrawal.
āāā it should reduce the entry balance by the withdrawn amount.
āāā it should reduce the aggregate amount by the withdrawn amount.
āāā it should update the entry state.
āāā it should update the timestamp.
āāā it should emit {Transfer}, {Withdraw} and {MetadataUpdate} events.
Put events in parenthesis: {EventName}.
Child branch symbols (ā/ā) must align with the tail of parent's āāā or āāā (3 spaces, not 4):
āāā when withdrawal address not zero
āāā when withdrawal address not owner ā Correct (3 spaces)
ā āāā when caller sender
# Scaffold tests from tree
bulloak scaffold -wf --skip-modifiers --format-descriptions <path/to/file.tree>
# Check all trees in a directory
bulloak check --skip-modifiers tests/**/*.tree
https://github.com/alexfertel/bulloak/blob/main/README.md
Test this skill with these prompts:
deposit function that reverts when amount is zero and succeeds otherwise"withdraw that checks null stream, caller authorization, and amount
validation"cancel in the Lockup protocol with proper stream state checks"