Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ members = [
resolver = "2"

[workspace.package]
version = "1.4.2"
version = "1.4.3"
edition = "2024"
# Remember to update clippy.toml as well
rust-version = "1.89"
Expand Down
34 changes: 23 additions & 11 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,30 @@ impl EthApi {
node_info!("eth_getAccountInfo");

if let Some(fork) = self.get_fork() {
let block_request = self.block_request(block_number).await?;
// check if the number predates the fork, if in fork mode
if let BlockRequest::Number(number) = self.block_request(block_number).await?
&& fork.predates_fork_inclusive(number)
{
// if this predates the fork we need to fetch balance, nonce, code individually
// because the provider might not support this endpoint
let balance = fork.get_balance(address, number).map_err(BlockchainError::from);
let code = fork.get_code(address, number).map_err(BlockchainError::from);
let nonce = self.get_transaction_count(address, Some(number.into()));
let (balance, code, nonce) = try_join!(balance, code, nonce)?;

return Ok(alloy_rpc_types::eth::AccountInfo { balance, nonce, code });
if let BlockRequest::Number(number) = block_request {
trace!(target: "node", "get_account_info: fork block {}, requested block {number}", fork.block_number());
return if fork.predates_fork(number) {
// if this predates the fork we need to fetch balance, nonce, code individually
// because the provider might not support this endpoint
let balance = fork.get_balance(address, number).map_err(BlockchainError::from);
let code = fork.get_code(address, number).map_err(BlockchainError::from);
let nonce = self.get_transaction_count(address, Some(number.into()));
let (balance, code, nonce) = try_join!(balance, code, nonce)?;

Ok(alloy_rpc_types::eth::AccountInfo { balance, nonce, code })
} else {
// Anvil node is at the same block or higher than the fork block,
// return account info from backend to reflect current state.
let account_info = self.backend.get_account(address).await?;
let code = self.backend.get_code(address, Some(block_request)).await?;
Ok(alloy_rpc_types::eth::AccountInfo {
balance: account_info.balance,
nonce: account_info.nonce,
code,
})
};
}
}

Expand Down
19 changes: 18 additions & 1 deletion crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ async fn test_fork_get_account() {

#[tokio::test(flavor = "multi_thread")]
async fn test_fork_get_account_info() {
let (_api, handle) = spawn(fork_config()).await;
let (api, handle) = spawn(fork_config()).await;
let provider = handle.http_provider();

let info = provider
Expand Down Expand Up @@ -1654,6 +1654,23 @@ async fn test_fork_get_account_info() {
code: Default::default(),
}
);

// Mine and check account info at new block number, see https://github.com/foundry-rs/foundry/issues/12148
api.evm_mine(None).await.unwrap();
let info = provider
.get_account_info(address!("0x19e53a7397bE5AA7908fE9eA991B03710bdC74Fd"))
// predates fork
.number(BLOCK_NUMBER + 1)
.await
.unwrap();
assert_eq!(
info,
AccountInfo {
balance: U256::from(14352720829244098514u64),
nonce: 6690,
code: Default::default(),
}
);
}

fn assert_hardfork_config(
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/src/rlp_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Item {
Data(Vec<u8>),
Array(Vec<Item>),
Array(Vec<Self>),
}

impl Encodable for Item {
Expand Down
Loading
Loading