cgewecke / hardhat-gas-reporter

Gas Usage Analytics for Hardhat
MIT License
412 stars 57 forks source link

Gas reporter isn't enabled by default #131

Closed canpoyrazoglu closed 9 months ago

canpoyrazoglu commented 2 years ago

Eventhough it says the default value of enabled in config is true, gas reporting wasn't working for me when I did tests with the following Hardhat config:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "hardhat-gas-reporter";

const config: HardhatUserConfig = {
    solidity: {
        version: "0.8.17",
        settings: {
            optimizer: {
                enabled: true,
                runs: 200
            }
        }
    },
[...]
}

When I explicitly added the gas reporter and set enabled to true, gas reporting worked:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "hardhat-gas-reporter";

const config: HardhatUserConfig = {
    solidity: {
        version: "0.8.17",
        settings: {
            optimizer: {
                enabled: true,
                runs: 200
            }
        }
    },
[...],
    gasReporter: {
        enabled: true
    }
}

I think the readme is misleading about being enabled by default.

prasad-kumkar commented 1 year ago

I faced this too

KidesLeo commented 1 year ago

Same here

nikhil-b-more commented 1 year ago

yes the same problem I was facing, the report was getting report but I enabled to true and it worked.

cgewecke commented 9 months ago

If you're using the hardhat toolbox you have to read the hardhat.config.ts that installs with the project. They have set it up to run with an environment variable.

if (gasReporterConfig?.enabled === undefined) {
    // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
    configAsAny.gasReporter.enabled = process.env.REPORT_GAS ? true : false;
}

https://github.com/NomicFoundation/hardhat/blob/2f5c30cec52434e6a798dadfd314979c7fd4c742/packages/hardhat-toolbox/src/index.ts#L30-L33