Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Add optional gas reporting to unit test run (ethereum-optimism#626)
Browse files Browse the repository at this point in the history
* Add hardhat-gas-reporter package and base config

* Generate an output file from gas reporter when run in CI
Selectively enable gas reporter based on ENABLE_GAS_REPORT env var

* Add gas reports to integration tests
  • Loading branch information
elenadimitrova authored Apr 28, 2021
1 parent af7d34e commit 7eb8a6e
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ jobs:
yarn build:contracts
yarn build:contracts:ovm
yarn test:integration
env:
FORCE_COLOR: 1
ENABLE_GAS_REPORT: 1
- name: Print gas report
run: cat integration-tests/gas-report.txt
6 changes: 5 additions & 1 deletion .github/workflows/ts-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ jobs:

- name: Test
run: yarn test:ci

env:
FORCE_COLOR: 1
ENABLE_GAS_REPORT: 1
- name: Print gas report
run: cat packages/contracts/gas-report.txt
lint:
name: Linting
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { HardhatUserConfig } from 'hardhat/types'
// Hardhat plugins
import '@nomiclabs/hardhat-ethers'
import '@eth-optimism/hardhat-ovm'
import 'hardhat-gas-reporter'

const enableGasReport = !!process.env.ENABLE_GAS_REPORT

const config: HardhatUserConfig = {
mocha: {
Expand All @@ -18,6 +21,12 @@ const config: HardhatUserConfig = {
ovm: {
solcVersion: '0.7.6',
},
gasReporter: {
enabled: enableGasReport,
currency: 'USD',
gasPrice: 100,
outputFile: process.env.CI ? 'gas-report.txt' : undefined,
},
}

export default config
1 change: 1 addition & 0 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"ethereum-waffle": "^3.3.0",
"ethers": "^5.0.32",
"hardhat": "^2.1.2",
"hardhat-gas-reporter": "^1.0.4",
"mocha": "^8.3.1",
"rimraf": "^3.0.2"
}
Expand Down
9 changes: 9 additions & 0 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import 'hardhat-deploy'
import '@typechain/hardhat'
import '@eth-optimism/hardhat-ovm'
import './tasks/deploy'
import 'hardhat-gas-reporter'

// Load environment variables from .env
dotenv.config()

const enableGasReport = !!process.env.ENABLE_GAS_REPORT

const config: HardhatUserConfig = {
networks: {
hardhat: {
Expand Down Expand Up @@ -64,6 +67,12 @@ const config: HardhatUserConfig = {
default: 0,
},
},
gasReporter: {
enabled: enableGasReport,
currency: 'USD',
gasPrice: 100,
outputFile: process.env.CI ? 'gas-report.txt' : undefined,
},
}

if (
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"ethers": "^5.0.31",
"hardhat": "^2.0.8",
"hardhat-deploy": "^0.7.4",
"hardhat-gas-reporter": "^1.0.4",
"lodash": "^4.17.20",
"merkle-patricia-tree": "^4.0.0",
"merkletreejs": "^0.2.12",
Expand Down
Loading

0 comments on commit 7eb8a6e

Please sign in to comment.