diff --git a/kms-connector/crates/gw-listener/tests/common/mod.rs b/kms-connector/crates/gw-listener/tests/common/mod.rs index 0ada1cecd8..069ae3183c 100644 --- a/kms-connector/crates/gw-listener/tests/common/mod.rs +++ b/kms-connector/crates/gw-listener/tests/common/mod.rs @@ -56,7 +56,7 @@ pub async fn start_test_listener( // Wait for all gw-listener event filters to be ready + 2 anvil blocks for _ in 0..NB_EVENT_TYPE { - test_instance.wait_for_log("Waiting for next").await; + test_instance.wait_for_log("Subscribed to ").await; } tokio::time::sleep(2 * test_instance.anvil_block_time()).await; diff --git a/kms-connector/crates/utils/src/tests/setup/db.rs b/kms-connector/crates/utils/src/tests/setup/db.rs index ec361a8cbb..51b3475708 100644 --- a/kms-connector/crates/utils/src/tests/setup/db.rs +++ b/kms-connector/crates/utils/src/tests/setup/db.rs @@ -2,8 +2,6 @@ use sqlx::{Pool, Postgres}; use testcontainers::{ContainerAsync, GenericImage, ImageExt, core::WaitFor, runners::AsyncRunner}; use tracing::info; -use crate::tests::setup::pick_free_port; - const POSTGRES_PORT: u16 = 5432; pub struct DbInstance { @@ -15,13 +13,11 @@ pub struct DbInstance { impl DbInstance { pub async fn setup() -> anyhow::Result { - let host_port = pick_free_port(); info!("Starting Postgres container..."); let container = GenericImage::new("postgres", "17.5") .with_wait_for(WaitFor::message_on_stderr( "database system is ready to accept connections", )) - .with_mapped_port(host_port, POSTGRES_PORT.into()) .with_env_var("POSTGRES_USER", "postgres") .with_env_var("POSTGRES_PASSWORD", "postgres") .start() @@ -29,6 +25,7 @@ impl DbInstance { info!("Postgres container ready!"); let cont_host = container.get_host().await?; + let host_port = container.get_host_port_ipv4(POSTGRES_PORT).await?; let admin_db_url = format!("postgresql://postgres:postgres@{cont_host}:{host_port}/postgres"); let db_url = diff --git a/kms-connector/crates/utils/src/tests/setup/gw.rs b/kms-connector/crates/utils/src/tests/setup/gw.rs index 6b1a347ec2..ce87a2128b 100644 --- a/kms-connector/crates/utils/src/tests/setup/gw.rs +++ b/kms-connector/crates/utils/src/tests/setup/gw.rs @@ -2,7 +2,7 @@ use crate::{ config::KmsWallet, conn::WalletGatewayProvider, provider::{FillersWithoutNonceManagement, NonceManagedProvider}, - tests::setup::{ROOT_CARGO_TOML, pick_free_port}, + tests::setup::ROOT_CARGO_TOML, }; use alloy::{ primitives::{Address, ChainId, FixedBytes}, @@ -17,7 +17,7 @@ use fhevm_gateway_bindings::{ use std::{sync::LazyLock, time::Duration}; use testcontainers::{ ContainerAsync, GenericImage, ImageExt, - core::{WaitFor, client::docker_client_instance}, + core::{ContainerPort, WaitFor, client::docker_client_instance}, runners::AsyncRunner, }; use tracing::info; @@ -78,9 +78,10 @@ impl GatewayInstance { pub async fn setup() -> anyhow::Result { let block_time = 1; - let anvil_host_port = pick_free_port(); - let anvil: ContainerAsync = - setup_anvil_gateway(anvil_host_port, block_time).await?; + + let anvil = setup_anvil_gateway(block_time).await?; + let anvil_host_port = anvil.get_host_port_ipv4(ANVIL_PORT).await?; + let wallet = KmsWallet::from_private_key_str( DEPLOYER_PRIVATE_KEY, Some(ChainId::from(*CHAIN_ID as u64)), @@ -118,19 +119,15 @@ impl GatewayInstance { } } -pub async fn setup_anvil_gateway( - host_port: u16, - block_time: u64, -) -> anyhow::Result> { +pub async fn setup_anvil_gateway(block_time: u64) -> anyhow::Result> { info!("Starting Anvil..."); let anvil = GenericImage::new("ghcr.io/foundry-rs/foundry", "v1.3.5") + .with_exposed_port(ContainerPort::Tcp(ANVIL_PORT)) .with_wait_for(WaitFor::message_on_stdout("Listening")) .with_entrypoint("anvil") .with_cmd([ "--host", "0.0.0.0", - "--port", - ANVIL_PORT.to_string().as_str(), "--chain-id", CHAIN_ID.to_string().as_str(), "--mnemonic", @@ -138,7 +135,6 @@ pub async fn setup_anvil_gateway( "--block-time", &format!("{block_time}"), ]) - .with_mapped_port(host_port, ANVIL_PORT.into()) .start() .await?;