Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add panics to cucumber tests #6470

Merged
merged 1 commit into from
Aug 20, 2024
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
61 changes: 57 additions & 4 deletions integration_tests/src/chat_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ impl ChatClientTrait for ChatFFI {
let error_out = Box::into_raw(Box::new(0));

let result;
unsafe { result = add_chat_contact(client.0, address_ptr, error_out) }
unsafe {
result = add_chat_contact(client.0, address_ptr, error_out);
if *error_out != 0 {
panic!("Error adding contact");
}
}

Ok(result)
}
Expand All @@ -183,14 +188,29 @@ impl ChatClientTrait for ChatFFI {

let key_bytes = key.into_bytes();
let len = i32::try_from(key_bytes.len()).expect("Truncation occurred") as c_uint;
let byte_key = unsafe { chat_byte_vector_create(key_bytes.as_ptr(), len, error_out) };
let byte_key = unsafe {
let byte_key = chat_byte_vector_create(key_bytes.as_ptr(), len, error_out);
if *error_out != 0 {
panic!("Error creating byte vector");
}
byte_key
};

let data_bytes = data.into_bytes();
let len = i32::try_from(data_bytes.len()).expect("Truncation occurred") as c_uint;
let byte_data = unsafe { chat_byte_vector_create(data_bytes.as_ptr(), len, error_out) };
let byte_data = unsafe {
let byte_data = chat_byte_vector_create(data_bytes.as_ptr(), len, error_out);
if *error_out != 0 {
panic!("Error creating byte vector");
}
byte_data
};

unsafe {
add_chat_message_metadata(message_ptr, byte_key, byte_data, error_out);
if *error_out != 0 {
panic!("Error adding metadata to message");
}
Ok(*Box::from_raw(message_ptr as *mut Message))
}
}
Expand All @@ -203,6 +223,9 @@ impl ChatClientTrait for ChatFFI {

unsafe {
let result = check_online_status(client.0, address_ptr, error_out);
if *error_out != 0 {
panic!("Error checking online status");
}
Ok(ContactOnlineStatus::from_byte(result).expect("A valid u8 from FFI status"))
}
}
Expand All @@ -219,6 +242,9 @@ impl ChatClientTrait for ChatFFI {
unsafe {
let message_ptr = create_chat_message(receiver_address_ptr, sender_address_ptr, message_c_char, error_out)
as *mut Message;
if *error_out != 0 {
panic!("Error creating message");
}
Ok(*Box::from_raw(message_ptr))
}
}
Expand All @@ -234,6 +260,9 @@ impl ChatClientTrait for ChatFFI {
let limit = i32::try_from(limit).expect("Truncation occurred") as c_uint;
let page = i32::try_from(page).expect("Truncation occurred") as c_uint;
let all_messages = get_chat_messages(client.0, address_ptr, limit, page, error_out) as *mut MessagesVector;
if *error_out != 0 {
panic!("Error getting messages");
}
messages = (*all_messages).0.clone();
}

