Skip to content

Commit

Permalink
feat: contracts coverage in mainline ci (#13342)
Browse files Browse the repository at this point in the history
Moves code coverage for smart contracts into mainline ci. CI will
now reject PRs that do not have 100% patch coverage.
  • Loading branch information
smartcontracts authored Dec 11, 2024
1 parent 83c4415 commit a055e9f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 69 deletions.
78 changes: 25 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -608,51 +608,21 @@ jobs:
docker pull $image_name || exit 1
docker run $image_name <<parameters.op_component>> --version || exit 1
contracts-bedrock-coverage:
docker:
- image: <<pipeline.parameters.ci_builder_image>>
resource_class: xlarge
steps:
- checkout
- install-contracts-dependencies
- check-changed:
patterns: contracts-bedrock,op-node
- run:
name: print forge version
command: forge --version
working_directory: packages/contracts-bedrock
# We do not use the pre-built contracts becuase forge coverage uses different optimizer settings
- run:
name: test and generate coverage
command: just coverage-lcov
no_output_timeout: 18m
environment:
FOUNDRY_PROFILE: cicoverage
working_directory: packages/contracts-bedrock
- codecov/upload:
disable_search: true
files: ./packages/contracts-bedrock/lcov.info
flags: contracts-bedrock-tests

contracts-bedrock-tests:
machine: true
resource_class: ethereum-optimism/latitude-1
parameters:
test_list:
description: List of test files to run
type: string
test_fuzz_runs:
description: Number of fuzz runs to apply
type: integer
default: 512
test_invariant_runs:
description: Number of invariant runs to apply
type: integer
default: 32
test_invariant_depth:
description: Depth of invariant runs
type: integer
default: 64
test_command:
description: Test command to execute (test or coverage)
type: string
default: test
test_flags:
description: Additional flags to pass to the test command
type: string
default: ""
test_timeout:
description: Timeout for running tests
type: string
Expand Down Expand Up @@ -699,7 +669,7 @@ jobs:
TEST_FILES=$(echo "$TEST_FILES" | circleci tests split --split-by=timings)
TEST_FILES=$(echo "$TEST_FILES" | sed 's|^test/||')
MATCH_PATH="./test/{$(echo "$TEST_FILES" | paste -sd "," -)}"
forge test --match-path "$MATCH_PATH"
forge <<parameters.test_command>> <<parameters.test_flags>> --match-path "$MATCH_PATH"
environment:
FOUNDRY_PROFILE: <<parameters.test_profile>>
working_directory: packages/contracts-bedrock
Expand All @@ -715,6 +685,14 @@ jobs:
name: Lint forge test names
command: just lint-forge-tests-check-no-build
working_directory: packages/contracts-bedrock
- when:
condition:
equal: ["<<parameters.test_command>>", "coverage"]
steps:
- codecov/upload:
disable_search: true
files: ./packages/contracts-bedrock/lcov.info
flags: contracts-bedrock-tests
- save_cache:
name: Save Go build cache
key: golang-build-cache-contracts-bedrock-tests-{{ checksum "go.sum" }}
Expand Down Expand Up @@ -1214,9 +1192,6 @@ workflows:
name: contracts-bedrock-build
# Build with just core + script contracts.
build_args: --deny-warnings --skip test
- contracts-bedrock-build:
name: contracts-bedrock-build-coverage
profile: cicoverage
- check-kontrol-build:
requires:
- contracts-bedrock-build
Expand All @@ -1234,6 +1209,14 @@ workflows:
test_list: git diff origin/develop...HEAD --name-only --diff-filter=AM -- './test/**/*.t.sol' | sed 's|packages/contracts-bedrock/||'
test_timeout: 1h
test_profile: ciheavy
- contracts-bedrock-tests:
# Generate coverage reports.
name: contracts-bedrock-coverage
test_list: find test -name "*.t.sol"
test_command: coverage
test_flags: --report lcov
test_timeout: 1h
test_profile: cicoverage
- contracts-bedrock-checks:
requires:
- contracts-bedrock-build
Expand Down Expand Up @@ -1480,17 +1463,6 @@ workflows:
jobs:
- publish-contract-artifacts

develop-forge-coverage:
when:
and:
- or:
- equal: ["develop", <<pipeline.git.branch>>]
- equal: [true, <<pipeline.parameters.contracts_coverage_dispatch>>]
- not:
equal: [scheduled_pipeline, << pipeline.trigger_source >>]
jobs:
- contracts-bedrock-coverage

develop-fault-proofs:
when:
and:
Expand Down
22 changes: 9 additions & 13 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ ignore:

coverage:
status:
patch:
default:
target: auto # target coverage is equal to the PR base
threshold: 0% # coverage is not allowed to reduce vs. the PR base
base: auto
informational: true
enabled: true
project:
default:
informational: true
patch:
contracts:
base: auto
target: auto
threshold: 5%
informational: false
flags:
- contracts-bedrock-tests

flag_management:
# Note: flags should have the same name as the circleci job in which they
# are uploaded.
individual_flags:
- name: contracts-bedrock-coverage
- name: contracts-bedrock-tests
paths:
- packages/contracts-bedrock/src
statuses:
- type: patch
target: 100%
6 changes: 3 additions & 3 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ depth = 32
optimizer = false

[profile.cicoverage.fuzz]
runs = 512
runs = 1

[profile.cicoverage.invariant]
runs = 256
depth = 32
runs = 1
depth = 1

################################################################
# PROFILE: CIHEAVY #
Expand Down

0 comments on commit a055e9f

Please sign in to comment.