Skip to content

Commit

Permalink
Fix anvil issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 5, 2023
1 parent 7766fa9 commit 3e55932
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/fake-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<AnvilInstance>,
reference_anvil: Mutex<AnvilInstance>,
Expand Down Expand Up @@ -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,
};

Expand All @@ -119,8 +122,10 @@ pub async fn serve(
Arc<DoubleAnvil>,
axum::Server<AddrIncoming, IntoMakeService<Router>>,
) {
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());
Expand Down

0 comments on commit 3e55932

Please sign in to comment.