1/
Now that @Sablier V2 is live, I would like to offer you a technical presentation of some of the key principles that went into building V2 Core.
I think we have one of the most robust codebases in web3 at the moment.
github.com/sablier-labs/v2-core
3/
Our Foundry test suite includes hundreds of files with unit, integration, invariant, and fork tests.
Unit and integration tests are further split into concrete and fuzz.
Each category gives us additional confidence that the protocol works correctly.
github.com/sablier-labs/v2-core/wiki/Tests
4/
Our secret sauce for testing is the Branching Tree Technique:
1. Target a function
2. Create a ".tree" file
3. Consider all possible execution paths
4. Consider what state leads to what paths
5. Define "when state is x" nodes
6. Define child "it should" tests
Example:
5/
Note that BTT is agnostic about test-driven development (TDD).
The function you are writing the Branching Tree for may or may not be already implemented.
What matters is that you don't jump head-first into Solidity (either production logic or tests).
7/
Notice that we used empty modifiers to "mirror" the Branching Tree in Solidity.
These modifiers need not be empty - you could use them as a scenario-building tool by implementing shared logic:
8/
Here's a sample of two other Branching Trees from V2 Core, as well as some excerpts from their implementation files.
9/
Side notes:
- We chose to mirror the Branching Trees with modifiers, but you can skip this part if you feel like it's too much
- We used ASCII characters to draw the trees
- There's a VSCode extension to get syntax highlighting for *.tree" files
marketplace.visualstudio.com/items?itemName=CTC.vscode-tree-extension
10/
Moving on to source code documentation.
In Sablier V2, all contracts, interfaces, libraries, functions, and variables are annotated with explanatory comments.
Explaining your code is crucial in web3 due to immutability.
11/
Closely related to documentation is code linting and formatting.
A linter helps you adhere to best practices, while a formatter makes your code more readable.
In V2 Core, we have a setup that combines Forge, Solhint, and Prettier.
12/
That was it; I hope you liked it and derived some value from this thread.
To stay in touch with all things development at @Sablier, join the chat in the #dev channel in our Discord community server.
discord.com/invite/bSwRCwWRsT