Skip to content
Draft
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
11 changes: 1 addition & 10 deletions crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,16 +1702,7 @@ impl EthApi {
node_info!("eth_feeHistory");
// max number of blocks in the requested range

let current = self.backend.best_number();
let slots_in_an_epoch = 32u64;

let number = match newest_block {
BlockNumber::Latest | BlockNumber::Pending => current,
BlockNumber::Earliest => 0,
BlockNumber::Number(n) => n,
BlockNumber::Safe => current.saturating_sub(slots_in_an_epoch),
BlockNumber::Finalized => current.saturating_sub(slots_in_an_epoch * 2),
};
let number = self.backend.convert_block_number(Some(newest_block));

// check if the number predates the fork, if in fork mode
if let Some(fork) = self.get_fork() {
Expand Down
21 changes: 20 additions & 1 deletion crates/anvil/tests/it/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utils::http_provider_with_signer;
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::{Address, U64, U256, uint};
use alloy_provider::Provider;
use alloy_rpc_types::{BlockId, TransactionRequest};
use alloy_rpc_types::{BlockId, BlockNumberOrTag, TransactionRequest};
use alloy_serde::WithOtherFields;
use anvil::{NodeConfig, eth::fees::INITIAL_BASE_FEE, spawn};

Expand Down Expand Up @@ -233,6 +233,25 @@ async fn test_can_use_fee_history() {
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_fee_history_safe_finalized_use_slots_in_an_epoch() {
let (api, handle) = spawn(NodeConfig::test().with_slots_in_an_epoch(3)).await;
let provider = handle.http_provider();

// (blocks mined, expected safe, expected finalized); finalized saturates at genesis first
for (mined, safe, finalized) in [(4, 1, 0), (10, 7, 4)] {
while api.block_number().unwrap() < U256::from(mined) {
api.mine_one().await;
}
for (tag, expected) in
[(BlockNumberOrTag::Safe, safe), (BlockNumberOrTag::Finalized, finalized)]
{
let history = provider.get_fee_history(1, tag, &[]).await.unwrap();
assert_eq!(history.oldest_block, expected, "{tag} at block {mined}");
}
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_estimate_gas_empty_data() {
let (api, handle) = spawn(NodeConfig::test()).await;
Expand Down
Loading