chore: adapt to EDR's new hardfork API - #8574
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR updates Hardhat’s EDR integration to align with EDR’s newer hardfork naming/typing (moving away from dropped exported constants/spec IDs), and adjusts both runtime code and tests to use the new hardfork-name flow consistently.
Changes:
- Replace uses of EDR-exported hardfork constants/spec IDs with Hardhat hardfork-name enums and validation (
getHardforkName). - Route local genesis/predeploy selection through a shared
getChainGenesisStatehelper and pass validated hardfork names through provider config. - Update and extend tests to cover the new conversion behavior and chain override filtering (e.g. omitting pre-Byzantium L1 activations).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/hardhat/test/internal/builtin-plugins/solidity-test/helpers.ts | Updates assertions to use Hardhat’s hardfork-name enums instead of EDR constants. |
| packages/hardhat/test/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts | Adjusts conversion tests for the new “hardfork name passthrough” and adds coverage for chain override filtering. |
| packages/hardhat/test/internal/builtin-plugins/network-manager/edr/genesis-state.ts | Updates tests to pass L1HardforkName.* values instead of EDR constants. |
| packages/hardhat/src/internal/builtin-plugins/solidity-test/helpers.ts | Switches hardfork resolution to getHardforkName and predeploy selection to getChainGenesisState. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/hardfork.ts | Adds getHardforkName helper to validate and return the correct hardfork enum for a chain type. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts | Moves L1 conversion to EDR’s L1Hardfork enum and updates chain override generation to use hardfork names + filtering. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/edr/genesis-state.ts | Changes caching/keying to use hardfork names and factors out getChainGenesisState. |
| packages/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts | Passes validated hardfork names into genesis-state creation and provider config. |
Suppressed comments (1)
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts:86
- Avoid throwing a generic
Errorhere; useassertHardhatInvariant(false, ...)(or aHardhatError) for invariant violations so error handling stays consistent across Hardhat.
default:
const _exhaustiveCheck: never = hardfork;
throw new Error(
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we want to print the fork
`Unknown L1 hardfork '${hardfork as L1Hardfork}', this shouldn't happen`,
);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (3)
Previously missed (3) — in code that hasn't changed since the last review.
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/genesis-state.ts:69
- The cache is still typed as Map<string, ...>, but this function now uses
L1HardforkName | OpHardforkNameas the hardfork cache key. This can lead to TypeScript errors/mismatched typing (and makes the cache type less precise). Update the cache map key type to matchhardforkName.
export async function getGenesisStateAndOwnedAccounts(
accountsConfig: EdrNetworkAccountsConfig,
forkingConfig: EdrNetworkForkingConfig | undefined,
chainType: ChainType,
hardforkName: L1HardforkName | OpHardforkName,
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/hardfork.ts:97
getHardforkNamecurrently accepts anyL1HardforkName, including pre-Byzantium forks (e.g. FRONTIER/DAO). But this EDR integration no longer maps/handles pre-Byzantium L1 hardforks (see the filtering inhardhatChainDescriptorsToEdrChainOverridesand theL1Hardforkenum usage), so allowing them here can lead to runtime failures when configuring the provider/genesis state. Consider rejecting pre-Byzantium L1 hardforks early in this validator.
export function getHardforkName(
hardfork: string,
chainType: ChainType,
): L1HardforkName | OpHardforkName {
return chainType === OPTIMISM_CHAIN_TYPE
? getOpHardforkName(hardfork)
: getL1HardforkName(hardfork);
}
packages/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/hardfork.ts:97
- This PR adds
getHardforkName, but there are no tests covering its behavior (e.g. L1 vs OP selection and pre-Byzantium L1 rejection). Adding unit tests would help prevent regressions, especially since this function is now used to build provider configs and chain overrides.
export function getHardforkName(
hardfork: string,
chainType: ChainType,
): L1HardforkName | OpHardforkName {
return chainType === OPTIMISM_CHAIN_TYPE
? getOpHardforkName(hardfork)
: getL1HardforkName(hardfork);
}
Context
Adapts HH to the hardfork API changes shipping in EDR with NomicFoundation/edr#1645:
SpecIdenum is renamed toL1HardforkChanges
L1HardforkenumhardforkHistoryentries for pre-Byzantium L1 hardforks are omitted from the EDR chain overrides, since EDR can no longer represent them.throw new Errorfallthroughs withassertHardhatInvariant(which made the file'seslint-disable no-restricted-syntaxexemption unnecessary).Behavior changes
hardforkHistoryentries no longer reach EDRhardhatHardforkToEdrSpecIdtogetHardforkName(internal API).