cgewecke / eth-gas-reporter

Gas usage per unit test. Average gas usage per method. A mocha reporter.
MIT License
603 stars 94 forks source link

hardhat_reset interferes with gas reporter #244

Closed jtremback closed 3 years ago

jtremback commented 3 years ago

Using the "hardhat_reset" request seems to break eth-gas-reporter. I have defined this function:

async function resetChain() {
  await network.provider.request({
    method: "hardhat_reset",
    params: [],
  });
}

And i call it like this: await resetChain(); on the first line of each test case. I am using Hardhat, with hardhat-waffle, and chai assertions.

When I comment out the call to hardhat_reset, full gas reporting works. Also, if I restart the evm by hand (ending and restarting the evm process in the terminal), the first time I run the tests again, even with hardhat_reset, gas reporting works. This gives me the hunch that there may be some kind of race condition in the setup.

cgewecke commented 3 years ago

Hi @jtremback. Thanks for reporting!

I think the problem might originate in this PR: https://github.com/nomiclabs/hardhat/pull/1024 which fixes a bug with the Ethers provider.

If that's the case, a possible solution is to duplicate the proxy provider logic there in hardhat-gas-reporter's provider wrapper, here

jtremback commented 3 years ago

Hmmm very interesting. Thanks!

jtremback commented 3 years ago

It looks like the chain state is reset at some point when running tests without calling this method. So I think I can do without this functionality for now and probably won't make the recommended changes at this point.

cgewecke commented 3 years ago

Ok cool - I'm going to re-open at HH gas reporter.