From 4e37790e1fbda6d4759ff87d2ff12ba775572cc7 Mon Sep 17 00:00:00 2001 From: cairo Date: Mon, 24 Jun 2024 19:29:18 -0400 Subject: [PATCH 1/9] add foundry to coverage --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2969af0c921..966bf4677d7 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "compile": "hardhat compile", "compile:harnesses": "env SRC=./certora/harnesses hardhat compile", - "coverage": "env COVERAGE=true hardhat coverage", + "coverage": "env COVERAGE=true hardhat coverage && forge coverage --report lcov --ir-minimum", "docs": "npm run prepare-docs && oz-docs", "docs:watch": "oz-docs watch contracts docs/templates docs/config.js", "prepare": "git config --local core.hooksPath .githooks", From d8fd9d5ce86f8166cef9aa5c8e88f73516570002 Mon Sep 17 00:00:00 2001 From: cairo Date: Tue, 25 Jun 2024 11:58:36 -0400 Subject: [PATCH 2/9] remove mocks and tests from foundry coverage --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 966bf4677d7..627b94288d4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "compile": "hardhat compile", "compile:harnesses": "env SRC=./certora/harnesses hardhat compile", - "coverage": "env COVERAGE=true hardhat coverage && forge coverage --report lcov --ir-minimum", + "coverage": "env COVERAGE=true hardhat coverage && forge coverage --report lcov --ir-minimum && lcov -o lcov.info --remove lcov.info --rc lcov_branch_coverage=1 --rc lcov_function_coverage=1 'test/*' 'contracts/mocks/*'", "docs": "npm run prepare-docs && oz-docs", "docs:watch": "oz-docs watch contracts docs/templates docs/config.js", "prepare": "git config --local core.hooksPath .githooks", From 06029fbc098d51b63c643f251a68ccdb10b62f48 Mon Sep 17 00:00:00 2001 From: cairo Date: Tue, 25 Jun 2024 12:49:59 -0400 Subject: [PATCH 3/9] install lcov and remove ir pipeline --- .github/workflows/checks.yml | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index c280885632c..7d997f14588 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -91,6 +91,8 @@ jobs: - uses: actions/checkout@v4 - name: Set up environment uses: ./.github/actions/setup + - name: Install LCOV + run: sudo apt-get install lcov - name: Run coverage run: npm run coverage - uses: codecov/codecov-action@v4 diff --git a/package.json b/package.json index 627b94288d4..7bc8929469b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "compile": "hardhat compile", "compile:harnesses": "env SRC=./certora/harnesses hardhat compile", - "coverage": "env COVERAGE=true hardhat coverage && forge coverage --report lcov --ir-minimum && lcov -o lcov.info --remove lcov.info --rc lcov_branch_coverage=1 --rc lcov_function_coverage=1 'test/*' 'contracts/mocks/*'", + "coverage": "env COVERAGE=true hardhat coverage && forge coverage --report lcov && lcov -o lcov.info --remove lcov.info --rc lcov_branch_coverage=1 --rc lcov_function_coverage=1 'test/*' 'contracts/mocks/*'", "docs": "npm run prepare-docs && oz-docs", "docs:watch": "oz-docs watch contracts docs/templates docs/config.js", "prepare": "git config --local core.hooksPath .githooks", From 5c503c170e742cd9db7f2c877ab8595e7fad9931 Mon Sep 17 00:00:00 2001 From: cairo Date: Wed, 26 Jun 2024 15:01:01 -0400 Subject: [PATCH 4/9] reduce fuzzing runs and remove zero hits for it --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7bc8929469b..93a7dde3e26 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "compile": "hardhat compile", "compile:harnesses": "env SRC=./certora/harnesses hardhat compile", - "coverage": "env COVERAGE=true hardhat coverage && forge coverage --report lcov && lcov -o lcov.info --remove lcov.info --rc lcov_branch_coverage=1 --rc lcov_function_coverage=1 'test/*' 'contracts/mocks/*'", + "coverage": "env COVERAGE=true hardhat coverage && FOUNDRY_FUZZ_RUNS=10 forge coverage --report lcov && lcov -o lcov.info --remove lcov.info 'test/*' 'contracts/mocks/*' && awk '!/,0/' lcov.info > temp && mv temp lcov.info", "docs": "npm run prepare-docs && oz-docs", "docs:watch": "oz-docs watch contracts docs/templates docs/config.js", "prepare": "git config --local core.hooksPath .githooks", From 9dc12c9af92aac26c6b8fec9fd3ccabf3b310930 Mon Sep 17 00:00:00 2001 From: cairo Date: Thu, 27 Jun 2024 14:17:35 +0200 Subject: [PATCH 5/9] coverage script --- package.json | 2 +- scripts/checks/coverage.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 scripts/checks/coverage.sh diff --git a/package.json b/package.json index 93a7dde3e26..f5ab048374c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "compile": "hardhat compile", "compile:harnesses": "env SRC=./certora/harnesses hardhat compile", - "coverage": "env COVERAGE=true hardhat coverage && FOUNDRY_FUZZ_RUNS=10 forge coverage --report lcov && lcov -o lcov.info --remove lcov.info 'test/*' 'contracts/mocks/*' && awk '!/,0/' lcov.info > temp && mv temp lcov.info", + "coverage": "scripts/checks/coverage.sh", "docs": "npm run prepare-docs && oz-docs", "docs:watch": "oz-docs watch contracts docs/templates docs/config.js", "prepare": "git config --local core.hooksPath .githooks", diff --git a/scripts/checks/coverage.sh b/scripts/checks/coverage.sh new file mode 100755 index 00000000000..19f3344f045 --- /dev/null +++ b/scripts/checks/coverage.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +export COVERAGE=true +export FOUNDRY_FUZZ_RUNS=10 + +# Hardhat coverage +npx hardhat coverage + +# Foundry coverage +forge coverage --report lcov +# Remove test and mock data +lcov --rc derive_function_end_line=0 -o lcov.info --remove lcov.info 'test/*' 'contracts/mocks/*' +# Remove zero hits +awk '!/,0/' lcov.info > temp && mv temp lcov.info + +# Reports are then uploaded to Codecov automatically by workflow, and merged. From 9fe61deb30ab22e6ae3526a3644aa0d541a2fc3b Mon Sep 17 00:00:00 2001 From: cairo Date: Fri, 28 Jun 2024 10:55:42 +0200 Subject: [PATCH 6/9] apply suggestions from code review Co-authored-by: Hadrien Croubois --- scripts/checks/coverage.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/checks/coverage.sh b/scripts/checks/coverage.sh index 19f3344f045..c1a898b34ab 100755 --- a/scripts/checks/coverage.sh +++ b/scripts/checks/coverage.sh @@ -1,16 +1,20 @@ #!/usr/bin/env bash +set -euo pipefail + export COVERAGE=true export FOUNDRY_FUZZ_RUNS=10 # Hardhat coverage -npx hardhat coverage +hardhat coverage -# Foundry coverage -forge coverage --report lcov -# Remove test and mock data -lcov --rc derive_function_end_line=0 -o lcov.info --remove lcov.info 'test/*' 'contracts/mocks/*' -# Remove zero hits -awk '!/,0/' lcov.info > temp && mv temp lcov.info +if [ "${CI:-"false"}" == "true" ]; then + # Foundry coverage + forge coverage --report lcov + # Remove test and mock data + lcov --rc derive_function_end_line=0 -o lcov.info --remove lcov.info 'test/*' 'contracts/mocks/*' + # Remove zero hits + sed -i '/,0/d' lcov.info +fi # Reports are then uploaded to Codecov automatically by workflow, and merged. From bf731195b685ff873b821de741c61d784a7fb958 Mon Sep 17 00:00:00 2001 From: cairo Date: Fri, 28 Jun 2024 10:57:01 +0200 Subject: [PATCH 7/9] remove lcov and use codecov ignore --- .codecov.yml | 3 +++ .github/workflows/checks.yml | 2 -- scripts/checks/coverage.sh | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 9455306a4d1..fecc5dd7e97 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -10,3 +10,6 @@ coverage: project: default: threshold: 1% +ignore: + - "test/*" + - "contracts/mocks/*" diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 7d997f14588..c280885632c 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -91,8 +91,6 @@ jobs: - uses: actions/checkout@v4 - name: Set up environment uses: ./.github/actions/setup - - name: Install LCOV - run: sudo apt-get install lcov - name: Run coverage run: npm run coverage - uses: codecov/codecov-action@v4 diff --git a/scripts/checks/coverage.sh b/scripts/checks/coverage.sh index c1a898b34ab..12e2323547a 100755 --- a/scripts/checks/coverage.sh +++ b/scripts/checks/coverage.sh @@ -11,8 +11,6 @@ hardhat coverage if [ "${CI:-"false"}" == "true" ]; then # Foundry coverage forge coverage --report lcov - # Remove test and mock data - lcov --rc derive_function_end_line=0 -o lcov.info --remove lcov.info 'test/*' 'contracts/mocks/*' # Remove zero hits sed -i '/,0/d' lcov.info fi From 10085558e2063d71035305d4aed55cad3f051287 Mon Sep 17 00:00:00 2001 From: cairo Date: Fri, 28 Jun 2024 11:19:11 +0200 Subject: [PATCH 8/9] fix ignore recursive --- .codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index fecc5dd7e97..6b3870a3327 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -11,5 +11,5 @@ coverage: default: threshold: 1% ignore: - - "test/*" - - "contracts/mocks/*" + - "test/**/*" + - "contracts/mocks/**/*" From 76c935133df8d828fc8b371b1b26ff7500c24230 Mon Sep 17 00:00:00 2001 From: cairo Date: Fri, 28 Jun 2024 11:43:21 +0200 Subject: [PATCH 9/9] faster ignore pattern --- .codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 6b3870a3327..5bee9146ab9 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -11,5 +11,5 @@ coverage: default: threshold: 1% ignore: - - "test/**/*" - - "contracts/mocks/**/*" + - "test" + - "contracts/mocks"