Commit a055e9f4 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat: contracts coverage in mainline ci (#13342)

Moves code coverage for smart contracts into mainline ci. CI will
now reject PRs that do not have 100% patch coverage.
parent 83c4415f
...@@ -608,32 +608,6 @@ jobs: ...@@ -608,32 +608,6 @@ jobs:
docker pull $image_name || exit 1 docker pull $image_name || exit 1
docker run $image_name <<parameters.op_component>> --version || 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: contracts-bedrock-tests:
machine: true machine: true
resource_class: ethereum-optimism/latitude-1 resource_class: ethereum-optimism/latitude-1
...@@ -641,18 +615,14 @@ jobs: ...@@ -641,18 +615,14 @@ jobs:
test_list: test_list:
description: List of test files to run description: List of test files to run
type: string type: string
test_fuzz_runs: test_command:
description: Number of fuzz runs to apply description: Test command to execute (test or coverage)
type: integer type: string
default: 512 default: test
test_invariant_runs: test_flags:
description: Number of invariant runs to apply description: Additional flags to pass to the test command
type: integer type: string
default: 32 default: ""
test_invariant_depth:
description: Depth of invariant runs
type: integer
default: 64
test_timeout: test_timeout:
description: Timeout for running tests description: Timeout for running tests
type: string type: string
...@@ -699,7 +669,7 @@ jobs: ...@@ -699,7 +669,7 @@ jobs:
TEST_FILES=$(echo "$TEST_FILES" | circleci tests split --split-by=timings) TEST_FILES=$(echo "$TEST_FILES" | circleci tests split --split-by=timings)
TEST_FILES=$(echo "$TEST_FILES" | sed 's|^test/||') TEST_FILES=$(echo "$TEST_FILES" | sed 's|^test/||')
MATCH_PATH="./test/{$(echo "$TEST_FILES" | paste -sd "," -)}" 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: environment:
FOUNDRY_PROFILE: <<parameters.test_profile>> FOUNDRY_PROFILE: <<parameters.test_profile>>
working_directory: packages/contracts-bedrock working_directory: packages/contracts-bedrock
...@@ -715,6 +685,14 @@ jobs: ...@@ -715,6 +685,14 @@ jobs:
name: Lint forge test names name: Lint forge test names
command: just lint-forge-tests-check-no-build command: just lint-forge-tests-check-no-build
working_directory: packages/contracts-bedrock 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: - save_cache:
name: Save Go build cache name: Save Go build cache
key: golang-build-cache-contracts-bedrock-tests-{{ checksum "go.sum" }} key: golang-build-cache-contracts-bedrock-tests-{{ checksum "go.sum" }}
...@@ -1214,9 +1192,6 @@ workflows: ...@@ -1214,9 +1192,6 @@ workflows:
name: contracts-bedrock-build name: contracts-bedrock-build
# Build with just core + script contracts. # Build with just core + script contracts.
build_args: --deny-warnings --skip test build_args: --deny-warnings --skip test
- contracts-bedrock-build:
name: contracts-bedrock-build-coverage
profile: cicoverage
- check-kontrol-build: - check-kontrol-build:
requires: requires:
- contracts-bedrock-build - contracts-bedrock-build
...@@ -1234,6 +1209,14 @@ workflows: ...@@ -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_list: git diff origin/develop...HEAD --name-only --diff-filter=AM -- './test/**/*.t.sol' | sed 's|packages/contracts-bedrock/||'
test_timeout: 1h test_timeout: 1h
test_profile: ciheavy 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: - contracts-bedrock-checks:
requires: requires:
- contracts-bedrock-build - contracts-bedrock-build
...@@ -1480,17 +1463,6 @@ workflows: ...@@ -1480,17 +1463,6 @@ workflows:
jobs: jobs:
- publish-contract-artifacts - 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: develop-fault-proofs:
when: when:
and: and:
......
...@@ -23,24 +23,20 @@ ignore: ...@@ -23,24 +23,20 @@ ignore:
coverage: coverage:
status: 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: project:
default: default:
informational: true informational: true
patch:
contracts:
base: auto
target: auto
threshold: 5%
informational: false
flags:
- contracts-bedrock-tests
flag_management: flag_management:
# Note: flags should have the same name as the circleci job in which they
# are uploaded.
individual_flags: individual_flags:
- name: contracts-bedrock-coverage - name: contracts-bedrock-tests
paths: paths:
- packages/contracts-bedrock/src - packages/contracts-bedrock/src
statuses:
- type: patch
target: 100%
...@@ -86,11 +86,11 @@ depth = 32 ...@@ -86,11 +86,11 @@ depth = 32
optimizer = false optimizer = false
[profile.cicoverage.fuzz] [profile.cicoverage.fuzz]
runs = 512 runs = 1
[profile.cicoverage.invariant] [profile.cicoverage.invariant]
runs = 256 runs = 1
depth = 32 depth = 1
################################################################ ################################################################
# PROFILE: CIHEAVY # # PROFILE: CIHEAVY #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment