@@ -2,7 +2,7 @@ use crate::{
22 config:: KmsWallet ,
33 conn:: WalletGatewayProvider ,
44 provider:: { FillersWithoutNonceManagement , NonceManagedProvider } ,
5- tests:: setup:: { ROOT_CARGO_TOML , pick_free_port } ,
5+ tests:: setup:: ROOT_CARGO_TOML ,
66} ;
77use alloy:: {
88 primitives:: { Address , ChainId , FixedBytes } ,
@@ -17,7 +17,7 @@ use fhevm_gateway_bindings::{
1717use std:: { sync:: LazyLock , time:: Duration } ;
1818use testcontainers:: {
1919 ContainerAsync , GenericImage , ImageExt ,
20- core:: { WaitFor , client:: docker_client_instance} ,
20+ core:: { ContainerPort , WaitFor , client:: docker_client_instance} ,
2121 runners:: AsyncRunner ,
2222} ;
2323use tracing:: info;
@@ -78,9 +78,10 @@ impl GatewayInstance {
7878
7979 pub async fn setup ( ) -> anyhow:: Result < Self > {
8080 let block_time = 1 ;
81- let anvil_host_port = pick_free_port ( ) ;
82- let anvil: ContainerAsync < GenericImage > =
83- setup_anvil_gateway ( anvil_host_port, block_time) . await ?;
81+
82+ let anvil = setup_anvil_gateway ( block_time) . await ?;
83+ let anvil_host_port = anvil. get_host_port_ipv4 ( ANVIL_PORT ) . await ?;
84+
8485 let wallet = KmsWallet :: from_private_key_str (
8586 DEPLOYER_PRIVATE_KEY ,
8687 Some ( ChainId :: from ( * CHAIN_ID as u64 ) ) ,
@@ -118,27 +119,22 @@ impl GatewayInstance {
118119 }
119120}
120121
121- pub async fn setup_anvil_gateway (
122- host_port : u16 ,
123- block_time : u64 ,
124- ) -> anyhow:: Result < ContainerAsync < GenericImage > > {
122+ pub async fn setup_anvil_gateway ( block_time : u64 ) -> anyhow:: Result < ContainerAsync < GenericImage > > {
125123 info ! ( "Starting Anvil..." ) ;
126124 let anvil = GenericImage :: new ( "ghcr.io/foundry-rs/foundry" , "v1.3.5" )
125+ . with_exposed_port ( ContainerPort :: Tcp ( ANVIL_PORT ) )
127126 . with_wait_for ( WaitFor :: message_on_stdout ( "Listening" ) )
128127 . with_entrypoint ( "anvil" )
129128 . with_cmd ( [
130129 "--host" ,
131130 "0.0.0.0" ,
132- "--port" ,
133- ANVIL_PORT . to_string ( ) . as_str ( ) ,
134131 "--chain-id" ,
135132 CHAIN_ID . to_string ( ) . as_str ( ) ,
136133 "--mnemonic" ,
137134 TEST_MNEMONIC ,
138135 "--block-time" ,
139136 & format ! ( "{block_time}" ) ,
140137 ] )
141- . with_mapped_port ( host_port, ANVIL_PORT . into ( ) )
142138 . start ( )
143139 . await ?;
144140
0 commit comments