sc-forks/solidity-coverage

Tests Fail when using `hardhat-viem` plugin

zdenham opened this issue ยท 5 comments

Workaround: (maintainer edit for visibility)

As of 0.8.12, viem should work with coverage if you set an environment variable before the command as below:

SOLIDITY_COVERAGE=true npx hardhat coverage

----- Original Issue -----

Using hardhat viem:

const token = await hre.viem.getContractAt(
    'MyContract',
    contractAddress,
    {
        walletClient,
    }
  );

Overriding the wallet client to test calling a contract from a different EOA doesn't seem to work properly (only when using solidity coverage)

await token.write.mint(); // does not call with the context of the `walletClient`

Here is minimal reproducible example:

https://github.com/zdenham/hardhat-testy-test

@zdenham Yes, sorry this is known issue with the viem plugin that's being tracked at hardhat in PR 4961 comment.

Got it--appreciate the response @cgewecke. Will keep up to date there

I have this problem too. Please keep me posted ๐Ÿ™

@zdenham, @joelamouche A workaround for this problem has been added in the latest version (0.8.12) via #883

Everything should work as expected if you set a SOLIDITY_COVERAGE env variable to true before running the task, e.g"

SOLIDITY_COVERAGE=true npx hardhat coverage

(This allows the plugin the configure the network correctly before the hardhat-viem plugin hijacks the provider).

Have edited the original comment with this workaround for visibility and am pinning this issue. Please just lmk if this fix does not work for some reason.