From 3e55932a3abaf70e675713aaf123fd457377559d Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Tue, 5 Dec 2023 15:22:32 +0100 Subject: [PATCH] Fix anvil issue --- crates/fake-rpc/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/fake-rpc/src/lib.rs b/crates/fake-rpc/src/lib.rs index 48f88f7..81c334e 100644 --- a/crates/fake-rpc/src/lib.rs +++ b/crates/fake-rpc/src/lib.rs @@ -1,6 +1,7 @@ use std::net::{Ipv4Addr, SocketAddr}; use std::sync::atomic::AtomicBool; use std::sync::Arc; +use std::time::Duration; use axum::extract::State; use axum::routing::{post, IntoMakeService}; @@ -11,6 +12,8 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use tokio::sync::Mutex; +pub const BLOCK_TIME_SECONDS: u64 = 2; + pub struct DoubleAnvil { main_anvil: Mutex, reference_anvil: Mutex, @@ -90,10 +93,10 @@ async fn rpc( anvil.advance().await.unwrap(); } - anvil.main_anvil.lock().await + anvil.reference_anvil.lock().await } "eth_getTransactionReceipt" => anvil.main_anvil.lock().await, - "eth_getTransactionByHash" => anvil.main_anvil.lock().await, + "eth_getTransactionByHash" => anvil.reference_anvil.lock().await, _ => anvil.main_anvil.lock().await, }; @@ -119,8 +122,10 @@ pub async fn serve( Arc, axum::Server>, ) { - let main_anvil = Anvil::new().spawn(); - let reference_anvil = Anvil::new().spawn(); + let main_anvil = Anvil::new().block_time(BLOCK_TIME_SECONDS).spawn(); + let reference_anvil = Anvil::new().block_time(BLOCK_TIME_SECONDS).spawn(); + + tokio::time::sleep(Duration::from_secs(BLOCK_TIME_SECONDS)).await; tracing::info!("Main anvil instance: {}", main_anvil.endpoint()); tracing::info!("Reference anvil instance: {}", reference_anvil.endpoint());