/zk-face-auth-contracts

Primary LanguageSolidityGNU General Public License v3.0GPL-3.0

Hardhat Foundry Template

Highly opinionated template for smart contract development.

Combines hardhat and foundry testing frameworks to take advantage of coverage and fuzzing capabiltiies, along with their native tools.

Getting Started

Requirements

The following will need to be installed. Please follow the links and instructions.

  • Foundry
  • Node >= 14
  • yarn or npm >= 7

Quickstart

  1. Install dependencies

Once you've cloned and entered into your repository, you need to install the necessary dependencies. In order to do so, simply run:

yarn install
forge install
  1. Build
forge build
  1. Test
forge test -vvv
# or
npx hardhat test

For more information on how to use Foundry, check out the Foundry Github Repository or type forge help in your terminal.

Features

GitHub Templates

The template comes with a list of templates:

GitHub Actions

  • CI

    • Lint
    • Test
    • Coverage
      • Show coverage report in the workflow summary
      • Set secrets.CODECOV_TOKEN on GitHub for visualizing coverage report to codecov.io (NOTE: the secrets is not required for public repo)
  • Static Analyzer (Slither)

    • To enable the upload of the SARIF file to GitHub, Requires to be public repo or GitHub Enterprise Cloud user.

Install Libraries

  • Install libraries with Foundry which work with Hardhat.
forge install openzeppelin/openzeppelin-contracts # just an example

And then update remappings in foundry.toml.

remappings = [
    "@openzeppelin/=lib/openzeppelin-contracts/",
]

This will allow you to import libraries like this:

// Instead of import "lib/openzeppelin-contracts/token/ERC20/ERC20.sol";
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

Generate documentation

  • Generates and builds an mdbook from Solidity source files.
forge doc # generates docs in ./docs
forge doc --serve # generates docs and serves them on localhost:3000

Update Gas Snapshots

forge snapshot

Coverage

forge coverage

Custom Tasks

  • Use Hardhat's task framework
npx hardhat example

Utility Commands

  • Use cast command which is a swiss army knife for smart contract development. Type cast --help for more information.

Tracing a tx

Runs a published transaction in a local environment and prints the trace.

cast run <txhash> --rpc-url <rpc-url>

Deplyment

See deployment

Resources

For more infomation on how to use Foundry features, refer to:

Acknowledgements