Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle large years #9032

Merged
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
8 changes: 7 additions & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 };

Expand Down
12 changes: 12 additions & 0 deletions crates/anvil/tests/it/anvil.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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);
}
Loading