Skip to content

Commit

Permalink
chore: add template
Browse files Browse the repository at this point in the history
  • Loading branch information
PierrickGT committed Mar 26, 2024
1 parent 3124f59 commit e7cfad5
Show file tree
Hide file tree
Showing 24 changed files with 2,787 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Localhost RPC URL
export LOCALHOST_RPC_URL=http://127.0.0.1:8545

# Mainnet RPC URLs
export MAINNET_RPC_URL=

# Testnet RPC URLs
export SEPOLIA_RPC_URL=

# Used for verifying contracts on Etherscan
export ETHERSCAN_API_KEY=
40 changes: 40 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Forge Coverage

on:
push:
branches:
- main
pull_request:

permissions: write-all

jobs:
check:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install lcov
uses: hrishikesh-kadam/setup-lcov@v1

- name: Run coverage
env:
MNEMONIC: ${{ secrets.MNEMONIC_FOR_TESTS }}
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
run: make coverage profile=ci
id: coverage

- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v3
with:
coverage-files: lcov.info
artifact-name: code-coverage-report
minimum-coverage: 95
github-token: ${{ secrets.GITHUB_TOKEN }}
update-comment: true
35 changes: 35 additions & 0 deletions .github/workflows/test-fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# name: Forge Fuzz Tests
#
# on:
# push:
# branches:
# - main
# pull_request:
#
# permissions: write-all
#
# jobs:
# check:
# name: Fuzz Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: recursive
#
# - name: Install Foundry
# uses: foundry-rs/foundry-toolchain@v1
#
# - name: Run Forge build
# run: |
# forge --version
# make sizes
# id: build
#
# - name: Run Forge fuzz tests
# run: make fuzz profile=ci
# env:
# # make fuzzing semi-deterministic to avoid noisy gas cost estimation
# # due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
# FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
# MNEMONIC: ${{ secrets.MNEMONIC_FOR_TESTS }}
48 changes: 48 additions & 0 deletions .github/workflows/test-gas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Forge Tests Gas Report

on:
push:
branches:
- main
pull_request:

permissions: write-all

jobs:
check:
name: Gas report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run Forge build
run: |
forge --version
make sizes
id: build

- name: Run Forge tests with gas report
run: make gas-report profile=ci
env:
# make fuzzing semi-deterministic to avoid noisy gas cost estimation
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
MNEMONIC: ${{ secrets.MNEMONIC_FOR_TESTS }}
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}

- name: Compare gas reports
uses: Rubilmax/foundry-gas-diff@v3.16
id: gas_diff

- name: Add gas diff to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: marocchino/sticky-pull-request-comment@v2
with:
# delete the comment in case changes no longer impact gas costs
delete: ${{ !steps.gas_diff.outputs.markdown }}
message: ${{ steps.gas_diff.outputs.markdown }}
30 changes: 30 additions & 0 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# name: Forge Integration Tests
#
# on:
# push:
# branches:
# - main
# pull_request:
#
# permissions: write-all
#
# jobs:
# check:
# name: Integration Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: recursive
#
# - name: Install Foundry
# uses: foundry-rs/foundry-toolchain@v1
#
# - name: Run Forge build
# run: |
# forge --version
# make sizes
# id: build
#
# - name: Run Forge integration tests
# run: make integration profile=ci
35 changes: 35 additions & 0 deletions .github/workflows/test-invariant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# name: Forge Invariant Tests
#
# on:
# push:
# branches:
# - main
# pull_request:
#
# permissions: write-all
#
# jobs:
# check:
# name: Invariant Tests
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: recursive
#
# - name: Install Foundry
# uses: foundry-rs/foundry-toolchain@v1
#
# - name: Run Forge build
# run: |
# forge --version
# make sizes
# id: build
#
# - name: Run Forge invariant tests
# run: make invariant profile=ci
# env:
# # make fuzzing semi-deterministic to avoid noisy gas cost estimation
# # due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds)
# FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }}
# MNEMONIC: ${{ secrets.MNEMONIC_FOR_TESTS }}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Coverage files
coverage/
lcov.info

# Docs
docs/

# Dotenv file
.env

# Mac OS files
.DS_Store

# NPM modules
node_modules
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint-staged && npm test
8 changes: 8 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"*.{json,md,sol,yml}": [
"npm run prettier"
],
"*.sol": [
"npm run solhint"
]
}
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"bracketSpacing": true,
"compiler": "0.8.25",
"parser": "solidity-parse",
"printWidth": 120,
"tabWidth": 4,
}
}
]
}

32 changes: 32 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"extends": ["solhint:recommended"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"code-complexity": ["warn", 10],
"compiler-version": ["error", "0.8.25"],
"comprehensive-interface": "off",
"const-name-snakecase": "off",
"func-name-mixedcase": "off",
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
],
"function-max-lines": ["warn", 100],
"immutable-vars-naming": "off",
"imports-on-top": "error",
"max-line-length": ["warn", 120],
"no-empty-blocks": "off",
"no-inline-assembly": "off",
"not-rely-on-time": "off",
"private-vars-leading-underscore": [
"warn",
{
"strict": true
}
],
"visibility-modifier-order": "error"
}
}
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# include .env file and export its env vars
# (-include to ignore error if it does not exist)
-include .env

# dapp deps
update:; forge update

# Deployment helpers
deploy-local :; FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --rpc-url localhost --broadcast -v
deploy-sepolia :; FOUNDRY_PROFILE=production forge script script/Deploy.s.sol --rpc-url sepolia --broadcast -vvv

# Run slither
slither :; FOUNDRY_PROFILE=production forge build --build-info --skip '*/test/**' --skip '*/script/**' --force && slither --compile-force-framework foundry --ignore-compile --sarif results.sarif --config-file slither.config.json .

# Common tasks
profile ?=default

build:
@./build.sh -p production

test:
@./test.sh -p $(profile)

fuzz:
@./test.sh -t testFuzz -p $(profile)

integration:
@./test.sh -d test/integration -p $(profile)

invariant:
@./test.sh -d test/invariant -p $(profile)

coverage:
FOUNDRY_PROFILE=$(profile) forge coverage --no-match-path 'test/invariant/**/*.sol' --report lcov && lcov --extract lcov.info -o lcov.info 'src/*' && genhtml lcov.info -o coverage

gas-report:
FOUNDRY_PROFILE=$(profile) forge test --gas-report > gasreport.ansi

sizes:
@./build.sh -p production -s

clean:
forge clean && rm -rf ./abi && rm -rf ./bytecode && rm -rf ./types

Loading

0 comments on commit e7cfad5

Please sign in to comment.