Commit f33d11e6 authored by Elena Gesheva's avatar Elena Gesheva Committed by GitHub

Add optional gas reporting to unit test run (#626)

* 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
parent 2d63f2f9
......@@ -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
......@@ -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
......
......@@ -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: {
......@@ -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
......@@ -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"
}
......
......@@ -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: {
......@@ -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 (
......
......@@ -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",
......
This diff is collapsed.
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