NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.33k stars 1.42k forks source link

Hardhat forking network validation #1902

Open fredlacs opened 3 years ago

fredlacs commented 3 years ago

A number of users attempt to fork different networks using hardhat.

Some networks are evm compatible with an RPC interface that works with hardhat forking, but the internals are sometimes different to that of the evm (for example gas metering is different).

By forking these networks with hardhat, users might get the impression that their tests are executing correctly but when contracts are deployed they can fail.

This can still be useful for integration testing, but users should get a warning about that when attempting to fork certain networks.

alcuadrado commented 3 years ago

Thanks for opening this issue, @fredlacs. It's something that we also noticed and were worried about. Many users don't realize that Hardhat Network and Arbitrum are very different systems, with some compatibility.

How do you think we should communicate this? In particular, what did you mean by "This can still be useful for integration testing"? Integration tests for contracts that are meant to be run on Arbitrum?

fredlacs commented 3 years ago

The feature is useful for integration testing in the sense that it can give a dev more confidence that their Arbitrum deployment will integrate with the correct addresses and using the intended interfaces.

The two main issues that I'd highlight in a warning are: possible different execution environment, precompiles and gas metering.

I think an opt-in mechanism with loud warnings for any chain ID that isn't whitelisted works well.

github-actions[bot] commented 2 years ago

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

gzeoneth commented 2 years ago

With #2995, the user would have to add a new flag to make networks like Arbitrum Nitro works with hardhat. That would serves as part of the opt-in mechanism but we probably should still have a warning based on chainId.

mdcoon commented 1 year ago

To add to the discussion. The precompiles are essential for any smart contract attempting to get L1 gas fee information on-chain, or even offchain in unit tests through the harhat ethers providers. The precompile addresses/opcodes are not passing. If I call an RPC endpoint directly outside of Hardhat, it works fine. But obviously can't test my contracts through a forked Hardhat instance that does not support the precompiles. Perhaps some opcodes and precompile addresses could be mapped to fallback to the backing archive node RPC endpoint.