diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 0b002d3db7ec..05a7a3ff7a7b 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -66,6 +66,7 @@ use anvil_core::eth::{ utils::meets_eip155, }; use anvil_rpc::error::RpcError; +use chrono::Datelike; use flate2::{read::GzDecoder, write::GzEncoder, Compression}; use foundry_evm::{ backend::{DatabaseError, DatabaseResult, RevertStateSnapshotAction}, @@ -1123,7 +1124,12 @@ impl Backend { node_info!(" Block Number: {}", block_number); node_info!(" Block Hash: {:?}", block_hash); - node_info!(" Block Time: {:?}\n", timestamp.to_rfc2822()); + if timestamp.year() > 9999 { + // rf2822 panics with more than 4 digits + node_info!(" Block Time: {:?}\n", timestamp.to_rfc3339()); + } else { + node_info!(" Block Time: {:?}\n", timestamp.to_rfc2822()); + } let outcome = MinedBlockOutcome { block_number, included, invalid }; diff --git a/crates/anvil/tests/it/anvil.rs b/crates/anvil/tests/it/anvil.rs index b8aed751d2e6..50e27c57aa57 100644 --- a/crates/anvil/tests/it/anvil.rs +++ b/crates/anvil/tests/it/anvil.rs @@ -1,5 +1,6 @@ //! tests for anvil specific logic +use alloy_eips::BlockNumberOrTag; use alloy_primitives::Address; use alloy_provider::Provider; use anvil::{spawn, NodeConfig}; @@ -76,3 +77,14 @@ async fn test_can_use_default_genesis_timestamp() { provider.get_block(0.into(), false.into()).await.unwrap().unwrap().header.timestamp ); } + +#[tokio::test(flavor = "multi_thread")] +async fn test_can_handle_large_timestamp() { + let (api, _handle) = spawn(NodeConfig::test()).await; + let num = 317071597274; + api.evm_set_next_block_timestamp(num).unwrap(); + api.mine_one().await; + + let block = api.block_by_number(BlockNumberOrTag::Latest).await.unwrap().unwrap(); + assert_eq!(block.header.timestamp, num); +}