Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Nov 16, 2024
1 parent 38d0759 commit bd29d4b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 40 deletions.
53 changes: 28 additions & 25 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/src/base_node_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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={}",
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/src/ffi/comms_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
21 changes: 19 additions & 2 deletions integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/src/wallet_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions integration_tests/tests/features/WalletFFI.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions integration_tests/tests/steps/wallet_ffi_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down

0 comments on commit bd29d4b

Please sign in to comment.