diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 701e4c7ebe..669da01f5d 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -10311,7 +10311,7 @@ mod test { let address_alice_str = str_to_pointer(LISTEN_MULTIADDR); let alice_network_str = str_to_pointer(NETWORK_STRING); - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); assert_eq!(*error_ptr, 0); let passphrase: *const c_char = @@ -10482,7 +10482,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("dolphis dancing in the coastal waters").unwrap()) as *const c_char; @@ -10703,7 +10703,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let config = comms_config_create(ptr::null(), address_str, false, false, error_ptr); + let config = comms_config_create(ptr::null(), address_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("a cat outside in Istanbul").unwrap()) as *const c_char; @@ -10761,7 +10761,7 @@ mod test { let db_path_str: *const c_char = CString::into_raw(db_path) as *const c_char; let address_str = CString::new(LISTEN_MULTIADDR).unwrap().into_raw() as *const c_char; - let config = comms_config_create(ptr::null(), address_str, false, false, error_ptr); + let config = comms_config_create(ptr::null(), address_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("a wave in teahupoo").unwrap()) as *const c_char; @@ -10840,7 +10840,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("Satoshi Nakamoto").unwrap()) as *const c_char; @@ -11011,7 +11011,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("J-bay open corona").unwrap()) as *const c_char; @@ -11143,7 +11143,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("The master and margarita").unwrap()) as *const c_char; @@ -11356,7 +11356,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; @@ -11581,7 +11581,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), address_alice_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), address_alice_str, true, true, error_ptr); assert_eq!(error, 0, "comms_config_create errored"); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; @@ -11832,7 +11832,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let network_str: *const c_char = CString::into_raw(network) as *const c_char; - let config = comms_config_create(ptr::null(), address_str, false, false, error_ptr); + let config = comms_config_create(ptr::null(), address_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let void_ptr: *mut c_void = &mut (5) as *mut _ as *mut c_void; @@ -12196,7 +12196,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let alice_network_str: *const c_char = CString::into_raw(network) as *const c_char; - let alice_config = comms_config_create(ptr::null(), alice_address_str, false, false, error_ptr); + let alice_config = comms_config_create(ptr::null(), alice_address_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let void_ptr: *mut c_void = &mut (5) as *mut _ as *mut c_void; @@ -12254,7 +12254,7 @@ mod test { let network = CString::new(NETWORK_STRING).unwrap(); let bob_network_str: *const c_char = CString::into_raw(network) as *const c_char; - let bob_config = comms_config_create(ptr::null(), bob_address_str, false, false, error_ptr); + let bob_config = comms_config_create(ptr::null(), bob_address_str, true, true, error_ptr); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let void_ptr: *mut c_void = &mut (5) as *mut _ as *mut c_void; @@ -12440,19 +12440,22 @@ mod test { // Bob's peer connection to Alice will still be active for a short while until Bob figures out Alice is // gone, and a 'dial_peer' command to Alice from Bob may return the previous connection state, but it // should not be possible to do anything with the connection. - let bob_comms_dial_peer = - bob_wallet_runtime.block_on(async { bob_wallet_comms.dial_peer(alice_peer_id).await.unwrap().await }); - if bob_comms_dial_peer.is_ok() && - bob_wallet_runtime - .block_on(bob_wallet_comms.open_substream( - alice_peer_id, - // TODO: this will cause this to fail even if the peer is active - &StreamProtocol::new("/test/me"), - )) - .is_ok() - { - panic!("Connection to Alice should not be active!"); - } + let _unused = bob_wallet_runtime.block_on(async { + if let Ok(dial_result) = bob_wallet_comms.dial_peer(alice_peer_id).await { + if let Ok(_) = dial_result.await { + if bob_wallet_runtime + .block_on(bob_wallet_comms.open_substream( + alice_peer_id, + // TODO: this will cause this to fail even if the peer is active + &StreamProtocol::new("/test/me"), + )) + .is_ok() + { + panic!("Connection to Alice should not be active!"); + } + } + } + }); // - Bob can still retrieve messages Alice sent let bob_contacts_get_messages = diff --git a/integration_tests/src/base_node_process.rs b/integration_tests/src/base_node_process.rs index e7df8006df..4a66a956a0 100644 --- a/integration_tests/src/base_node_process.rs +++ b/integration_tests/src/base_node_process.rs @@ -241,9 +241,9 @@ pub async fn spawn_base_node_with_config( } debug!(target: LOG_TARGET, "Wait for service..."); - wait_for_service(tcp_port, ServiceType::Tcp).await; - wait_for_service(udp_port, ServiceType::Udp).await; - wait_for_service(grpc_port, ServiceType::Tcp).await; + wait_for_service(tcp_port, ServiceType::Tcp, &bn_name).await; + // wait_for_service(udp_port, ServiceType::Udp, &bn_name).await; + wait_for_service(grpc_port, ServiceType::Tcp, &bn_name).await; debug!( target: LOG_TARGET, "Spawned base node: name={}; tcp_port={}; udp_port={}; grpc_port={}; is_seed_node={}", diff --git a/integration_tests/src/ffi/comms_config.rs b/integration_tests/src/ffi/comms_config.rs index 28c6273dac..74f9144719 100644 --- a/integration_tests/src/ffi/comms_config.rs +++ b/integration_tests/src/ffi/comms_config.rs @@ -44,11 +44,11 @@ impl CommsConfig { unsafe { let _public_addr_tcp = format!("/ip4/127.0.0.1/tcp/{}", tcp_port); let listen_addr_tcp = format!("/ip4/0.0.0.0/tcp/{}", tcp_port); - let _public_addr_udp = format!("/ip4/127.0.0.1/udp/{}/quic-v1", udp_port); + let public_addr_udp = format!("/ip4/127.0.0.1/udp/{}/quic-v1", udp_port); let listen_addr_udp = format!("/ip4/0.0.0.0/udp/{}/quic-v1", udp_port); ptr = ffi_import::comms_config_create( - null_mut(), + CString::new(public_addr_udp).unwrap().into_raw(), CString::new(format!("{}, {}", listen_addr_tcp, listen_addr_udp)) .unwrap() .into_raw(), diff --git a/integration_tests/src/lib.rs b/integration_tests/src/lib.rs index affca56a2b..106e9d4da9 100644 --- a/integration_tests/src/lib.rs +++ b/integration_tests/src/lib.rs @@ -64,7 +64,7 @@ pub enum ServiceType { Udp, } -pub async fn wait_for_service(port: u64, service_type: ServiceType) { +pub async fn wait_for_service(port: u64, service_type: ServiceType, process_name: &str) { // Check if we can open a socket to a port. let max_tries = 4 * 60; let mut attempts = 0; @@ -74,18 +74,35 @@ pub async fn wait_for_service(port: u64, service_type: ServiceType) { match service_type { ServiceType::Tcp => { if TcpSocket::new_v4().unwrap().connect(addr).await.is_ok() { + println!( + "Service '{:?}' on port '{}' started for '{}' after {} ms", + service_type, + port, + process_name, + attempts * 250 + ); return; } }, ServiceType::Udp => { if UdpSocket::bind(addr).await.is_ok() { + println!( + "Service '{:?}' on port '{}' started for '{}' after {} ms", + service_type, + port, + process_name, + attempts * 250 + ); return; } }, } if attempts >= max_tries { - panic!("Service {:?} on port {} never started", service_type, port); + panic!( + "Service '{:?}' on port '{}' never started for '{}'", + service_type, port, process_name + ); } tokio::time::sleep(Duration::from_millis(250)).await; diff --git a/integration_tests/src/wallet_process.rs b/integration_tests/src/wallet_process.rs index 72828c19be..67435438ef 100644 --- a/integration_tests/src/wallet_process.rs +++ b/integration_tests/src/wallet_process.rs @@ -194,9 +194,9 @@ pub async fn spawn_wallet( tokio::time::sleep(Duration::from_secs(5)).await; - wait_for_service(tcp_port, ServiceType::Tcp).await; - wait_for_service(udp_port, ServiceType::Udp).await; - wait_for_service(grpc_port, ServiceType::Tcp).await; + wait_for_service(tcp_port, ServiceType::Tcp, &wallet_name).await; + // wait_for_service(udp_port, ServiceType::Udp, &wallet_name).await; + wait_for_service(grpc_port, ServiceType::Tcp, &wallet_name).await; if let Some((_, base_node_request)) = base_node { let mut wallet_client = create_wallet_client(world, wallet_name.clone()) diff --git a/integration_tests/tests/features/WalletFFI.feature b/integration_tests/tests/features/WalletFFI.feature index e63cf3f14d..8cd8fed59b 100644 --- a/integration_tests/tests/features/WalletFFI.feature +++ b/integration_tests/tests/features/WalletFFI.feature @@ -284,3 +284,4 @@ Feature: Wallet FFI And The fee per gram stats for FFI_WALLET are 18, 37, 56 When mining node MINER mines 1 blocks And The fee per gram stats for FFI_WALLET are 1, 1, 1 + And I stop ffi wallet FFI_WALLET diff --git a/integration_tests/tests/steps/wallet_ffi_steps.rs b/integration_tests/tests/steps/wallet_ffi_steps.rs index 3a8020844c..c0dd2d1f9c 100644 --- a/integration_tests/tests/steps/wallet_ffi_steps.rs +++ b/integration_tests/tests/steps/wallet_ffi_steps.rs @@ -78,11 +78,13 @@ async fn ffi_get_emoji_id(world: &mut TariWorld, wallet: String) { #[then(expr = "I stop ffi wallet {word}")] async fn ffi_stop_wallet(world: &mut TariWorld, wallet: String) { - let address = world.get_wallet_address_base58(&wallet).await.unwrap(); - let ffi_wallet = world.ffi_wallets.get_mut(&wallet).unwrap(); - println!("Adding wallet {}", wallet); - world.stopped_wallet_addresses.insert(wallet, address); - ffi_wallet.destroy(); + if let Ok(address) = world.get_wallet_address_base58(&wallet).await { + println!("Adding wallet '{}' to stopped_wallet_addresses", wallet); + world.stopped_wallet_addresses.insert(wallet.clone(), address); + } + if let Some(ffi_wallet) = world.ffi_wallets.get_mut(&wallet) { + ffi_wallet.destroy(); + } } #[then(expr = "I retrieve the mnemonic word list for {word}")]