Foundry forge coverage

Visual line coverage report with LCOV

forge coverage lcov report

If you run “forge coverage” in a foundry project, you’ll get a table showing how much of your lines and branches are covered.

foundry forge coverage

If you want to see visually which lines and branches are or are not covered, use the following steps

Instructions to get line visual coverage in foundry

1. Install genhtml

brew install genhtml

2. Create a coverage directory in your foundry project

mkdir coverage

3. Run the following command

forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage

4. Open the following file

coverage/index.html

And you’ll be able to see a coverage report like what you see at the top of the page.

No available formula with the name “genhtml”. Did you mean ekhtml?

If you get this error, do

brew install ekhtml

and it will install genhtml.

Credits

This tutorial was created by Matteo Vendittoli, a student at the RareSkills blockchain bootcamp.

Addendum: Visual line coverage in Visual Studio Code

It is also possible to view line coverage directly inside Visual Studio Code. Credit to 0xasp_ on Twitter for sharing this with us (original tweet).

1. Install the Coverage Gutters extension in VSCode

2. Generate the coverage report

forge coverage --report lcov

3. Open the Command Palette

Pick display coverage report

Originally Published Feb 8, 2023

20 Common Solidity Beginner Mistakes

20 Common Solidity Beginner Mistakes Our intent is not to be patronizing towards developers early in their journey with this article. Having reviewed code from numerous Solidity developers, we’ve seen some mistakes occur more frequently and we list those here. By no means is this an exhaustive list of mistakes a Solidity developer can make. […]

Smart Contract Foundry Upgrades with the OpenZeppelin Plugin

Smart Contract Foundry Upgrades with the OpenZeppelin Plugin Upgrading a smart contract is a multistep and error-prone process, so to minimize the chances of human error, it is desirable to use a tool that automates the procedure as much as possible. Therefore, the OpenZeppelin Upgrade Plugin streamlines deploying, upgrading and managing smart contracts built with Foundry or […]

UUPS: Universal Upgradeable Proxy Standard (ERC-1822)

UUPS: Universal Upgradeable Proxy Standard (ERC-1822) The UUPS pattern is a proxy pattern where the upgrade function resides in the implementation contract, but changes the implementation address stored in the proxy contract via a delegatecall from the proxy. The high level mechanism is shown in the animation below: Similar to the Transparent Upgradeable Proxy, the […]

Try Catch and all the ways Solidity can revert

Try Catch and all the ways Solidity can revert This article describes all the kinds of errors that can happen when a smart contract is called, and how the Solidity Try / Catch block responds (or fails to respond) to each of them. To understand how Try / Catch works in Solidity, we must understand […]

Featured Jobs