From c5c27299b4633c865b10b4c63ada42a556077124 Mon Sep 17 00:00:00 2001 From: jbcaron Date: Sat, 7 Dec 2024 23:30:04 +0100 Subject: [PATCH] fix: CI --- crates/client/eth/src/client.rs | 5 ++- crates/client/eth/src/l1_gas_price.rs | 44 ++++----------------------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/crates/client/eth/src/client.rs b/crates/client/eth/src/client.rs index 8b40c9726..a8374098f 100644 --- a/crates/client/eth/src/client.rs +++ b/crates/client/eth/src/client.rs @@ -210,7 +210,10 @@ pub mod eth_client_getter_test { AnvilPortNum(guard.next.next().expect("no more port to use")) } - fn create_anvil_instance() -> AnvilInstance { + pub fn create_anvil_instance() -> AnvilInstance { + // Adding a delay of 5 seconds to mitigate potential rate limiting issues + // when interacting with the upstream API. + std::thread::sleep(std::time::Duration::from_secs(5)); let port = get_port(); let anvil = Anvil::new() .fork(FORK_URL.clone()) diff --git a/crates/client/eth/src/l1_gas_price.rs b/crates/client/eth/src/l1_gas_price.rs index 33a7f7a9d..e6ca2b321 100644 --- a/crates/client/eth/src/l1_gas_price.rs +++ b/crates/client/eth/src/l1_gas_price.rs @@ -99,30 +99,18 @@ async fn update_l1_block_metrics(eth_client: &EthereumClient, l1_gas_provider: G #[cfg(test)] mod eth_client_gas_price_worker_test { use super::*; - use crate::client::eth_client_getter_test::create_ethereum_client; - use alloy::node_bindings::Anvil; + use crate::client::eth_client_getter_test::{create_anvil_instance, create_ethereum_client}; use httpmock::{MockServer, Regex}; use mc_mempool::GasPriceProvider; use serial_test::serial; use std::time::SystemTime; use tokio::task::JoinHandle; use tokio::time::{timeout, Duration}; - const ANOTHER_ANVIL_PORT: u16 = 8546; - const L1_BLOCK_NUMBER: u64 = 20395662; - - lazy_static::lazy_static! { - static ref FORK_URL: String = std::env::var("ETH_FORK_URL").expect("ETH_FORK_URL not set"); - } #[serial] #[tokio::test] async fn gas_price_worker_when_infinite_loop_true_works() { - let anvil = Anvil::new() - .fork(FORK_URL.clone()) - .fork_block_number(L1_BLOCK_NUMBER) - .port(ANOTHER_ANVIL_PORT) - .try_spawn() - .expect("issue while forking for the anvil"); + let anvil = create_anvil_instance(); let eth_client = create_ethereum_client(Some(anvil.endpoint().as_str())); let l1_gas_provider = GasPriceProvider::new(); @@ -166,12 +154,7 @@ mod eth_client_gas_price_worker_test { #[serial] #[tokio::test] async fn gas_price_worker_when_infinite_loop_false_works() { - let anvil = Anvil::new() - .fork(FORK_URL.clone()) - .fork_block_number(L1_BLOCK_NUMBER) - .port(ANOTHER_ANVIL_PORT) - .try_spawn() - .expect("issue while forking for the anvil"); + let anvil = create_anvil_instance(); let eth_client = create_ethereum_client(Some(anvil.endpoint().as_str())); let l1_gas_provider = GasPriceProvider::new(); @@ -190,12 +173,7 @@ mod eth_client_gas_price_worker_test { #[serial] #[tokio::test] async fn gas_price_worker_when_gas_price_fix_works() { - let anvil = Anvil::new() - .fork(FORK_URL.clone()) - .fork_block_number(L1_BLOCK_NUMBER) - .port(ANOTHER_ANVIL_PORT) - .try_spawn() - .expect("issue while forking for the anvil"); + let anvil = create_anvil_instance(); let eth_client = create_ethereum_client(Some(anvil.endpoint().as_str())); let l1_gas_provider = GasPriceProvider::new(); l1_gas_provider.update_eth_l1_gas_price(20); @@ -216,12 +194,7 @@ mod eth_client_gas_price_worker_test { #[serial] #[tokio::test] async fn gas_price_worker_when_data_gas_price_fix_works() { - let anvil = Anvil::new() - .fork(FORK_URL.clone()) - .fork_block_number(L1_BLOCK_NUMBER) - .port(ANOTHER_ANVIL_PORT) - .try_spawn() - .expect("issue while forking for the anvil"); + let anvil = create_anvil_instance(); let eth_client = create_ethereum_client(Some(anvil.endpoint().as_str())); let l1_gas_provider = GasPriceProvider::new(); l1_gas_provider.update_eth_l1_data_gas_price(20); @@ -306,12 +279,7 @@ mod eth_client_gas_price_worker_test { #[serial] #[tokio::test] async fn update_gas_price_works() { - let anvil = Anvil::new() - .fork(FORK_URL.clone()) - .fork_block_number(L1_BLOCK_NUMBER) - .port(ANOTHER_ANVIL_PORT) - .try_spawn() - .expect("issue while forking for the anvil"); + let anvil = create_anvil_instance(); let eth_client = create_ethereum_client(Some(anvil.endpoint().as_str())); let l1_gas_provider = GasPriceProvider::new();