A comprehensive guide on how to use AI to automate BTT (Blockchain Transaction Testing)

TLDR

I am mindblown how @cursor_ai and Bulloak (by @alexfertel) can automate Solidity BTT testing in Foundry:

  • Tell @cursor_ai to create .tree files from Solidity file

  • Use bulloak scafold to create .s.sol files from .tree files

  • @cursor_ai performs well in basic tests

  • 90% of task done

What is BTT?

The Branching Tree Technique (BTT) is a structured approach to test case design that ensures comprehensive coverage of all possible scenarios and edge cases in your smart contract tests. You can learn more in the Bulloak website and from the BTT Foundry best practices presentation from Paul Razvan Berg.

BTT organizes test cases in a tree-like structure, where:

├──Branches represent different conditions or states

└──Leaves represent specific test cases or assertions

How can I generate BTT tree files?

Open a Cursor chat with the Solidity files you want to test, attach the @PaulRBerg presentation about BTT testing to the chat context and it will do a first try.

A Cursor chat with the Solidity files you want to test

t will generate a single .tree file and it didn't use the correct naming in some trees, which is not optimal, we ask it to follow the table convention from the specific slide.

A Cursor chat with the Solidity files you want to test

After telling him the naming convention, the output was much better. Them, asked Cursor to split the big .tree file into one .tree file per function and store it in folders.

A Cursor chat with the Solidity files you want to test

The output was a bash script that creates all the structure, just click to run in your terminal.

Once all directories and trees are in your project, run bulloak:


bulloak scaffold -S -w tests/unit/**/*.tree

And that's it! It will generate all the .s.sol test files for you, following BTT convention.

If bulloak finds an incorrect line in a .tree file, you can always fix it manually or just ask Cursor to fix it.

Them, you can try to use Cursor to write all the remaining boilerplate and even do 90% of all the assertions in your test files, if your smart contract is not that complex.

Conclusion

I'm really excited to see AI can be used to improve security and speed up development times in smart contracts at the Web3 sector, something that have been not possible from a long time.

If you are a smart contracts engineer and deploy a lot of smart contracts into testnet or production, give Catapulta.sh a try!