hardhat-gas-reporter
hardhat-gas-reporter copied to clipboard
Not working for internal methods in libraries
Description
I have the following set up:
- Library with pure internal methods
- Mock contract that exposes the library's internal methods
For which I'm getting no gas report:
I'm not sure if this is caused by my using a library with internal methods or Solidity v0.8 🤔
Steps to Reproduce
- git clone [email protected]:paulrberg/prb-math.git
- cd prb-math
- git checkout 79def09e62d0f188f55e0abc96c7c7026f370785
- yarn install
- REPORT_GAS=true yarn run test
Environment
Hmm. Thanks for reporting, will take a look...
Update: this seems to be about Solidity v0.8, not internal functions in libraries.
I just added hardhat-gas-reporter to my solidity-template, and I am getting no gas report:
@paulrberg Oh ok! Good to know. I will definitely look at this today....
@paulrberg The solidity-template has a slightly different problem ...
This line in the config, where excludeContracts
has an empty string is confusing the reporter's filter logic
Everything gets skipped because:
"everything".includes("") === true // ...and profound!
The issue with libraries will require a different fix. All the methods you want to measure there are calls
rather than transactions and the reporter reads gas from tx receipts.
Will look at adding option to measure these and test against the precision lib this weekend.
Re empty string in excludeContracts
- oh, of course! Thanks for the heads-up. I removed the empty string and it works now.
The issue with libraries will require a different fix. All the methods you want to measure there are calls rather than transactions and the reporter reads gas from tx receipts.
Interesting. I suppose that in the meantime my best bet is to make the functions in PRBMathMock
non-constant? Maybe emit an event?
Would love to include this into my project, but I am also running into this issue unfortunately.
Support for view and pure methods is added in 2.0 - I think that probably covers this case. The options look like this:
gasReporter: {
// This option executes an additional `eth_estimateGas` for every `eth_call`
// detected by the reporter. If you have 1000's of tests setting it to true has a
// noticeable performance impact
reportPureAndViewMethods: true,
// This option can add several seconds to test startup time if you have
// 100's of contracts in your project. (It parses all the sources in your dependency tree
// to identify state variable declarations)
excludeAutoGeneratedGetters: true,
}
Closing for now but please just ping if you feel there's something additional to consider here.
https://github.com/cgewecke/hardhat-gas-reporter/releases/tag/v2.0.0