hardhat-gas-reporter icon indicating copy to clipboard operation
hardhat-gas-reporter copied to clipboard

Not working for internal methods in libraries

Open PaulRBerg opened this issue 3 years ago • 6 comments

Description

I have the following set up:

  1. Library with pure internal methods
  2. Mock contract that exposes the library's internal methods

For which I'm getting no gas report:

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

  1. git clone [email protected]:paulrberg/prb-math.git
  2. cd prb-math
  3. git checkout 79def09e62d0f188f55e0abc96c7c7026f370785
  4. yarn install
  5. REPORT_GAS=true yarn run test

Environment

PaulRBerg avatar Mar 24 '21 17:03 PaulRBerg

Hmm. Thanks for reporting, will take a look...

cgewecke avatar Mar 25 '21 23:03 cgewecke

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:

Capture d’écran 2021-04-01 à 12 44 09

PaulRBerg avatar Apr 01 '21 09:04 PaulRBerg

@paulrberg Oh ok! Good to know. I will definitely look at this today....

cgewecke avatar Apr 01 '21 17:04 cgewecke

@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.

cgewecke avatar Apr 02 '21 15:04 cgewecke

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?

PaulRBerg avatar Apr 03 '21 07:04 PaulRBerg

Would love to include this into my project, but I am also running into this issue unfortunately.

bmeredith avatar Jul 05 '21 01:07 bmeredith

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

cgewecke avatar Mar 14 '24 05:03 cgewecke