Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kms-connector/crates/gw-listener/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions kms-connector/crates/utils/src/tests/setup/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -15,20 +13,19 @@ pub struct DbInstance {

impl DbInstance {
pub async fn setup() -> anyhow::Result<Self> {
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()
.await?;
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 =
Expand Down
20 changes: 8 additions & 12 deletions kms-connector/crates/utils/src/tests/setup/gw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand Down Expand Up @@ -78,9 +78,10 @@ impl GatewayInstance {

pub async fn setup() -> anyhow::Result<Self> {
let block_time = 1;
let anvil_host_port = pick_free_port();
let anvil: ContainerAsync<GenericImage> =
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)),
Expand Down Expand Up @@ -118,27 +119,22 @@ impl GatewayInstance {
}
}

pub async fn setup_anvil_gateway(
host_port: u16,
block_time: u64,
) -> anyhow::Result<ContainerAsync<GenericImage>> {
pub async fn setup_anvil_gateway(block_time: u64) -> anyhow::Result<ContainerAsync<GenericImage>> {
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",
TEST_MNEMONIC,
"--block-time",
&format!("{block_time}"),
])
.with_mapped_port(host_port, ANVIL_PORT.into())
.start()
.await?;

Expand Down