Testing smart contracts is an essential part of the development process as it ensures that the code you write behaves as intended and is secure against various technical and economic exploits. Many different libraries are used by different teams, there are pros and cons to using each different library and in some cases, they can be used in a complementary fashion. We will cover the most popular ones among top-tier developers as well as the most commonly used ones like HardHat and Truffle.
Opinionated recommendations: Foundry for testing and Hardhat for deployments
Foundry is the hottest library in the Ethereum development landscape, it is originally built by Georgios Konstantopoulos who is one of the most highly respected developers in the entire Ethereum ecosystem. Georgios is currently the CTO at Paradigm and part of his job is building tools for developers that will be used to create the applications of the future.
Foundry is composed of two parts: Forge and Cast.
- Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- Cast: CLI for interacting with EVM smart contracts, sending transactions and getting chain data.
- Anvil: local Ethereum node, similar to Ganache or Hardhat Network.
The library is written in Rust, which is a systems-level programming language that has memory safety, borrow checking, performant concurrency, and many other features which are making it one of the favorite languages used by developers across all fronts. Many popular libraries are being written in Rust, popular compiler targets like WASM are supported by Rust, a lot of Ethereum developer tooling is built using Rust or is refactoring their infrastructure to use Rust. It is a very exciting trend in blockchain development and many developers are learning the language to be able to contribute to these cool pieces of software. The best way to get started with Rust is The Rust Book and the Rustlings repo.
- Nader Dabit’s Foundry Cheatsheet
- Brockjelmore’s Foundry walkthrough
- The Foundry Book - Community sourced documentation
- Foudry 0.2.0
- Zero Knowledge Podcast Episode 224: Foundry with Georgios Konstantopoulos
- Tweet from @andreasbigger:
- Familiarize yourself w/ Forge-cli
- Checkout some templates:
- Dive into repos using Foundry:
- Brockelmore’s testing verbosity with forge-std
- Foundry templates
- To get started, go through the official documentation
Dapptools is a suite of Ethereum focused CLI tools following the Unix design philosophy, favoring composability, configurability, and extensibility.
There are 4 key elements in Dapptools:
- dapp - All you need Ethereum development tool. Build, test, fuzz, formally verify, debug & deploy solidity contracts.
- seth - Ethereum CLI. Query contracts, send transactions, follow logs, slice & dice data.
- hevm - Testing-oriented EVM implementation. Debug, fuzz, or symbolically execute code against local or mainnet state.
- ethsign - Sign Ethereum transactions from a local Keystore or hardware wallet.
A cool innovation done by app tools was the hEVM which is an EVM implementation written in Haskell (a functional programming language) that allows to symbolically execute Solidity code and formally verify the results of the resulting bytecode (opcode operations). This feature was later adopted by Foundry, including many others that were first provided by Dapptools.
Truffle Suite is a suite of tools developed by Consensys to locally test smart contracts by deploying them on a local instance of the Ethereum blockchain, mocking user addresses using the Ganache library, writing tests using Truffle, and creating on-chain data pipelines for user interfaces using Drizzle. It was one of the first complete Ethereum developer tooling ecosystems that were released, but they’ve fallen out of favor in recent years as libraries like Hardhat overtook it.