From dca2d15c2902c05c7c47bfd3ada64fa58943f971 Mon Sep 17 00:00:00 2001 From: Radomir Sebek Date: Thu, 19 Jun 2025 12:56:55 +0200 Subject: [PATCH 1/4] test: optimize and add coverage step to ./yml flow --- .github/workflows/checks.yml | 12 ++++++++++++ .solcover.js | 8 ++++++++ hardhat.node.config.ts | 2 +- package.json | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 8d7c4ce5..86e66f08 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + workflow_dispatch: concurrency: group: checks-${{ github.ref }} @@ -45,3 +46,14 @@ jobs: - name: Run tests run: npm run test:parallel + + - name: Generate test coverage + run: npm run coverage + + - name: Upload artifact of tests + if: '!cancelled()' + uses: actions/upload-artifact@v4 + with: + name: solidity-test-coverage + path: ./coverage/ + retention-days: 7 diff --git a/.solcover.js b/.solcover.js index 72ae67cc..f70c3559 100644 --- a/.solcover.js +++ b/.solcover.js @@ -3,6 +3,9 @@ module.exports = { testCommand: 'npm run test', compileCommand: 'npm run compile', configureYulOptimizer: true, + measureStatementCoverage: true, + measureFunctionCoverage: true, + measureBranchCoverage: true, skipFiles: [ 'constants', 'errors', @@ -11,4 +14,9 @@ module.exports = { 'utils', 'Token.sol', ], + istanbulFolder: './coverage', + istanbulReporter: [ + 'html', + 'text' + ] }; diff --git a/hardhat.node.config.ts b/hardhat.node.config.ts index 6bead10f..48e34fcd 100644 --- a/hardhat.node.config.ts +++ b/hardhat.node.config.ts @@ -65,7 +65,7 @@ const config: HardhatUserConfig = { }, }, }, - viaIR: process.env.COVERAGE_REPORT ? false : true, + viaIR: true, }, }, ], diff --git a/package.json b/package.json index d1334136..34c94ea7 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "clean": "hardhat clean", "compile:size": "hardhat size-contracts", "compile": "hardhat compile --config hardhat.node.config.ts", - "coverage": "cross-env COVERAGE_REPORT=true HARDHAT_DEPLOY_FIXTURE=true hardhat coverage --network hardhat --solcoverjs ./.solcover.js --temp artifacts --testfiles './test/**/*.test.ts'", + "coverage": "cross-env SOLIDITY_COVERAGE=true HARDHAT_DEPLOY_FIXTURE=true hardhat coverage --solcoverjs ./.solcover.js --testfiles './test/**/*.test.ts'", "deploy:base_sepolia_dev": "hardhat deploy --network base_sepolia_dev", "deploy:base_sepolia_stable_dev_prod": "hardhat deploy --network base_sepolia_stable_dev_prod", "deploy:base_sepolia_stable_dev_staging": "hardhat deploy --network base_sepolia_stable_dev_staging", From 51e3bf609c0d802a94d396b0153249a00dcc92dc Mon Sep 17 00:00:00 2001 From: Radomir Sebek Date: Thu, 19 Jun 2025 13:11:11 +0200 Subject: [PATCH 2/4] seperate coverage into dedicated job --- .github/workflows/checks.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 86e66f08..00903e73 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -20,6 +20,9 @@ jobs: - name: Set up environment uses: ./.github/actions/setup + - name: Build typechain for linting + run: npx hardhat typechain + - name: Run Solidity and Typescript linters run: npm run lint @@ -47,6 +50,13 @@ jobs: - name: Run tests run: npm run test:parallel + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up environment + uses: ./.github/actions/setup - name: Generate test coverage run: npm run coverage From 857862b2cf60880d21af418ab39d4acbc73d7166 Mon Sep 17 00:00:00 2001 From: Radomir Sebek Date: Thu, 19 Jun 2025 13:26:41 +0200 Subject: [PATCH 3/4] refactoring into seperate .yml --- .github/workflows/checks.yml | 19 ------------------ .github/workflows/coverage.yml | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 00903e73..19302e93 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -4,7 +4,6 @@ on: pull_request: branches: - main - workflow_dispatch: concurrency: group: checks-${{ github.ref }} @@ -49,21 +48,3 @@ jobs: - name: Run tests run: npm run test:parallel - - coverage: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Set up environment - uses: ./.github/actions/setup - - name: Generate test coverage - run: npm run coverage - - - name: Upload artifact of tests - if: '!cancelled()' - uses: actions/upload-artifact@v4 - with: - name: solidity-test-coverage - path: ./coverage/ - retention-days: 7 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..079ce2b4 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,35 @@ +name: solidity-test-coverage + +on: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: solidity-test-coverage-${{ github.ref }} + cancel-in-progress: true + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up environment + uses: ./.github/actions/setup + + - name: Generate test coverage + run: npm run coverage + + - name: Upload artifact of tests + if: '!cancelled()' + uses: actions/upload-artifact@v4 + with: + name: solidity-test-coverage + path: ./coverage/ + retention-days: 7 From b469c584b1768bb7b004009261fd839593015265 Mon Sep 17 00:00:00 2001 From: Radomir Sebek Date: Thu, 19 Jun 2025 13:42:20 +0200 Subject: [PATCH 4/4] final fix --- .github/workflows/coverage.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 079ce2b4..8bf51903 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,9 +1,6 @@ name: solidity-test-coverage on: - pull_request: - branches: - - main push: branches: - main