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: ...@@ -42,3 +42,8 @@ jobs:
yarn build:contracts yarn build:contracts
yarn build:contracts:ovm yarn build:contracts:ovm
yarn test:integration 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: ...@@ -54,7 +54,11 @@ jobs:
- name: Test - name: Test
run: yarn test:ci run: yarn test:ci
env:
FORCE_COLOR: 1
ENABLE_GAS_REPORT: 1
- name: Print gas report
run: cat packages/contracts/gas-report.txt
lint: lint:
name: Linting name: Linting
runs-on: ubuntu-latest runs-on: ubuntu-latest
......
...@@ -3,6 +3,9 @@ import { HardhatUserConfig } from 'hardhat/types' ...@@ -3,6 +3,9 @@ import { HardhatUserConfig } from 'hardhat/types'
// Hardhat plugins // Hardhat plugins
import '@nomiclabs/hardhat-ethers' import '@nomiclabs/hardhat-ethers'
import '@eth-optimism/hardhat-ovm' import '@eth-optimism/hardhat-ovm'
import 'hardhat-gas-reporter'
const enableGasReport = !!process.env.ENABLE_GAS_REPORT
const config: HardhatUserConfig = { const config: HardhatUserConfig = {
mocha: { mocha: {
...@@ -18,6 +21,12 @@ const config: HardhatUserConfig = { ...@@ -18,6 +21,12 @@ const config: HardhatUserConfig = {
ovm: { ovm: {
solcVersion: '0.7.6', solcVersion: '0.7.6',
}, },
gasReporter: {
enabled: enableGasReport,
currency: 'USD',
gasPrice: 100,
outputFile: process.env.CI ? 'gas-report.txt' : undefined,
},
} }
export default config export default config
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
"ethereum-waffle": "^3.3.0", "ethereum-waffle": "^3.3.0",
"ethers": "^5.0.32", "ethers": "^5.0.32",
"hardhat": "^2.1.2", "hardhat": "^2.1.2",
"hardhat-gas-reporter": "^1.0.4",
"mocha": "^8.3.1", "mocha": "^8.3.1",
"rimraf": "^3.0.2" "rimraf": "^3.0.2"
} }
......
...@@ -14,10 +14,13 @@ import 'hardhat-deploy' ...@@ -14,10 +14,13 @@ import 'hardhat-deploy'
import '@typechain/hardhat' import '@typechain/hardhat'
import '@eth-optimism/hardhat-ovm' import '@eth-optimism/hardhat-ovm'
import './tasks/deploy' import './tasks/deploy'
import 'hardhat-gas-reporter'
// Load environment variables from .env // Load environment variables from .env
dotenv.config() dotenv.config()
const enableGasReport = !!process.env.ENABLE_GAS_REPORT
const config: HardhatUserConfig = { const config: HardhatUserConfig = {
networks: { networks: {
hardhat: { hardhat: {
...@@ -64,6 +67,12 @@ const config: HardhatUserConfig = { ...@@ -64,6 +67,12 @@ const config: HardhatUserConfig = {
default: 0, default: 0,
}, },
}, },
gasReporter: {
enabled: enableGasReport,
currency: 'USD',
gasPrice: 100,
outputFile: process.env.CI ? 'gas-report.txt' : undefined,
},
} }
if ( if (
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
"ethers": "^5.0.31", "ethers": "^5.0.31",
"hardhat": "^2.0.8", "hardhat": "^2.0.8",
"hardhat-deploy": "^0.7.4", "hardhat-deploy": "^0.7.4",
"hardhat-gas-reporter": "^1.0.4",
"lodash": "^4.17.20", "lodash": "^4.17.20",
"merkle-patricia-tree": "^4.0.0", "merkle-patricia-tree": "^4.0.0",
"merkletreejs": "^0.2.12", "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