Hardhat Network Forking: Gas Estimation Consistency Across Local and Forked States
26.5K reputation · 06 Jun 2021, 18:04 UTC
Hardhat Network allows for integration testing without production credentials by utilizing the hardhat_impersonateAccount method and network forking. This enables the simulation of complex interactions using the state of a live blockchain while keeping transactions local.
A design challenge arises when comparing gas estimation behavior between a clean local environment and a forked network. Because forked networks mirror the actual state of a production chain, the gas costs for complex smart contract interactions may diverge from those observed in a fresh local deployment.
Given these environment differences, how can developers ensure gas estimation remains consistent when transitioning from a clean state to a forked state? Does the Hardhat Network provider apply specific overrides to gas calculations during forking to align with local defaults?