Expand All @@ -245,10 +274,19 @@ impl ChatClientTrait for ChatFFI {

let error_out = Box::into_raw(Box::new(0));
let len = i32::try_from(message_id.len()).expect("Truncation occurred") as c_uint;
let byte_vector = unsafe { chat_byte_vector_create(message_id.as_ptr(), len, error_out) };
let byte_vector = unsafe {
let byte_vector = chat_byte_vector_create(message_id.as_ptr(), len, error_out);
if *error_out != 0 {
panic!("Error creating byte vector");
}
byte_vector
};

unsafe {
let message = get_chat_message(client.0, byte_vector, error_out) as *mut Message;
if *error_out != 0 {
panic!("Error getting message");
}
let message = (*message).clone();
return Ok(message);
}
Expand All @@ -262,6 +300,9 @@ impl ChatClientTrait for ChatFFI {

unsafe {
send_chat_message(client.0, message_ptr, error_out);
if *error_out != 0 {
panic!("Error sending message");
}
}

Ok(())
Expand All @@ -274,6 +315,9 @@ impl ChatClientTrait for ChatFFI {

unsafe {
send_read_confirmation_for_message(client.0, message_ptr, error_out);
if *error_out != 0 {
panic!("Error sending read receipt");
}
}

Ok(())
Expand All @@ -286,6 +330,9 @@ impl ChatClientTrait for ChatFFI {
unsafe {
let error_out = Box::into_raw(Box::new(0));
let vector = get_conversationalists(client.0, error_out) as *mut Conversationalists;
if *error_out != 0 {
panic!("Error getting conversationalists");
}
addresses = (*vector).0.clone();
}

Expand Down Expand Up @@ -351,6 +398,9 @@ pub async fn spawn_ffi_chat_client(name: &str, seed_peers: Vec<Peer>, base_dir:
address_ptr,
error_out,
);
if *error_out != 0 {
panic!("Error creating chat client");
}
}

ChatFFI {
Expand Down Expand Up @@ -385,6 +435,9 @@ pub async fn sideload_ffi_chat_client(
adress_ptr,
error_out,
);
if *error_out != 0 {
panic!("Error sideloading chat client");
}
}

ChatFFI {
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/src/ffi/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl Balance {
available = ffi_import::balance_get_available(self.ptr, &mut error);
if error > 0 {
println!("balance_get_available error {}", error);
panic!("balance_get_available error");
}
}
available
Expand All @@ -60,6 +61,7 @@ impl Balance {
time_locked = ffi_import::balance_get_time_locked(self.ptr, &mut error);
if error > 0 {
println!("balance_get_time_locked error {}", error);
panic!("balance_get_time_locked error");
}
}
time_locked
Expand All @@ -72,6 +74,7 @@ impl Balance {
pending_incoming = ffi_import::balance_get_pending_incoming(self.ptr, &mut error);
if error > 0 {
println!("balance_get_pending_incoming error {}", error);
panic!("balance_get_pending_incoming error");
}
}
pending_incoming
Expand All @@ -84,6 +87,7 @@ impl Balance {
pending_outgoing = ffi_import::balance_get_pending_outgoing(self.ptr, &mut error);
if error > 0 {
println!("balance_get_pending_outgoing error {}", error);
panic!("balance_get_pending_outgoing error");
}
}
pending_outgoing
Expand Down
12 changes: 12 additions & 0 deletions integration_tests/src/ffi/completed_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl CompletedTransaction {
tx_id = ffi_import::completed_transaction_get_transaction_id(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_transaction_id error {}", error);
panic!("completed_transaction_get_transaction_id error");
}
}
tx_id
Expand All @@ -61,6 +62,7 @@ impl CompletedTransaction {
ptr = ffi_import::completed_transaction_get_destination_tari_address(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_destination_tari_address error {}", error);
panic!("completed_transaction_get_destination_tari_address error");
}
}
WalletAddress::from_ptr(ptr)
Expand All @@ -74,6 +76,7 @@ impl CompletedTransaction {
ptr = ffi_import::completed_transaction_get_source_tari_address(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_source_tari_address error {}", error);
panic!("completed_transaction_get_source_tari_address error");
}
}
WalletAddress::from_ptr(ptr)
Expand All @@ -86,6 +89,7 @@ impl CompletedTransaction {
ptr = ffi_import::completed_transaction_get_transaction_kernel(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_transaction_kernel error {}", error);
panic!("completed_transaction_get_transaction_kernel error");
}
}
Kernel::from_ptr(ptr)
Expand All @@ -99,6 +103,7 @@ impl CompletedTransaction {
amount = ffi_import::completed_transaction_get_amount(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_amount error {}", error);
panic!("completed_transaction_get_amount error");
}
}
amount
Expand All @@ -112,6 +117,7 @@ impl CompletedTransaction {
fee = ffi_import::completed_transaction_get_fee(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_fee error {}", error);
panic!("completed_transaction_get_fee error");
}
}
fee
Expand All @@ -125,6 +131,7 @@ impl CompletedTransaction {
timestamp = ffi_import::completed_transaction_get_timestamp(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_timestamp error {}", error);
panic!("completed_transaction_get_timestamp error");
}
}
timestamp
Expand All @@ -138,6 +145,7 @@ impl CompletedTransaction {
ptr = ffi_import::completed_transaction_get_message(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_message error {}", error);
panic!("completed_transaction_get_message error");
}
}
FFIString::from_ptr(ptr as *mut i8).as_string()
Expand All @@ -151,6 +159,7 @@ impl CompletedTransaction {
status = ffi_import::completed_transaction_get_status(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_status error {}", error);
panic!("completed_transaction_get_status error");
}
}
status
Expand All @@ -163,6 +172,7 @@ impl CompletedTransaction {
is_outbound = ffi_import::completed_transaction_is_outbound(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_is_outbound error {}", error);
panic!("completed_transaction_is_outbound error");
}
}
is_outbound
Expand All @@ -176,6 +186,7 @@ impl CompletedTransaction {
confirmations_cnt = ffi_import::completed_transaction_get_confirmations(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_confirmations error {}", error);
panic!("completed_transaction_get_confirmations error");
}
}
confirmations_cnt
Expand All @@ -189,6 +200,7 @@ impl CompletedTransaction {
reason = ffi_import::completed_transaction_get_cancellation_reason(self.ptr, &mut error);
if error > 0 {
println!("completed_transaction_get_cancellation_reason error {}", error);
panic!("completed_transaction_get_cancellation_reason error");
}
}
reason
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/src/ffi/completed_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl CompletedTransactions {
length = ffi_import::completed_transactions_get_length(self.ptr, &mut error);
if error > 0 {
println!("completed_transactions_get_length error {}", error);
panic!("completed_transactions_get_length error");
}
}
length
Expand All @@ -60,6 +61,7 @@ impl CompletedTransactions {
ptr = ffi_import::completed_transactions_get_at(self.ptr, position, &mut error);
if error > 0 {
println!("completed_transactions_get_at error {}", error);
panic!("completed_transactions_get_at error");
}
}
CompletedTransaction::from_ptr(ptr)
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/src/ffi/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Contact {
);
if error > 0 {
println!("contact_create error {}", error);
panic!("contact_create error");
}
}
Self { ptr }
Expand All @@ -70,6 +71,7 @@ impl Contact {
alias = FFIString::from_ptr(ffi_import::contact_get_alias(self.ptr, &mut error));
if error > 0 {
println!("contact_get_alias error {}", error);
panic!("contact_get_alias error");
}
}
alias.as_string()
Expand All @@ -82,6 +84,7 @@ impl Contact {
ptr = ffi_import::contact_get_tari_address(self.ptr, &mut error);
if error > 0 {
println!("contact_get_tari_address error {}", error);
panic!("contact_get_tari_address error");
}
}
WalletAddress::from_ptr(ptr)
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/src/ffi/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl Contacts {
length = ffi_import::contacts_get_length(self.ptr, &mut error);
if error > 0 {
println!("contacts_get_length error {}", error);
panic!("contacts_get_length error");
}
}
length
Expand All @@ -61,6 +62,7 @@ impl Contacts {
ptr = ffi_import::contacts_get_at(self.ptr, position, &mut error);
if error > 0 {
println!("contacts_get_at error {}", error);
panic!("contacts_get_at error");
}
}
Contact::from_ptr(ptr)
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/src/ffi/contacts_liveness_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl ContactsLivenessData {
ptr = ffi_import::liveness_data_get_public_key(self.ptr, &mut error);
if error > 0 {
println!("liveness_data_get_public_key error {}", error);
panic!("liveness_data_get_public_key error");
}
}
WalletAddress::from_ptr(ptr)
Expand All @@ -61,6 +62,7 @@ impl ContactsLivenessData {
latency = ffi_import::liveness_data_get_latency(self.ptr, &mut error);
if error > 0 {
println!("liveness_data_get_latency error {}", error);
panic!("liveness_data_get_latency error");
}
}
latency
Expand All @@ -73,6 +75,7 @@ impl ContactsLivenessData {
ptr = ffi_import::liveness_data_get_last_seen(self.ptr, &mut error);
if error > 0 {
println!("liveness_data_get_last_seen error {}", error);
panic!("liveness_data_get_last_seen error");
}
}
FFIString::from_ptr(ptr).as_string()
Expand All @@ -85,6 +88,7 @@ impl ContactsLivenessData {
message_type = ffi_import::liveness_data_get_message_type(self.ptr, &mut error);
if error > 0 {
println!("liveness_data_get_message_type error {}", error);
panic!("liveness_data_get_message_type error");
}
}
message_type
Expand All @@ -97,6 +101,7 @@ impl ContactsLivenessData {
ptr = ffi_import::liveness_data_get_online_status(self.ptr, &mut error);
if error > 0 {
println!("liveness_data_get_online_status error {}", error);
panic!("liveness_data_get_online_status error");
}
}
FFIString::from_ptr(ptr as *mut i8).as_string()
Expand Down
Loading
Loading