Skip to content

Commit b655e30

Browse files
authoredApr 15, 2024··
Merge pull request #5114 from NomicFoundation/edr/366-hardhat-metadata-fork-id
Use remote chain id in fork metadata
2 parents 5e6a640 + 3d7f13e commit b655e30

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
 

‎.changeset/itchy-maps-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/edr": patch
3+
---
4+
5+
Fixed a bug in `hardhat_metadata` where the local chain id was being used in the fork metadata

‎crates/edr_evm/src/blockchain/forked.rs

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct ForkedBlockchain {
8989
/// The chan id of the forked blockchain is either the local chain id
9090
/// override or the chain id of the remote blockchain.
9191
chain_id: u64,
92+
/// The chain id of the remote blockchain. It might deviate from chain_id.
93+
remote_chain_id: u64,
9294
network_id: u64,
9395
spec_id: SpecId,
9496
hardfork_activations: Option<HardforkActivations>,
@@ -218,13 +220,19 @@ impl ForkedBlockchain {
218220
remote: RemoteBlockchain::new(rpc_client, runtime),
219221
state_root_generator,
220222
chain_id: chain_id_override.unwrap_or(remote_chain_id),
223+
remote_chain_id,
221224
fork_block_number,
222225
network_id,
223226
spec_id,
224227
hardfork_activations,
225228
})
226229
}
227230

231+
/// Returns the chain id of the remote blockchain.
232+
pub fn remote_chain_id(&self) -> u64 {
233+
self.remote_chain_id
234+
}
235+
228236
fn runtime(&self) -> &runtime::Handle {
229237
self.remote.runtime()
230238
}

‎crates/edr_provider/src/data.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,7 @@ fn create_blockchain_and_state(
23232323

23242324
Ok(BlockchainAndState {
23252325
fork_metadata: Some(ForkMetadata {
2326-
chain_id: blockchain.chain_id(),
2326+
chain_id: blockchain.remote_chain_id(),
23272327
fork_block_number,
23282328
fork_block_hash: *blockchain
23292329
.block_by_number(fork_block_number)
@@ -2777,6 +2777,19 @@ mod tests {
27772777
Ok(())
27782778
}
27792779

2780+
#[test]
2781+
fn fork_metadata_fork_mode() -> anyhow::Result<()> {
2782+
let fixture = ProviderTestFixture::new_forked(None)?;
2783+
2784+
let fork_metadata = fixture
2785+
.provider_data
2786+
.fork_metadata()
2787+
.expect("fork metadata should exist");
2788+
assert_eq!(fork_metadata.chain_id, 1);
2789+
2790+
Ok(())
2791+
}
2792+
27802793
#[test]
27812794
fn console_log_mine_block() -> anyhow::Result<()> {
27822795
let mut fixture = ProviderTestFixture::new_local()?;

0 commit comments

Comments
 (0)