Skip to content

Commit

Permalink
Merge pull request #5114 from NomicFoundation/edr/366-hardhat-metadat…
Browse files Browse the repository at this point in the history
…a-fork-id

Use remote chain id in fork metadata
  • Loading branch information
fvictorio committed Apr 15, 2024
2 parents 5e6a640 + 3d7f13e commit b655e30
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/itchy-maps-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": patch
---

Fixed a bug in `hardhat_metadata` where the local chain id was being used in the fork metadata
8 changes: 8 additions & 0 deletions crates/edr_evm/src/blockchain/forked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub struct ForkedBlockchain {
/// The chan id of the forked blockchain is either the local chain id
/// override or the chain id of the remote blockchain.
chain_id: u64,
/// The chain id of the remote blockchain. It might deviate from chain_id.
remote_chain_id: u64,
network_id: u64,
spec_id: SpecId,
hardfork_activations: Option<HardforkActivations>,
Expand Down Expand Up @@ -218,13 +220,19 @@ impl ForkedBlockchain {
remote: RemoteBlockchain::new(rpc_client, runtime),
state_root_generator,
chain_id: chain_id_override.unwrap_or(remote_chain_id),
remote_chain_id,
fork_block_number,
network_id,
spec_id,
hardfork_activations,
})
}

/// Returns the chain id of the remote blockchain.
pub fn remote_chain_id(&self) -> u64 {
self.remote_chain_id
}

fn runtime(&self) -> &runtime::Handle {
self.remote.runtime()
}
Expand Down
15 changes: 14 additions & 1 deletion crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ fn create_blockchain_and_state(

Ok(BlockchainAndState {
fork_metadata: Some(ForkMetadata {
chain_id: blockchain.chain_id(),
chain_id: blockchain.remote_chain_id(),
fork_block_number,
fork_block_hash: *blockchain
.block_by_number(fork_block_number)
Expand Down Expand Up @@ -2777,6 +2777,19 @@ mod tests {
Ok(())
}

#[test]
fn fork_metadata_fork_mode() -> anyhow::Result<()> {
let fixture = ProviderTestFixture::new_forked(None)?;

let fork_metadata = fixture
.provider_data
.fork_metadata()
.expect("fork metadata should exist");
assert_eq!(fork_metadata.chain_id, 1);

Ok(())
}

#[test]
fn console_log_mine_block() -> anyhow::Result<()> {
let mut fixture = ProviderTestFixture::new_local()?;
Expand Down

0 comments on commit b655e30

Please sign in to comment.