Hardhat-deploy: `hardhat-deploy` doesn't work with `solidity-coverage`

Created on 22 Jun 2021  ·  14Comments  ·  Source: wighawag/hardhat-deploy

To reproduce:

  1. Clone https://github.com/wighawag/template-ethereum-contracts
  2. yarn
  3. yarn coverage

And you should get this error:

image

Most helpful comment

@GeekBerry If you look at the code wighawag pointed to, you will understand: https://github.com/sc-forks/solidity-coverage/blob/3c0f3a5c7db26e82974873bbf61cf462072a7c6d/plugins/resources/nomiclabs.utils.js#L136-L141

I hack in node_modules/solidity-coverage/plugins/resources/nomiclabs.utils.js and change line 136 to

env.network = Object.assign({
    name: networkName,
    config: networkConfig,
    provider: provider,
    isHardhatEVM: isHardhatEVM,
}, env.network);

then run coverage successful.

I guess solidity-coverage author might fix this issue next version.

All 14 comments

+1

@wighawag Is it an issue on my side? Or is it an issue in hardhat-deploy?

same for me, running:
├─ @nomiclabs/[email protected]
├─ @nomiclabs/[email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]

+1

This seems to have been introduced in 0.8.x. Using 0.7.11 works for me.

Thanks all for reporting.

Sorry for the late reply, I am currently traveling with family and do not have much time on my laptop.

I had a look today though and the issue is that solidity-coverage create a new network object here: https://github.com/sc-forks/solidity-coverage/blob/3c0f3a5c7db26e82974873bbf61cf462072a7c6d/plugins/resources/nomiclabs.utils.js#L136-L141 overriding any modifications made by other plugins.

hardhat-deploy/solidity-coverage compatibility had a similar issue in the past for that same reason (see https://github.com/sc-forks/solidity-coverage/issues/624) and hardhat-deploy made a workaround for it at that time but newest hardhat-deploy version relies on the ability to add field to the network object, it thus also relies on accessing the network object at plugin import time and so the fix should in my opinion be in solidity-coverage. Instead of creating a new object, solidity-coverage could simply modify the existing hre.network keeping any other addition from other plugins to it.

A replacement of these line https://github.com/sc-forks/solidity-coverage/blob/3c0f3a5c7db26e82974873bbf61cf462072a7c6d/plugins/resources/nomiclabs.utils.js#L136-L141

To these:

env.network.name = networkName;
env.network.config = networkConfig;
env.network.provider = provider;
env.network.isHardhatEVM = isHardhatEVM;

Should do it

What do you think @cgewecke ?

but what is the env ? how could i config it?

@wighawag Thank you for the time you took to investigate!!

I hope @cgewecke will be able to modify solidity-coverage soon...

env.network.name = networkName;
env.network.config = networkConfig;
env.network.provider = provider;
env.network.isHardhatEVM = isHardhatEVM;

Should do it

Tested and it works.

env.network.name = networkName;
env.network.config = networkConfig;
env.network.provider = provider;
env.network.isHardhatEVM = isHardhatEVM;

Should do it

Tested and it works.

em~, but what is env ? process.env or require('hardhat').network.isHardhatEVM?

@GeekBerry If you look at the code wighawag pointed to, you will understand: https://github.com/sc-forks/solidity-coverage/blob/3c0f3a5c7db26e82974873bbf61cf462072a7c6d/plugins/resources/nomiclabs.utils.js#L136-L141

I hack in node_modules/solidity-coverage/plugins/resources/nomiclabs.utils.js and change line 136 to

env.network = Object.assign({
    name: networkName,
    config: networkConfig,
    provider: provider,
    isHardhatEVM: isHardhatEVM,
}, env.network);

then run coverage successful.

I guess solidity-coverage author might fix this issue next version.

+1

Hey all, the issue is on the solidity-coverage side, I ll close the issue as hardhat-deploy cannot do much.
In my template, I patch solidity-coverage with patch-package and have it working, see : https://github.com/wighawag/template-ethereum-contracts/blob/main/patches/solidity-coverage%2B0.7.16.patch

There is this PR that fixes it in solidity-coverage : https://github.com/sc-forks/solidity-coverage/pull/647

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitpusha picture gitpusha  ·  6Comments

tennox picture tennox  ·  4Comments

smartcontracts picture smartcontracts  ·  20Comments

lepidotteri picture lepidotteri  ·  5Comments

jaypaik picture jaypaik  ·  13Comments