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

Is the "remoteContracts" config option working?

Open skogard opened this issue 2 years ago • 2 comments

I've been trying to use hardhat-gas-reporter for contracts already deployed on rinkeby, which I pull in through the forking method. The forking works but the gas reporter doesn't print the imported contracts.

I found out that you're supposed to be able to get this to work using the remoteContracts config as mentioned here: https://github.com/cgewecke/hardhat-gas-reporter/issues/46 But I am not sure if it's actually working. The issue sounds like it's all resolved but it never works for me, and when I looked into the code, the remoteContracts array is ignored when it's passed to eth-gas-reporter at https://github.com/cgewecke/hardhat-gas-reporter/blob/master/src/index.ts#L186 - You can see that the InternalReporterConfig initialization code at https://github.com/cgewecke/eth-gas-reporter/blob/master/lib/config.js#L6 does not include the remoteContracts attribute, and therefore the remoteContracts is always undefined after initializing, even though the options object did have the remoteContracts attribute defined. They get stripped off.

Am i missing something? I can't find anyone complaining about this so I am thinking maybe I'm doing something wrong, but at the same time the code doesn't look like it's supposed to work. Would appreciate any pointers.

By the way I can get it to work if I manually go into node_modules/eth-gas-reporter/lib/config.js at https://github.com/cgewecke/eth-gas-reporter/blob/master/lib/config.js#L7 and add a line: this.remoteContracts = options.remoteContracts, it works, which proves my theory above. But maybe I am looking at this completely wrong, any clue? Would like to be able to use this without these monkey patching.

cc: @cgewecke

skogard avatar Jan 19 '22 22:01 skogard

@skogard Thanks for opening. Do you have a repo & branch where I could reproduce this / investigate?

Just to clarify (not saying there isn't a bug fwiw), the way remoteContracts works is that the task async loads the remote contract bytecode and stores it in a file scoped variable before mocha loads the reporter.

Then, at eth-gas-reporter, the contract artifact data is generated by invoking a function called getContracts which is defined here at hardhat-gas-reporter.

That function is passed as an option to eth-gas-reporter - when eth-gas-reporter invokes it, the file scoped variable's data is added to the set of artifacts the reporter tracks.

The getContracts option is not user facing ... it's just a trick hardhat-gas-reporter uses to interface with eth-gas-reporter. One of the limitations of eth-gas-reporter is that it does not support any asynchronous initialization and we have to use these weird methods to load data here first and read it there later.

So... TLDR, it's not obvious to me why your hack works. Maybe something else is going on.

cgewecke avatar Jan 19 '22 23:01 cgewecke

Thanks for the workaround @skogard. I too could not get remoteContracts to work against a mainnet fork out of the box.

Adding this.remoteContracts = options.remoteContracts; to the Config constructor in node_modules/eth-gas-reporter/lib/config.js did the trick.

FYI, here's the remoteContracts I'm using

remoteContracts: [
    {
        abi: ICurve3Pool__factory.abi,
        address: "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7",
        name: "Curve3Pool",
    },
],

naddison36 avatar Jul 14 '22 00:07 naddison36

i also ran into this. @naddison36 's fixup worked. it seems that the internal reporter config is not quite up to date options = new InternalReporterConfig(options); options are overridden and remoteContracts does not come along for the ride i also see the following printed out:

Warning: failed to fetch bytecode for remote contract: ContractName
Error was: TypeError: sha1 is not a function

3commascapital avatar Apr 28 '23 07:04 3commascapital

Also what about remote contracts that are deployed during the test, so they do not have an address to be specified in remoteContracts in hardhat.config?

sirpy avatar Nov 14 '23 14:11 sirpy

This is fixed in the latest version...closing.

cgewecke avatar Feb 27 '24 00:02 cgewecke