Skip to content

Commit

Permalink
chore: fix cucumber tests (#6469)
Browse files Browse the repository at this point in the history
Description
---
Fixes Wallet FFI tests by adding missing callback
Adds panic to places where null pointer is returned
  • Loading branch information
SWvheerden committed Aug 15, 2024
1 parent 0fa0ca4 commit d7d3f69
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions integration_tests/src/ffi/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ impl Callbacks {
);
}

pub fn callback_wallet_scanned_height(&mut self, height: u64) {
println!("wallet scanned up to height {}.", height);
}

pub fn on_basenode_state_update(&mut self, state: *mut c_void) {
*self.basenode_state_updated.lock().unwrap() += 1;
println!(
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/src/ffi/comms_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl CommsConfig {
600,
&mut error,
);
if error > 0 {
println!("comms config error {}", error);
panic!("comms config error");
}
}
Self { ptr }
}
Expand Down
1 change: 1 addition & 0 deletions integration_tests/src/ffi/ffi_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ extern "C" {
callback_transaction_validation_complete: unsafe extern "C" fn(u64, u64),
callback_saf_messages_received: unsafe extern "C" fn(),
callback_connectivity_status: unsafe extern "C" fn(u64),
callback_wallet_scanned_height: unsafe extern "C" fn(u64),
callback_base_node_state_updated: unsafe extern "C" fn(*mut TariBaseNodeState),
recovery_in_progress: *mut bool,
error_out: *mut c_int,
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/src/ffi/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl PublicKey {
ptr = ffi_import::public_key_create(bytes.get_ptr(), &mut error);
if error > 0 {
println!("public_key_create error {}", error);
panic!("public_key_create error");
}
}
Self { ptr }
Expand All @@ -63,6 +64,7 @@ impl PublicKey {
ptr = ffi_import::public_key_from_private_key(private_key.get_ptr(), &mut error);
if error > 0 {
println!("public_key_from_private_key error {}", error);
panic!("public_key_from_private_key error");
}
}
Self { ptr }
Expand All @@ -75,6 +77,7 @@ impl PublicKey {
ptr = ffi_import::public_key_from_hex(CString::new(key).unwrap().into_raw(), &mut error);
if error > 0 {
println!("public_key_from_private_key error {}", error);
panic!("public_key_from_private_key error");
}
}
Self { ptr }
Expand All @@ -91,6 +94,7 @@ impl PublicKey {
ptr = ffi_import::public_key_get_bytes(self.ptr, &mut error);
if error > 0 {
println!("public_key_get_bytes error {}", error);
panic!("public_key_get_bytes error");
}
}
FFIBytes::from_ptr(ptr)
Expand Down
1 change: 1 addition & 0 deletions integration_tests/src/ffi/transport_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl TransportConfig {
ptr = ffi_import::transport_tcp_create(listener_address, &mut error);
if error > 0 {
println!("transport_tcp_create error {}", error);
panic!("transport_tcp_create error");
}
}
Self { ptr }
Expand Down
25 changes: 25 additions & 0 deletions integration_tests/src/ffi/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ extern "C" fn callback_connectivity_status(status: u64) {
callbacks.on_connectivity_status(status);
// println!("callback_connectivity_status");
}

extern "C" fn callback_wallet_scanned_height(height: u64) {
let callbacks = Callbacks::instance();
callbacks.callback_wallet_scanned_height(height);
// println!("callback_wallet_scanned_height");
}

extern "C" fn callback_base_node_state(state: *mut TariBaseNodeState) {
let callbacks = Callbacks::instance();
callbacks.on_basenode_state_update(state);
Expand Down Expand Up @@ -169,6 +176,7 @@ impl Wallet {
let mut recovery_in_progress: bool = false;
let mut error = 0;
let ptr;

unsafe {
ptr = wallet_create(
comms_config.get_ptr(),
Expand Down Expand Up @@ -197,12 +205,14 @@ impl Wallet {
callback_transaction_validation_complete,
callback_saf_messages_received,
callback_connectivity_status,
callback_wallet_scanned_height,
callback_base_node_state,
&mut recovery_in_progress,
&mut error,
);
if error > 0 {
println!("wallet_create error {}", error);
panic!("wallet_create error");
}
}
#[allow(clippy::arc_with_non_send_sync)]
Expand Down Expand Up @@ -248,6 +258,7 @@ impl Wallet {
);
if error > 0 {
println!("wallet_set_base_node_peer error {}", error);
panic!("wallet_set_base_node_peer error");
}
}
success
Expand All @@ -260,6 +271,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_tari_address(self.ptr, &mut error);
if error > 0 {
println!("wallet_get_tari_address error {}", error);
panic!("wallet_get_tari_address error");
}
}
WalletAddress::from_ptr(ptr)
Expand All @@ -281,6 +293,7 @@ impl Wallet {
success = ffi_import::wallet_upsert_contact(self.ptr, contact.get_ptr(), &mut error);
if error > 0 {
println!("wallet_upsert_contact error {}", error);
panic!("wallet_upsert_contact error");
}
}
success
Expand All @@ -293,6 +306,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_contacts(self.ptr, &mut error);
if error > 0 {
println!("wallet_get_contacts error {}", error);
panic!("wallet_get_contacts error");
}
}
Contacts::from_ptr(ptr)
Expand All @@ -305,6 +319,7 @@ impl Wallet {
success = ffi_import::wallet_remove_contact(self.ptr, contact.get_ptr(), &mut error);
if error > 0 {
println!("wallet_remove_contact error {}", error);
panic!("wallet_remove_contact error");
}
}
success
Expand All @@ -317,6 +332,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_balance(self.ptr, &mut error);
if error > 0 {
println!("wallet_get_balance error {}", error);
panic!("wallet_get_balance error");
}
}
Balance::from_ptr(ptr)
Expand Down Expand Up @@ -346,6 +362,7 @@ impl Wallet {
);
if error > 0 {
println!("wallet_send_transaction error {}", error);
panic!("wallet_send_transaction error");
}
}
tx_id
Expand All @@ -358,6 +375,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_pending_outbound_transactions(self.ptr, &mut error);
if error > 0 {
println!("wallet_get_pending_outbound_transactions error {}", error);
panic!("wallet_get_pending_outbound_transactions error");
}
}
PendingOutboundTransactions::from_ptr(ptr)
Expand All @@ -370,6 +388,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_pending_inbound_transactions(self.ptr, &mut error);
if error > 0 {
println!("wallet_get_pending_inbound_transactions error {}", error);
panic!("wallet_get_pending_inbound_transactions error");
}
}
PendingInboundTransactions::from_ptr(ptr)
Expand All @@ -382,6 +401,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_completed_transactions(self.ptr, &mut error);
if error > 0 {
println!("wallet_get_completed_transactions error {}", error);
panic!("wallet_get_completed_transactions error");
}
}
CompletedTransactions::from_ptr(ptr)
Expand All @@ -394,6 +414,7 @@ impl Wallet {
cancelled = ffi_import::wallet_cancel_pending_transaction(self.ptr, transaction_id, &mut error);
if error > 0 {
println!("wallet_cancel_pending_transaction error {}", error);
panic!("wallet_cancel_pending_transaction error");
}
}
cancelled
Expand All @@ -406,6 +427,7 @@ impl Wallet {
request_key = ffi_import::wallet_start_txo_validation(self.ptr, &mut error);
if error > 0 {
println!("wallet_start_txo_validation error {}", error);
panic!("wallet_start_txo_validation error");
}
}
request_key
Expand All @@ -418,6 +440,7 @@ impl Wallet {
request_key = ffi_import::wallet_start_transaction_validation(self.ptr, &mut error);
if error > 0 {
println!("wallet_start_transaction_validation error {}", error);
panic!("wallet_start_transaction_validation error");
}
}
request_key
Expand All @@ -435,6 +458,7 @@ impl Wallet {
ptr = ffi_import::wallet_get_fee_per_gram_stats(self.ptr, count, &mut error);
if error > 0 {
println!("wallet_get_fee_per_gram_stats error {}", error);
panic!("wallet_get_fee_per_gram_stats error");
}
}
FeePerGramStats::from_ptr(ptr)
Expand All @@ -447,6 +471,7 @@ impl Wallet {
ptr = ffi_import::contacts_handle(self.ptr, &mut error);
if error > 0 {
println!("contacts_handle error {}", error);
panic!("contacts_handle error");
}
}
ptr
Expand Down

0 comments on commit d7d3f69

Please sign in to comment.