From 1d088eb4016848d6e9683f538d385877e846fa42 Mon Sep 17 00:00:00 2001 From: Kelvin Fichter Date: Tue, 10 Dec 2024 16:17:09 -0500 Subject: [PATCH] feat: contracts coverage in mainline ci Moves code coverage for smart contracts into mainline ci. CI will now reject PRs that do not have 100% patch coverage. --- .circleci/config.yml | 78 ++++++++----------------- codecov.yml | 22 +++---- packages/contracts-bedrock/foundry.toml | 6 +- 3 files changed, 37 insertions(+), 69 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 54420f0b4b1c..8d2b56bf2254 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -608,32 +608,6 @@ jobs: docker pull $image_name || exit 1 docker run $image_name <> --version || exit 1 - contracts-bedrock-coverage: - docker: - - 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 @@ -641,18 +615,14 @@ jobs: 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 @@ -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 <> <> --match-path "$MATCH_PATH" environment: FOUNDRY_PROFILE: <> working_directory: packages/contracts-bedrock @@ -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: ["<>", "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" }} @@ -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 @@ -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 @@ -1480,17 +1463,6 @@ workflows: jobs: - publish-contract-artifacts - develop-forge-coverage: - when: - and: - - or: - - equal: ["develop", <>] - - equal: [true, <>] - - not: - equal: [scheduled_pipeline, << pipeline.trigger_source >>] - jobs: - - contracts-bedrock-coverage - develop-fault-proofs: when: and: diff --git a/codecov.yml b/codecov.yml index 8fd1bc517731..9f41fd222787 100644 --- a/codecov.yml +++ b/codecov.yml @@ -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% diff --git a/packages/contracts-bedrock/foundry.toml b/packages/contracts-bedrock/foundry.toml index 181391e7c49e..b99237116a76 100644 --- a/packages/contracts-bedrock/foundry.toml +++ b/packages/contracts-bedrock/foundry.toml @@ -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 #