Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests Fail when using hardhat-viem plugin #874

Open
zdenham opened this issue Mar 18, 2024 · 5 comments
Open

Tests Fail when using hardhat-viem plugin #874

zdenham opened this issue Mar 18, 2024 · 5 comments

Comments

@zdenham
Copy link

zdenham commented Mar 18, 2024

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`
@cgewecke cgewecke changed the title Tests Fail with Coverage Which Otherwise Succeed Tests Fail with Coverage when using viem plugin Mar 18, 2024
@zdenham
Copy link
Author

zdenham commented Mar 18, 2024

Here is minimal reproducible example:

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

@cgewecke
Copy link
Member

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

@zdenham
Copy link
Author

zdenham commented Mar 19, 2024

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

@joelamouche
Copy link

I have this problem too. Please keep me posted 🙏

@cgewecke cgewecke changed the title Tests Fail with Coverage when using viem plugin Tests Fail when using hardhat-viem plugin Apr 5, 2024
@cgewecke
Copy link
Member

cgewecke commented Apr 5, 2024

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

@cgewecke cgewecke pinned this issue Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants