Skip to content

Commit

Permalink
fix: CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron committed Dec 7, 2024
1 parent 76962ff commit c5c2729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 39 deletions.
5 changes: 4 additions & 1 deletion crates/client/eth/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
44 changes: 6 additions & 38 deletions crates/client/eth/src/l1_gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit c5c2729

Please sign in to comment.