Skip to content

Commit 567ac47

Browse files
authored
fix: ethgetaccinfo (#11715)
1 parent 0ac1878 commit 567ac47

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

crates/anvil/src/eth/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use anvil_rpc::{error::RpcError, response::ResponseResult};
8282
use foundry_common::provider::ProviderBuilder;
8383
use foundry_evm::decode::RevertDecoder;
8484
use futures::{
85-
StreamExt,
85+
StreamExt, TryFutureExt,
8686
channel::{mpsc::Receiver, oneshot},
8787
};
8888
use parking_lot::RwLock;
@@ -774,8 +774,8 @@ impl EthApi {
774774
{
775775
// if this predates the fork we need to fetch balance, nonce, code individually
776776
// because the provider might not support this endpoint
777-
let balance = self.balance(address, Some(number.into()));
778-
let code = self.get_code(address, Some(number.into()));
777+
let balance = fork.get_balance(address, number).map_err(BlockchainError::from);
778+
let code = fork.get_code(address, number).map_err(BlockchainError::from);
779779
let nonce = self.get_transaction_count(address, Some(number.into()));
780780
let (balance, code, nonce) = try_join!(balance, code, nonce)?;
781781

crates/anvil/tests/it/fork.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use alloy_network::{EthereumWallet, ReceiptResponse, TransactionBuilder, Transac
1313
use alloy_primitives::{Address, Bytes, TxHash, TxKind, U64, U256, address, b256, bytes, uint};
1414
use alloy_provider::Provider;
1515
use alloy_rpc_types::{
16-
BlockId, BlockNumberOrTag,
16+
AccountInfo, BlockId, BlockNumberOrTag,
1717
anvil::Forking,
1818
request::{TransactionInput, TransactionRequest},
1919
state::EvmOverrides,
@@ -1619,6 +1619,27 @@ async fn test_fork_get_account() {
16191619
assert_eq!(alice_acc_init, alice_acc_prev_block);
16201620
}
16211621

1622+
#[tokio::test(flavor = "multi_thread")]
1623+
async fn test_fork_get_account_info() {
1624+
let (_api, handle) = spawn(fork_config()).await;
1625+
let provider = handle.http_provider();
1626+
1627+
let info = provider
1628+
.get_account_info(address!("0x19e53a7397bE5AA7908fE9eA991B03710bdC74Fd"))
1629+
// predates fork
1630+
.number(BLOCK_NUMBER - 1)
1631+
.await
1632+
.unwrap();
1633+
assert_eq!(
1634+
info,
1635+
AccountInfo {
1636+
balance: U256::from(14353753764795095694u64),
1637+
nonce: 6689,
1638+
code: Default::default(),
1639+
}
1640+
);
1641+
}
1642+
16221643
fn assert_hardfork_config(
16231644
config: &EthConfig,
16241645
expected_blob_params: &BlobParams,

0 commit comments

Comments
 (0)