summaryrefslogtreecommitdiff
path: root/impls
diff options
context:
space:
mode:
Diffstat (limited to 'impls')
-rw-r--r--impls/monero.rs/build.rs9
-rw-r--r--impls/monero.rs/example/src/main.rs7
-rw-r--r--impls/monero.rs/src/lib.rs463
-rw-r--r--impls/monero.rs/tests/integration_tests.rs326
4 files changed, 597 insertions, 208 deletions
diff --git a/impls/monero.rs/build.rs b/impls/monero.rs/build.rs
index 2f62780..4d3af46 100644
--- a/impls/monero.rs/build.rs
+++ b/impls/monero.rs/build.rs
@@ -1,8 +1,8 @@
+use bindgen::EnumVariation;
use std::env;
use std::fs::{self, OpenOptions};
use std::io::Write;
use std::path::PathBuf;
-use bindgen::EnumVariation;
#[cfg(unix)]
use std::os::unix::fs as unix_fs;
@@ -100,7 +100,9 @@ fn main() {
.blocklist_type("_.*")
.blocklist_function("__.*")
.layout_tests(false)
- .default_enum_style(EnumVariation::Rust { non_exhaustive: false })
+ .default_enum_style(EnumVariation::Rust {
+ non_exhaustive: false,
+ })
.derive_default(false)
.conservative_inline_namespaces()
.generate_comments(false)
@@ -129,7 +131,8 @@ fn main() {
.open(out_path.clone())
.expect("Failed to open bindings.rs");
- file.write_all(new_contents.as_bytes()).expect("Failed to write to bindings.rs");
+ file.write_all(new_contents.as_bytes())
+ .expect("Failed to write to bindings.rs");
}
}
}
diff --git a/impls/monero.rs/example/src/main.rs b/impls/monero.rs/example/src/main.rs
index 39163dc..2de8d2b 100644
--- a/impls/monero.rs/example/src/main.rs
+++ b/impls/monero.rs/example/src/main.rs
@@ -1,4 +1,4 @@
-use monero_c_rust::{NetworkType, WalletError, WalletManager, WalletConfig};
+use monero_c_rust::{NetworkType, WalletConfig, WalletError, WalletManager};
use tempfile::TempDir;
fn main() -> Result<(), WalletError> {
@@ -27,7 +27,7 @@ fn main() -> Result<(), WalletError> {
// Initialize the wallet.
let config = WalletConfig {
daemon_address: "xmr-node.cakewallet.com:18081".to_string(),
- upper_transaction_size_limit: 10000, // TODO: use sane value.
+ upper_transaction_size_limit: 0, // TODO: use sane value.
daemon_username: "".to_string(),
daemon_password: "".to_string(),
use_ssl: false,
@@ -66,7 +66,8 @@ fn main() -> Result<(), WalletError> {
// Clean up the wallet.
std::fs::remove_file(wallet_str).expect("Failed to delete test wallet");
- std::fs::remove_file(format!("{}.keys", wallet_str)).expect("Failed to delete test wallet keys");
+ std::fs::remove_file(format!("{}.keys", wallet_str))
+ .expect("Failed to delete test wallet keys");
Ok(())
}
diff --git a/impls/monero.rs/src/lib.rs b/impls/monero.rs/src/lib.rs
index 1334b7a..d8167bb 100644
--- a/impls/monero.rs/src/lib.rs
+++ b/impls/monero.rs/src/lib.rs
@@ -4,9 +4,9 @@ use std::ptr::NonNull;
use std::sync::Arc;
pub mod bindings;
-pub use bindings::WalletStatus_Ok;
-pub use bindings::WalletStatus_Error;
pub use bindings::WalletStatus_Critical;
+pub use bindings::WalletStatus_Error;
+pub use bindings::WalletStatus_Ok;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NetworkType {
@@ -171,7 +171,7 @@ impl WalletManager {
/// ```
pub fn get_status(&self, wallet_ptr: *mut c_void) -> WalletResult<()> {
if wallet_ptr.is_null() {
- return Err(WalletError::NullPointer); // Ensure NullPointer is returned for null wallet
+ return Err(WalletError::NullPointer); // Ensure NullPointer is returned for null wallet
}
unsafe {
@@ -269,9 +269,12 @@ impl WalletManager {
language: &str,
network_type: NetworkType,
) -> WalletResult<Wallet> {
- let c_path = CString::new(path).map_err(|_| WalletError::FfiError("Invalid path".to_string()))?;
- let c_password = CString::new(password).map_err(|_| WalletError::FfiError("Invalid password".to_string()))?;
- let c_language = CString::new(language).map_err(|_| WalletError::FfiError("Invalid language".to_string()))?;
+ let c_path =
+ CString::new(path).map_err(|_| WalletError::FfiError("Invalid path".to_string()))?;
+ let c_password = CString::new(password)
+ .map_err(|_| WalletError::FfiError("Invalid password".to_string()))?;
+ let c_language = CString::new(language)
+ .map_err(|_| WalletError::FfiError("Invalid language".to_string()))?;
unsafe {
let wallet_ptr = bindings::MONERO_WalletManager_createWallet(
@@ -580,8 +583,10 @@ impl WalletManager {
password: &str,
network_type: NetworkType,
) -> WalletResult<Wallet> {
- let c_path = CString::new(path).map_err(|_| WalletError::FfiError("Invalid path".to_string()))?;
- let c_password = CString::new(password).map_err(|_| WalletError::FfiError("Invalid password".to_string()))?;
+ let c_path =
+ CString::new(path).map_err(|_| WalletError::FfiError("Invalid path".to_string()))?;
+ let c_password = CString::new(password)
+ .map_err(|_| WalletError::FfiError("Invalid password".to_string()))?;
unsafe {
let wallet_ptr = bindings::MONERO_WalletManager_openWallet(
@@ -724,15 +729,14 @@ impl Wallet {
/// ```
pub fn get_address(&self, account_index: u64, address_index: u64) -> WalletResult<String> {
unsafe {
- let address_ptr = bindings::MONERO_Wallet_address(self.ptr.as_ptr(), account_index, address_index);
+ let address_ptr =
+ bindings::MONERO_Wallet_address(self.ptr.as_ptr(), account_index, address_index);
self.throw_if_error()?;
if address_ptr.is_null() {
Err(self.get_last_error())
} else {
- let address = CStr::from_ptr(address_ptr)
- .to_string_lossy()
- .into_owned();
+ let address = CStr::from_ptr(address_ptr).to_string_lossy().into_owned();
Ok(address)
}
}
@@ -796,9 +800,7 @@ impl Wallet {
let error_msg = if error_ptr.is_null() {
"Unknown error".to_string()
} else {
- CStr::from_ptr(error_ptr)
- .to_string_lossy()
- .into_owned()
+ CStr::from_ptr(error_ptr).to_string_lossy().into_owned()
};
WalletError::WalletErrorCode(status, error_msg)
@@ -813,7 +815,7 @@ impl Wallet {
pub fn throw_if_error(&self) -> WalletResult<()> {
let status_result = self.manager.get_status(self.ptr.as_ptr());
if status_result.is_err() {
- return status_result; // Return the error if the status is not OK.
+ return status_result; // Return the error if the status is not OK.
}
Ok(())
}
@@ -845,10 +847,14 @@ impl Wallet {
let balance = bindings::MONERO_Wallet_balance(self.ptr.as_ptr(), account_index);
self.throw_if_error()?;
- let unlocked_balance = bindings::MONERO_Wallet_unlockedBalance(self.ptr.as_ptr(), account_index);
+ let unlocked_balance =
+ bindings::MONERO_Wallet_unlockedBalance(self.ptr.as_ptr(), account_index);
self.throw_if_error()?;
- Ok(GetBalance { balance, unlocked_balance })
+ Ok(GetBalance {
+ balance,
+ unlocked_balance,
+ })
}
}
@@ -881,7 +887,8 @@ impl Wallet {
/// fs::remove_file(format!("{}.keys", wallet_str)).expect("Failed to delete test wallet keys");
/// ```
pub fn create_account(&self, label: &str) -> WalletResult<()> {
- let c_label = CString::new(label).map_err(|_| WalletError::FfiError("Invalid label".to_string()))?;
+ let c_label =
+ CString::new(label).map_err(|_| WalletError::FfiError("Invalid label".to_string()))?;
unsafe {
bindings::MONERO_Wallet_addSubaddressAccount(self.ptr.as_ptr(), c_label.as_ptr());
@@ -943,7 +950,8 @@ impl Wallet {
};
let balance = bindings::MONERO_Wallet_balance(self.ptr.as_ptr(), i);
- let unlocked_balance = bindings::MONERO_Wallet_unlockedBalance(self.ptr.as_ptr(), i);
+ let unlocked_balance =
+ bindings::MONERO_Wallet_unlockedBalance(self.ptr.as_ptr(), i);
accounts.push(Account {
index: i,
@@ -1059,15 +1067,15 @@ impl Wallet {
let result = bindings::MONERO_Wallet_init(
self.ptr.as_ptr(),
- c_daemon_address.as_ptr(),
+ c_daemon_address.into_raw(),
config.upper_transaction_size_limit,
- c_daemon_username.as_ptr(),
- c_daemon_password.as_ptr(),
+ c_daemon_username.into_raw(),
+ c_daemon_password.into_raw(),
config.use_ssl,
config.light_wallet,
- c_proxy_address.as_ptr(),
+ c_proxy_address.into_raw(),
);
-
+
if result {
Ok(())
} else {
@@ -1145,7 +1153,7 @@ impl Wallet {
pub fn refresh_async(&self) -> WalletResult<Refreshed> {
unsafe {
bindings::MONERO_Wallet_refreshAsync(self.ptr.as_ptr());
- return Ok(Refreshed)
+ return Ok(Refreshed);
}
}
@@ -1155,22 +1163,32 @@ impl Wallet {
///
/// * `WalletResult<Transfer>` - On success, returns a `Transfer` struct containing transaction details.
/// On failure, returns a `WalletError`.
- pub fn transfer(&self, account_index: u32, destinations: Vec<Destination>, get_tx_key: bool, sweep_all: bool) -> WalletResult<Transfer> {
+ pub fn transfer(
+ &self,
+ account_index: u32,
+ destinations: Vec<Destination>,
+ get_tx_key: bool,
+ sweep_all: bool,
+ ) -> WalletResult<Transfer> {
// Define separators
let separator = ";";
- let separator_c = CString::new(separator).map_err(|_| WalletError::FfiError("Invalid separator".to_string()))?;
+ let separator_c = CString::new(separator)
+ .map_err(|_| WalletError::FfiError("Invalid separator".to_string()))?;
// Concatenate destination addresses and amounts.
let addresses: Vec<String> = destinations.iter().map(|d| d.address.clone()).collect();
let address_list = addresses.join(separator);
- let c_address_list = CString::new(address_list).map_err(|_| WalletError::FfiError("Invalid address list".to_string()))?;
+ let c_address_list = CString::new(address_list)
+ .map_err(|_| WalletError::FfiError("Invalid address list".to_string()))?;
let amounts: Vec<String> = destinations.iter().map(|d| d.amount.to_string()).collect();
let amount_list = amounts.join(separator);
- let c_amount_list = CString::new(amount_list).map_err(|_| WalletError::FfiError("Invalid amount list".to_string()))?;
+ let c_amount_list = CString::new(amount_list)
+ .map_err(|_| WalletError::FfiError("Invalid amount list".to_string()))?;
// TODO: Payment IDs.
- let payment_id = CString::new("").map_err(|_| WalletError::FfiError("Invalid payment_id".to_string()))?;
+ let payment_id = CString::new("")
+ .map_err(|_| WalletError::FfiError("Invalid payment_id".to_string()))?;
let mixin_count = 16;
// Pending transaction priority - default to 0 (Default)
@@ -1180,10 +1198,12 @@ impl Wallet {
let subaddr_account = account_index;
// TODO: Preferred inputs.
- let c_preferred_inputs = CString::new("").map_err(|_| WalletError::FfiError("Invalid preferred inputs".to_string()))?;
+ let c_preferred_inputs = CString::new("")
+ .map_err(|_| WalletError::FfiError("Invalid preferred inputs".to_string()))?;
// Separator for preferred inputs
- let preferred_inputs_separator = CString::new("").map_err(|_| WalletError::FfiError("Invalid preferred inputs separator".to_string()))?;
+ let preferred_inputs_separator = CString::new("")
+ .map_err(|_| WalletError::FfiError("Invalid preferred inputs separator".to_string()))?;
unsafe {
// Create the transaction with multiple destinations.
@@ -1212,7 +1232,9 @@ impl Wallet {
// Get the transaction ID.
let txid_ptr = bindings::MONERO_PendingTransaction_txid(tx_ptr, separator_c.as_ptr());
if txid_ptr.is_null() {
- return Err(WalletError::FfiError("Failed to get transaction ID".to_string()));
+ return Err(WalletError::FfiError(
+ "Failed to get transaction ID".to_string(),
+ ));
}
let txid = CStr::from_ptr(txid_ptr).to_string_lossy().into_owned();
@@ -1221,8 +1243,10 @@ impl Wallet {
// Optionally get the transaction key.
let tx_key = if get_tx_key {
- let c_txid = CString::new(txid.clone()).map_err(|_| WalletError::FfiError("Invalid txid".to_string()))?;
- let tx_key_ptr = bindings::MONERO_Wallet_getTxKey(self.ptr.as_ptr(), c_txid.as_ptr());
+ let c_txid = CString::new(txid.clone())
+ .map_err(|_| WalletError::FfiError("Invalid txid".to_string()))?;
+ let tx_key_ptr =
+ bindings::MONERO_Wallet_getTxKey(self.ptr.as_ptr(), c_txid.as_ptr());
if tx_key_ptr.is_null() {
None
} else {
@@ -1236,12 +1260,12 @@ impl Wallet {
//
// TODO: Make submission optional.
let tx_ptr_as_i8 = tx_ptr as *const i8;
- let submit_result = bindings::MONERO_Wallet_submitTransaction(
- self.ptr.as_ptr(),
- tx_ptr_as_i8,
- );
+ let submit_result =
+ bindings::MONERO_Wallet_submitTransaction(self.ptr.as_ptr(), tx_ptr_as_i8);
if !submit_result {
- return Err(WalletError::FfiError("Failed to submit transaction".to_string()));
+ return Err(WalletError::FfiError(
+ "Failed to submit transaction".to_string(),
+ ));
}
Ok(Transfer {
@@ -1256,17 +1280,27 @@ impl Wallet {
/// Sweep all funds from the specific account to the specified destination.
///
/// TODO: Example / docs-tests.
- pub fn sweep_all(&self, account_index: u32, destination: Destination, get_tx_key: bool) -> WalletResult<Transfer> {
+ pub fn sweep_all(
+ &self,
+ account_index: u32,
+ destination: Destination,
+ get_tx_key: bool,
+ ) -> WalletResult<Transfer> {
// Convert the destination address to a CString.
- let c_address = CString::new(destination.address.clone()).map_err(|_| WalletError::FfiError("Invalid address".to_string()))?;
+ let c_address = CString::new(destination.address.clone())
+ .map_err(|_| WalletError::FfiError("Invalid address".to_string()))?;
// Placeholder values for fields not needed in sweep_all.
- let empty_separator = CString::new("").map_err(|_| WalletError::FfiError("Invalid separator".to_string()))?;
- let payment_id = CString::new("").map_err(|_| WalletError::FfiError("Invalid payment_id".to_string()))?;
+ let empty_separator =
+ CString::new("").map_err(|_| WalletError::FfiError("Invalid separator".to_string()))?;
+ let payment_id = CString::new("")
+ .map_err(|_| WalletError::FfiError("Invalid payment_id".to_string()))?;
let mixin_count = 16;
let pending_tx_priority = bindings::Priority_Default;
- let c_preferred_inputs = CString::new("").map_err(|_| WalletError::FfiError("Invalid preferred inputs".to_string()))?;
- let preferred_inputs_separator = CString::new("").map_err(|_| WalletError::FfiError("Invalid preferred inputs separator".to_string()))?;
+ let c_preferred_inputs = CString::new("")
+ .map_err(|_| WalletError::FfiError("Invalid preferred inputs".to_string()))?;
+ let preferred_inputs_separator = CString::new("")
+ .map_err(|_| WalletError::FfiError("Invalid preferred inputs separator".to_string()))?;
unsafe {
// Create the sweep transaction.
@@ -1293,9 +1327,12 @@ impl Wallet {
}
// Get the transaction ID.
- let txid_ptr = bindings::MONERO_PendingTransaction_txid(tx_ptr, empty_separator.as_ptr());
+ let txid_ptr =
+ bindings::MONERO_PendingTransaction_txid(tx_ptr, empty_separator.as_ptr());
if txid_ptr.is_null() {
- return Err(WalletError::FfiError("Failed to get transaction ID".to_string()));
+ return Err(WalletError::FfiError(
+ "Failed to get transaction ID".to_string(),
+ ));
}
let txid = CStr::from_ptr(txid_ptr).to_string_lossy().into_owned();
@@ -1304,8 +1341,10 @@ impl Wallet {
// Optionally get the transaction key.
let tx_key = if get_tx_key {
- let c_txid = CString::new(txid.clone()).map_err(|_| WalletError::FfiError("Invalid txid".to_string()))?;
- let tx_key_ptr = bindings::MONERO_Wallet_getTxKey(self.ptr.as_ptr(), c_txid.as_ptr());
+ let c_txid = CString::new(txid.clone())
+ .map_err(|_| WalletError::FfiError("Invalid txid".to_string()))?;
+ let tx_key_ptr =
+ bindings::MONERO_Wallet_getTxKey(self.ptr.as_ptr(), c_txid.as_ptr());
if tx_key_ptr.is_null() {
None
} else {
@@ -1319,12 +1358,12 @@ impl Wallet {
//
// TODO: Make submission optional.
let tx_ptr_as_i8 = tx_ptr as *const i8;
- let submit_result = bindings::MONERO_Wallet_submitTransaction(
- self.ptr.as_ptr(),
- tx_ptr_as_i8,
- );
+ let submit_result =
+ bindings::MONERO_Wallet_submitTransaction(self.ptr.as_ptr(), tx_ptr_as_i8);
if !submit_result {
- return Err(WalletError::FfiError("Failed to submit sweep transaction".to_string()));
+ return Err(WalletError::FfiError(
+ "Failed to submit sweep transaction".to_string(),
+ ));
}
Ok(Transfer {
@@ -1419,7 +1458,9 @@ impl Wallet {
})
} else {
// Retrieve the last error.
- Err(WalletError::FfiError("Transaction key is invalid.".to_string()))
+ Err(WalletError::FfiError(
+ "Transaction key is invalid.".to_string(),
+ ))
}
}
}
@@ -1439,13 +1480,18 @@ impl Drop for Wallet {
}
#[cfg(test)]
-use tempfile::TempDir;
-#[cfg(test)]
use std::fs;
+#[cfg(test)]
+use tempfile::TempDir;
#[cfg(test)]
fn check_and_delete_existing_wallets(temp_dir: &TempDir) -> std::io::Result<()> {
- let test_wallet_names = &["test_wallet", "mainnet_wallet", "testnet_wallet", "stagenet_wallet"];
+ let test_wallet_names = &[
+ "test_wallet",
+ "mainnet_wallet",
+ "testnet_wallet",
+ "stagenet_wallet",
+ ];
for name in test_wallet_names {
let wallet_file = temp_dir.path().join(name);
@@ -1480,9 +1526,12 @@ fn test_wallet_manager_creation() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet_result = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet);
+ let wallet_result =
+ manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet);
assert!(wallet_result.is_ok(), "WalletManager creation failed");
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -1493,14 +1542,19 @@ fn test_wallet_creation() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet);
assert!(wallet.is_ok(), "Failed to create wallet");
let wallet = wallet.unwrap();
- assert!(wallet.is_deterministic().is_ok(), "Wallet creation seems to have failed");
+ assert!(
+ wallet.is_deterministic().is_ok(),
+ "Wallet creation seems to have failed"
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -1510,7 +1564,9 @@ fn test_get_seed() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a new wallet.
let wallet = manager
@@ -1519,13 +1575,24 @@ fn test_get_seed() {
// Test getting seed with no offset (None).
let result = wallet.get_seed(None);
- assert!(result.is_ok(), "Failed to get seed without offset: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to get seed without offset: {:?}",
+ result.err()
+ );
assert!(!result.unwrap().is_empty(), "Seed without offset is empty");
// Test getting seed with a specific offset (Some("offset")).
let result_with_offset = wallet.get_seed(Some("offset"));
- assert!(result_with_offset.is_ok(), "Failed to get seed with offset: {:?}", result_with_offset.err());
- assert!(!result_with_offset.unwrap().is_empty(), "Seed with offset is empty");
+ assert!(
+ result_with_offset.is_ok(),
+ "Failed to get seed with offset: {:?}",
+ result_with_offset.err()
+ );
+ assert!(
+ !result_with_offset.unwrap().is_empty(),
+ "Seed with offset is empty"
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -1535,9 +1602,13 @@ fn test_get_address() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet).expect("Failed to create wallet");
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ .expect("Failed to create wallet");
let result = wallet.get_address(0, 0);
assert!(result.is_ok(), "Failed to get address: {:?}", result.err());
assert!(!result.unwrap().is_empty(), "Address is empty");
@@ -1550,11 +1621,19 @@ fn test_is_deterministic() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet).expect("Failed to create wallet");
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ .expect("Failed to create wallet");
let result = wallet.is_deterministic();
- assert!(result.is_ok(), "Failed to check if wallet is deterministic: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to check if wallet is deterministic: {:?}",
+ result.err()
+ );
assert!(result.unwrap(), "Wallet should be deterministic");
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -1572,7 +1651,9 @@ fn test_wallet_creation_with_different_networks() {
for (name, net_type) in wallets {
let wallet_path = temp_dir.path().join(name);
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager.create_wallet(wallet_str, "password", "English", net_type);
assert!(wallet.is_ok(), "Failed to create wallet: {}", name);
@@ -1586,7 +1667,10 @@ fn test_restore_mnemonic_success() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string").to_string();
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string")
+ .to_string();
// Example mnemonic seed (ensure this is a valid seed for your context).
let mnemonic_seed = "hemlock jubilee eden hacksaw boil superior inroads epoxy exhale orders cavernous second brunt saved richly lower upgrade hitched launching deepest mostly playful layout lower eden".to_string();
@@ -1596,11 +1680,15 @@ fn test_restore_mnemonic_success() {
"password".to_string(),
mnemonic_seed,
NetworkType::Mainnet,
- 0, // Restore from the beginning of the blockchain.
- 1, // Default KDF rounds.
+ 0, // Restore from the beginning of the blockchain.
+ 1, // Default KDF rounds.
"".to_string(), // No seed offset.
);
- assert!(wallet.is_ok(), "Failed to restore wallet: {:?}", wallet.err());
+ assert!(
+ wallet.is_ok(),
+ "Failed to restore wallet: {:?}",
+ wallet.err()
+ );
// Clean up wallet files.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -1612,7 +1700,10 @@ fn test_restore_polyseed_success() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string").to_string();
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string")
+ .to_string();
let polyseed = "capital chief route liar question fix clutch water outside pave hamster occur always learn license knife".to_string();
let restored_wallet = manager.restore_polyseed(
@@ -1620,12 +1711,16 @@ fn test_restore_polyseed_success() {
"password".to_string(),
polyseed.clone(),
NetworkType::Mainnet,
- 0, // Restore from the beginning of the blockchain.
- 1, // Default KDF rounds.
+ 0, // Restore from the beginning of the blockchain.
+ 1, // Default KDF rounds.
"".to_string(), // No seed offset.
- true, // Create a new wallet.
+ true, // Create a new wallet.
+ );
+ assert!(
+ restored_wallet.is_ok(),
+ "Failed to restore wallet from polyseed: {:?}",
+ restored_wallet.err()
);
- assert!(restored_wallet.is_ok(), "Failed to restore wallet from polyseed: {:?}", restored_wallet.err());
// Clean up wallet files.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -1637,7 +1732,9 @@ fn test_generate_from_keys_unit() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("generated_wallet_unit");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Test parameters.
//
@@ -1662,7 +1759,11 @@ fn test_generate_from_keys_unit() {
network_type,
kdf_rounds,
);
- assert!(result.is_ok(), "Failed to generate wallet from keys: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to generate wallet from keys: {:?}",
+ result.err()
+ );
// Clean up wallet files.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -1673,13 +1774,22 @@ fn test_multiple_address_generation() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet).expect("Failed to create wallet");
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ .expect("Failed to create wallet");
for i in 0..5 {
let result = wallet.get_address(0, i);
- assert!(result.is_ok(), "Failed to get address {}: {:?}", i, result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to get address {}: {:?}",
+ i,
+ result.err()
+ );
assert!(!result.unwrap().is_empty(), "Address {} is empty", i);
}
@@ -1708,7 +1818,7 @@ fn test_wallet_error_display() {
WalletError::WalletErrorCode(code, msg) => {
assert_eq!(code, 2);
assert_eq!(msg, "Sample wallet error");
- },
+ }
_ => panic!("Expected WalletErrorCode variant"),
}
}
@@ -1718,7 +1828,9 @@ fn test_wallet_status() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a wallet to use for status checking
let wallet = manager
@@ -1727,7 +1839,11 @@ fn test_wallet_status() {
// Check the status of the wallet, expecting it to be OK
let status_result = manager.get_status(wallet.ptr.as_ptr());
- assert!(status_result.is_ok(), "Failed to get status: {:?}", status_result.err());
+ assert!(
+ status_result.is_ok(),
+ "Failed to get status: {:?}",
+ status_result.err()
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -1737,10 +1853,13 @@ fn test_open_wallet() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a wallet to be opened later
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
.expect("Failed to create wallet");
// Drop the wallet so it can be opened later
@@ -1748,7 +1867,11 @@ fn test_open_wallet() {
// Try to open the wallet
let open_result = manager.open_wallet(wallet_str, "password", NetworkType::Mainnet);
- assert!(open_result.is_ok(), "Failed to open wallet: {:?}", open_result.err());
+ assert!(
+ open_result.is_ok(),
+ "Failed to open wallet: {:?}",
+ open_result.err()
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -1758,12 +1881,20 @@ fn test_get_balance() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet).unwrap();
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ .unwrap();
let balance_result = wallet.get_balance(0);
- assert!(balance_result.is_ok(), "Failed to get balance: {:?}", balance_result.err());
+ assert!(
+ balance_result.is_ok(),
+ "Failed to get balance: {:?}",
+ balance_result.err()
+ );
let _balance = balance_result.unwrap();
// assert!(_balance.balance >= 0, "Balance should be non-negative");
@@ -1778,7 +1909,9 @@ fn test_create_account() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a wallet.
let wallet = manager
@@ -1787,7 +1920,11 @@ fn test_create_account() {
// Create a new account.
let result = wallet.create_account("Test Account");
- assert!(result.is_ok(), "Failed to create account: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to create account: {:?}",
+ result.err()
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -1797,13 +1934,21 @@ fn test_get_accounts() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet).expect("Failed to create wallet");
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ .expect("Failed to create wallet");
// Add two accounts for testing
- wallet.create_account("Test Account 1").expect("Failed to create account 1");
- wallet.create_account("Test Account 2").expect("Failed to create account 2");
+ wallet
+ .create_account("Test Account 1")
+ .expect("Failed to create account 1");
+ wallet
+ .create_account("Test Account 2")
+ .expect("Failed to create account 2");
// Retrieve all accounts
let accounts = wallet.get_accounts().expect("Failed to retrieve accounts");
@@ -1822,19 +1967,30 @@ fn test_close_wallet() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a wallet.
- let mut wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ let mut wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
.expect("Failed to create wallet");
// Close the wallet.
let close_result = wallet.close_wallet();
- assert!(close_result.is_ok(), "Failed to close wallet: {:?}", close_result.err());
+ assert!(
+ close_result.is_ok(),
+ "Failed to close wallet: {:?}",
+ close_result.err()
+ );
// Attempt to close the wallet again.
let close_again_result = wallet.close_wallet();
- assert!(close_again_result.is_ok(), "Failed to close wallet a second time: {:?}", close_again_result.err());
+ assert!(
+ close_again_result.is_ok(),
+ "Failed to close wallet a second time: {:?}",
+ close_again_result.err()
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -1858,10 +2014,13 @@ fn test_init_success() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a wallet.
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
.expect("Failed to create wallet");
// Define initialization configuration.
@@ -1877,7 +2036,11 @@ fn test_init_success() {
// Initialize the wallet.
let init_result = wallet.init(config);
- assert!(init_result.is_ok(), "Failed to initialize wallet: {:?}", init_result.err());
+ assert!(
+ init_result.is_ok(),
+ "Failed to initialize wallet: {:?}",
+ init_result.err()
+ );
// Clean up wallet files.
fs::remove_file(wallet_str).expect("Failed to delete test wallet");
@@ -1893,7 +2056,9 @@ fn test_refresh_success() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let wallet = manager
@@ -1916,12 +2081,20 @@ fn test_refresh_success() {
println!("Initializing the wallet...");
let init_result = wallet.init(config);
- assert!(init_result.is_ok(), "Failed to initialize wallet: {:?}", init_result.err());
+ assert!(
+ init_result.is_ok(),
+ "Failed to initialize wallet: {:?}",
+ init_result.err()
+ );
// Perform a refresh operation after initialization.
println!("Refreshing the wallet...");
let refresh_result = wallet.refresh();
- assert!(refresh_result.is_ok(), "Failed to refresh wallet: {:?}", refresh_result.err());
+ assert!(
+ refresh_result.is_ok(),
+ "Failed to refresh wallet: {:?}",
+ refresh_result.err()
+ );
// Clean up wallet files.
fs::remove_file(wallet_str).expect("Failed to delete test wallet");
@@ -1935,7 +2108,9 @@ fn test_set_seed_language() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet_set_seed_language");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a new wallet.
let wallet = manager
@@ -1944,7 +2119,11 @@ fn test_set_seed_language() {
// Set the seed language to Spanish.
let result = wallet.set_seed_language("Spanish");
- assert!(result.is_ok(), "Failed to set seed language: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to set seed language: {:?}",
+ result.err()
+ );
// Optionally, retrieve the seed language to verify it was set correctly.
// This requires implementing a corresponding `get_seed_language` method.
@@ -1953,12 +2132,14 @@ fn test_set_seed_language() {
teardown(&temp_dir).expect("Failed to clean up after test");
}
-
#[test]
fn test_check_tx_key() {
let temp_dir = TempDir::new().expect("Failed to create temporary directory");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string").to_string();
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string")
+ .to_string();
let mnemonic_seed = "capital chief route liar question fix clutch water outside pave hamster occur always learn license knife".to_string();
let passphrase = "".to_string();
@@ -1974,16 +2155,20 @@ fn test_check_tx_key() {
0,
1,
passphrase.clone(),
- true
+ true,
)
.expect("Failed to restore wallet from polyseed");
// Print the primary address.
- println!("Primary address: {}", wallet.get_address(0, 0).expect("Failed to get address"));
+ println!(
+ "Primary address: {}",
+ wallet.get_address(0, 0).expect("Failed to get address")
+ );
// Valid transaction details.
let valid_txid = "b3f1b71f5127f9d655e58f7a2b324a64bfbc5a3ea1ce8846a0f4c51cbcb87ea6".to_string();
- let valid_tx_key = "48ef9d8b772c4f5097e29a4ba413605497d978c74e879fda67545dddff312b0a".to_string();
+ let valid_tx_key =
+ "48ef9d8b772c4f5097e29a4ba413605497d978c74e879fda67545dddff312b0a".to_string();
let valid_address = "465cUW8wTMSCV8oVVh7CuWWHs7yeB1oxhNPrsEM5FKSqadTXmobLqsNEtRnyGsbN1rbDuBtWdtxtXhTJda1Lm9vcH2ZdrD1".to_string();
// Check the transaction key.
@@ -1999,24 +2184,31 @@ fn test_check_tx_key() {
match valid_check {
Ok(check) => {
assert!(check.valid, "Valid transaction key should be valid.");
- assert!(check.error.is_none(), "There should be no error for valid transaction key.");
+ assert!(
+ check.error.is_none(),
+ "There should be no error for valid transaction key."
+ );
println!("Valid transaction key check passed.");
- },
+ }
Err(e) => {
panic!("Error checking valid transaction key: {:?}", e);
- },
+ }
}
// Clean up wallet files.
fs::remove_file(&wallet_path).expect("Failed to delete test wallet");
- fs::remove_file(format!("{}.keys", wallet_path.display())).expect("Failed to delete test wallet keys");
+ fs::remove_file(format!("{}.keys", wallet_path.display()))
+ .expect("Failed to delete test wallet keys");
}
#[test]
fn test_invalid_check_tx_key() {
let temp_dir = TempDir::new().expect("Failed to create temporary directory");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string").to_string();
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string")
+ .to_string();
let mnemonic_seed = "capital chief route liar question fix clutch water outside pave hamster occur always learn license knife".to_string();
let passphrase = "".to_string();
@@ -2032,12 +2224,15 @@ fn test_invalid_check_tx_key() {
0,
1,
passphrase.clone(),
- true
+ true,
)
.expect("Failed to restore wallet from polyseed");
// Print the primary address.
- println!("Primary address: {}", wallet.get_address(0, 0).expect("Failed to get address"));
+ println!(
+ "Primary address: {}",
+ wallet.get_address(0, 0).expect("Failed to get address")
+ );
// Invalid transaction details.
let invalid_txid = "invalid_tx_id".to_string();
@@ -2057,15 +2252,19 @@ fn test_invalid_check_tx_key() {
match invalid_check {
Ok(check) => {
assert!(!check.valid, "Invalid transaction key should be invalid.");
- assert!(check.error.is_some(), "There should be an error message for invalid transaction key.");
+ assert!(
+ check.error.is_some(),
+ "There should be an error message for invalid transaction key."
+ );
println!("Invalid transaction key check correctly identified as invalid.");
- },
+ }
Err(e) => {
println!("Expected error for invalid transaction key: {:?}", e);
- },
+ }
}
// Clean up wallet files.
fs::remove_file(&wallet_path).expect("Failed to delete test wallet");
- fs::remove_file(format!("{}.keys", wallet_path.display())).expect("Failed to delete test wallet keys");
-} \ No newline at end of file
+ fs::remove_file(format!("{}.keys", wallet_path.display()))
+ .expect("Failed to delete test wallet keys");
+}
diff --git a/impls/monero.rs/tests/integration_tests.rs b/impls/monero.rs/tests/integration_tests.rs
index 079a9a6..0b425a6 100644
--- a/impls/monero.rs/tests/integration_tests.rs
+++ b/impls/monero.rs/tests/integration_tests.rs
@@ -1,4 +1,6 @@
-use monero_c_rust::{WalletManager, NetworkType, WalletConfig, WalletError, WalletResult, WalletStatus_Ok};
+use monero_c_rust::{
+ NetworkType, WalletConfig, WalletError, WalletManager, WalletResult, WalletStatus_Ok,
+};
use std::fs;
use std::sync::Arc;
use std::time::Instant;
@@ -22,7 +24,10 @@ fn check_and_delete_existing_wallets(temp_dir: &TempDir) -> std::io::Result<()>
// Delete wallet file if it exists.
if wallet_file.exists() {
if let Err(e) = fs::remove_file(&wallet_file) {
- println!("Warning: Failed to delete wallet file {:?}: {}", wallet_file, e);
+ println!(
+ "Warning: Failed to delete wallet file {:?}: {}",
+ wallet_file, e
+ );
} else {
println!("Deleted existing wallet file: {:?}", wallet_file);
}
@@ -40,7 +45,10 @@ fn check_and_delete_existing_wallets(temp_dir: &TempDir) -> std::io::Result<()>
// Delete address file if it exists.
if address_file.exists() {
if let Err(e) = fs::remove_file(&address_file) {
- println!("Warning: Failed to delete address file {:?}: {}", address_file, e);
+ println!(
+ "Warning: Failed to delete address file {:?}: {}",
+ address_file, e
+ );
} else {
println!("Deleted existing address file: {:?}", address_file);
}
@@ -86,10 +94,16 @@ fn test_wallet_manager_creation() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
- let wallet_result = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet);
- assert!(wallet_result.is_ok(), "WalletManager creation seems to have failed");
+ let wallet_result =
+ manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet);
+ assert!(
+ wallet_result.is_ok(),
+ "WalletManager creation seems to have failed"
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -99,12 +113,17 @@ fn test_wallet_creation() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet);
assert!(wallet.is_ok(), "Failed to create wallet");
let wallet = wallet.unwrap();
- assert!(wallet.is_deterministic().is_ok(), "Wallet creation seems to have failed");
+ assert!(
+ wallet.is_deterministic().is_ok(),
+ "Wallet creation seems to have failed"
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -114,7 +133,10 @@ fn test_restore_mnemonic_integration() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string").to_string();
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string")
+ .to_string();
let mnemonic_seed = "hemlock jubilee eden hacksaw boil superior inroads epoxy exhale orders cavernous second brunt saved richly lower upgrade hitched launching deepest mostly playful layout lower eden".to_string();
let restored_wallet = manager.restore_mnemonic(
@@ -122,21 +144,35 @@ fn test_restore_mnemonic_integration() {
"password".to_string(),
mnemonic_seed,
NetworkType::Mainnet,
- 0, // Restore from the beginning of the blockchain.
- 1, // Default KDF rounds.
+ 0, // Restore from the beginning of the blockchain.
+ 1, // Default KDF rounds.
"".to_string(), // No seed offset.
);
- assert!(restored_wallet.is_ok(), "Failed to restore wallet: {:?}", restored_wallet.err());
+ assert!(
+ restored_wallet.is_ok(),
+ "Failed to restore wallet: {:?}",
+ restored_wallet.err()
+ );
// Check that the wallet is deterministic.
let wallet = restored_wallet.unwrap();
- assert!(wallet.is_deterministic().is_ok(), "Restored wallet seems to have failed");
- assert!(wallet.is_deterministic().unwrap(), "Restored wallet should be deterministic");
+ assert!(
+ wallet.is_deterministic().is_ok(),
+ "Restored wallet seems to have failed"
+ );
+ assert!(
+ wallet.is_deterministic().unwrap(),
+ "Restored wallet should be deterministic"
+ );
// Optionally, verify the address if applicable.
let address_result = wallet.get_address(0, 0);
- assert!(address_result.is_ok(), "Failed to retrieve address: {:?}", address_result.err());
+ assert!(
+ address_result.is_ok(),
+ "Failed to retrieve address: {:?}",
+ address_result.err()
+ );
let address = address_result.unwrap();
assert_eq!(
address,
@@ -154,7 +190,10 @@ fn test_restore_polyseed_integration() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string").to_string();
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string")
+ .to_string();
let mnemonic_seed = "capital chief route liar question fix clutch water outside pave hamster occur always learn license knife".to_string();
let restored_wallet = manager.restore_polyseed(
@@ -162,22 +201,36 @@ fn test_restore_polyseed_integration() {
"password".to_string(),
mnemonic_seed,
NetworkType::Mainnet,
- 0, // Restore from the beginning of the blockchain.
- 1, // Default KDF rounds.
+ 0, // Restore from the beginning of the blockchain.
+ 1, // Default KDF rounds.
"".to_string(), // No seed offset.
- true, // Create a new wallet.
+ true, // Create a new wallet.
);
- assert!(restored_wallet.is_ok(), "Failed to restore wallet: {:?}", restored_wallet.err());
+ assert!(
+ restored_wallet.is_ok(),
+ "Failed to restore wallet: {:?}",
+ restored_wallet.err()
+ );
// Check that the wallet is deterministic.
let wallet = restored_wallet.unwrap();
- assert!(wallet.is_deterministic().is_ok(), "Restored wallet seems to have failed");
- assert!(wallet.is_deterministic().unwrap(), "Restored wallet should be deterministic");
+ assert!(
+ wallet.is_deterministic().is_ok(),
+ "Restored wallet seems to have failed"
+ );
+ assert!(
+ wallet.is_deterministic().unwrap(),
+ "Restored wallet should be deterministic"
+ );
// Optionally, verify the address if applicable.
let address_result = wallet.get_address(0, 0);
- assert!(address_result.is_ok(), "Failed to retrieve address: {:?}", address_result.err());
+ assert!(
+ address_result.is_ok(),
+ "Failed to retrieve address: {:?}",
+ address_result.err()
+ );
let address = address_result.unwrap();
assert_eq!(
address,
@@ -195,7 +248,9 @@ fn test_generate_from_keys_integration() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager.generate_from_keys(
wallet_str.to_string(),
@@ -209,7 +264,11 @@ fn test_generate_from_keys_integration() {
1, // KDF rounds.
);
- assert!(wallet.is_ok(), "Failed to generate wallet from keys: {:?}", wallet.err());
+ assert!(
+ wallet.is_ok(),
+ "Failed to generate wallet from keys: {:?}",
+ wallet.err()
+ );
// Verify that the wallet was generated correctly.
let wallet = wallet.expect("Failed to create wallet");
@@ -224,14 +283,21 @@ fn test_generate_from_keys_integration() {
// The address should be "45wsWad9...".
let address_result = wallet.get_address(0, 0);
- assert!(address_result.is_ok(), "Failed to get address: {:?}", address_result.err());
+ assert!(
+ address_result.is_ok(),
+ "Failed to get address: {:?}",
+ address_result.err()
+ );
let address = address_result.unwrap();
assert_eq!(address, "45wsWad9EwZgF3VpxQumrUCRaEtdyyh6NG8sVD3YRVVJbK1jkpJ3zq8WHLijVzodQ22LxwkdWx7fS2a6JzaRGzkNU8K2Dhi");
// Get the seed. It should be "hemlock jubilee...".
let seed_result = wallet.get_seed(None);
- assert!(seed_result.is_ok(), "Failed to get seed: {:?}",
- seed_result.err());
+ assert!(
+ seed_result.is_ok(),
+ "Failed to get seed: {:?}",
+ seed_result.err()
+ );
let seed = seed_result.unwrap();
assert_eq!(seed, "hemlock jubilee eden hacksaw boil superior inroads epoxy exhale orders cavernous second brunt saved richly lower upgrade hitched launching deepest mostly playful layout lower eden");
@@ -245,7 +311,9 @@ fn test_generate_view_only_from_keys_integration() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager.generate_from_keys(
wallet_str.to_string(),
@@ -259,7 +327,11 @@ fn test_generate_view_only_from_keys_integration() {
1, // KDF rounds.
);
- assert!(wallet.is_ok(), "Failed to generate wallet from keys: {:?}", wallet.err());
+ assert!(
+ wallet.is_ok(),
+ "Failed to generate wallet from keys: {:?}",
+ wallet.err()
+ );
// Verify that the wallet was generated correctly.
let wallet = wallet.expect("Failed to create wallet");
@@ -274,7 +346,11 @@ fn test_generate_view_only_from_keys_integration() {
// The address should be "45wsWad9...".
let address_result = wallet.get_address(0, 0);
- assert!(address_result.is_ok(), "Failed to get address: {:?}", address_result.err());
+ assert!(
+ address_result.is_ok(),
+ "Failed to get address: {:?}",
+ address_result.err()
+ );
let address = address_result.unwrap();
assert_eq!(address, "45wsWad9EwZgF3VpxQumrUCRaEtdyyh6NG8sVD3YRVVJbK1jkpJ3zq8WHLijVzodQ22LxwkdWx7fS2a6JzaRGzkNU8K2Dhi");
@@ -285,7 +361,10 @@ fn test_generate_view_only_from_keys_integration() {
"Failed to check if wallet is deterministic: {:?}",
is_deterministic_result.err()
);
- assert!(!is_deterministic_result.unwrap(), "Wallet should not be deterministic");
+ assert!(
+ !is_deterministic_result.unwrap(),
+ "Wallet should not be deterministic"
+ );
// Clean up wallet files.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -298,7 +377,9 @@ fn test_get_seed() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager
.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
@@ -317,8 +398,15 @@ fn test_get_seed() {
let start = Instant::now();
let result_with_offset = wallet.get_seed(Some("example_offset"));
println!("get_seed with offset took {:?}", start.elapsed());
- assert!(result_with_offset.is_ok(), "Failed to get seed with offset: {:?}", result_with_offset.err());
- assert!(!result_with_offset.unwrap().is_empty(), "Seed with offset is empty");
+ assert!(
+ result_with_offset.is_ok(),
+ "Failed to get seed with offset: {:?}",
+ result_with_offset.err()
+ );
+ assert!(
+ !result_with_offset.unwrap().is_empty(),
+ "Seed with offset is empty"
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -330,7 +418,9 @@ fn test_get_address() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager
.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
@@ -352,7 +442,9 @@ fn test_is_deterministic() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager
.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
@@ -361,7 +453,11 @@ fn test_is_deterministic() {
let start = Instant::now();
let result = wallet.is_deterministic();
println!("is_deterministic check took {:?}", start.elapsed());
- assert!(result.is_ok(), "Failed to check if wallet is deterministic: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to check if wallet is deterministic: {:?}",
+ result.err()
+ );
assert!(result.unwrap(), "Wallet should be deterministic");
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -384,7 +480,9 @@ fn test_wallet_creation_with_different_networks() {
// Construct the full path for each wallet within temp_dir.
let wallet_path = temp_dir.path().join(name);
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager.create_wallet(wallet_str, "password", "English", net_type);
assert!(wallet.is_ok(), "Failed to create wallet: {}", name);
@@ -400,7 +498,9 @@ fn test_multiple_address_generation() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager
.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
@@ -411,7 +511,12 @@ fn test_multiple_address_generation() {
let start = Instant::now();
let result = wallet.get_address(0, i);
println!("Address generation took {:?}", start.elapsed());
- assert!(result.is_ok(), "Failed to get address {}: {:?}", i, result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to get address {}: {:?}",
+ i,
+ result.err()
+ );
assert!(!result.unwrap().is_empty(), "Address {} is empty", i);
}
@@ -442,7 +547,7 @@ fn test_wallet_error_display() {
WalletError::WalletErrorCode(code, msg) => {
assert_eq!(code, 2);
assert_eq!(msg, "Sample wallet error");
- },
+ }
_ => panic!("Expected WalletErrorCode variant"),
}
}
@@ -453,13 +558,20 @@ fn test_wallet_status_integration() {
// Create a wallet.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
- let wallet = manager.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
+ let wallet = manager
+ .create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
.expect("Failed to create wallet");
// Check the status of the wallet.
let status = manager.get_status(wallet.ptr.as_ptr());
- assert!(status.is_ok(), "Expected status OK, got error: {:?}", status.err());
+ assert!(
+ status.is_ok(),
+ "Expected status OK, got error: {:?}",
+ status.err()
+ );
// Clean up.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -471,7 +583,9 @@ fn test_open_wallet_integration() {
// Create a wallet.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager
.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
@@ -482,7 +596,11 @@ fn test_open_wallet_integration() {
// Try opening the wallet.
let open_result = manager.open_wallet(wallet_str, "password", NetworkType::Mainnet);
- assert!(open_result.is_ok(), "Failed to open wallet: {:?}", open_result.err());
+ assert!(
+ open_result.is_ok(),
+ "Failed to open wallet: {:?}",
+ open_result.err()
+ );
// Clean up.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -493,10 +611,18 @@ fn test_open_wallet_invalid_password() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create a wallet with a valid password.
- let wallet = manager.create_wallet(wallet_str, "correct_password", "English", NetworkType::Mainnet)
+ let wallet = manager
+ .create_wallet(
+ wallet_str,
+ "correct_password",
+ "English",
+ NetworkType::Mainnet,
+ )
.expect("Failed to create wallet");
// Drop the wallet
@@ -504,7 +630,10 @@ fn test_open_wallet_invalid_password() {
// Attempt to open the wallet with an incorrect password.
let open_result = manager.open_wallet(wallet_str, "wrong_password", NetworkType::Mainnet);
- assert!(open_result.is_err(), "Expected an error when opening wallet with incorrect password");
+ assert!(
+ open_result.is_err(),
+ "Expected an error when opening wallet with incorrect password"
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -527,7 +656,8 @@ fn test_open_wallet_invalid_path() {
"Expected a non-OK status code, got OK instead."
);
assert!(
- error_message.contains("file not found") || error_message.contains("openWallet"),
+ error_message.contains("file not found")
+ || error_message.contains("openWallet"),
"Unexpected error message: {}",
error_message
);
@@ -546,7 +676,9 @@ fn test_get_balance_integration() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let wallet = manager
@@ -559,7 +691,11 @@ fn test_get_balance_integration() {
let balance_result = wallet.get_balance(0); // Account index 0.
println!("Fetching balance took {:?}", start.elapsed());
- assert!(balance_result.is_ok(), "Failed to fetch balance: {:?}", balance_result.err());
+ assert!(
+ balance_result.is_ok(),
+ "Failed to fetch balance: {:?}",
+ balance_result.err()
+ );
let balance = balance_result.unwrap();
println!("Balance: {:?}", balance);
@@ -580,7 +716,9 @@ fn test_create_account_integration() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let wallet = manager
@@ -593,7 +731,11 @@ fn test_create_account_integration() {
let result = wallet.create_account("Test Account Integration");
println!("create_account took {:?}", start.elapsed());
- assert!(result.is_ok(), "Failed to create account: {:?}", result.err());
+ assert!(
+ result.is_ok(),
+ "Failed to create account: {:?}",
+ result.err()
+ );
teardown(&temp_dir).expect("Failed to clean up after test");
}
@@ -603,19 +745,29 @@ fn test_get_accounts_integration() {
let (manager, temp_dir) = setup().expect("Failed to set up test environment");
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
let wallet = manager
.create_wallet(wallet_str, "password", "English", NetworkType::Mainnet)
.expect("Failed to create wallet");
// Add multiple accounts.
- wallet.create_account("Integration Account 1").expect("Failed to create account");
- wallet.create_account("Integration Account 2").expect("Failed to create account");
+ wallet
+ .create_account("Integration Account 1")
+ .expect("Failed to create account");
+ wallet
+ .create_account("Integration Account 2")
+ .expect("Failed to create account");
// Fetch accounts.
let accounts_result = wallet.get_accounts();
- assert!(accounts_result.is_ok(), "Failed to fetch accounts: {:?}", accounts_result.err());
+ assert!(
+ accounts_result.is_ok(),
+ "Failed to fetch accounts: {:?}",
+ accounts_result.err()
+ );
let accounts = accounts_result.unwrap().accounts;
assert_eq!(accounts.len(), 3, "Expected 3 accounts");
@@ -629,7 +781,9 @@ fn test_close_wallet_integration() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let mut wallet = manager
@@ -644,14 +798,22 @@ fn test_close_wallet_integration() {
let start = Instant::now();
let close_result = wallet.close_wallet();
println!("close_wallet took {:?}", start.elapsed());
- assert!(close_result.is_ok(), "Failed to close wallet: {:?}", close_result.err());
+ assert!(
+ close_result.is_ok(),
+ "Failed to close wallet: {:?}",
+ close_result.err()
+ );
// Attempt to close the wallet again.
println!("Attempting to close the wallet again...");
let start = Instant::now();
let close_again_result = wallet.close_wallet();
println!("Second close_wallet call took {:?}", start.elapsed());
- assert!(close_again_result.is_ok(), "Failed to close wallet a second time: {:?}", close_again_result.err());
+ assert!(
+ close_again_result.is_ok(),
+ "Failed to close wallet a second time: {:?}",
+ close_again_result.err()
+ );
// Clean up.
teardown(&temp_dir).expect("Failed to clean up after test");
@@ -664,7 +826,9 @@ fn test_get_height_integration() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet_height");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let _wallet = manager
@@ -698,7 +862,9 @@ fn test_refresh_integration_success() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("refresh_integration_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let wallet = manager
@@ -724,7 +890,11 @@ fn test_refresh_integration_success() {
let duration = start.elapsed();
println!("Initialization took {:?}", duration);
- assert!(init_result.is_ok(), "Failed to initialize wallet: {:?}", init_result.err());
+ assert!(
+ init_result.is_ok(),
+ "Failed to initialize wallet: {:?}",
+ init_result.err()
+ );
// Perform a refresh operation after initialization.
println!("Refreshing the wallet...");
@@ -733,7 +903,11 @@ fn test_refresh_integration_success() {
let refresh_duration = refresh_start.elapsed();
println!("Refresh operation took {:?}", refresh_duration);
- assert!(refresh_result.is_ok(), "Failed to refresh wallet: {:?}", refresh_result.err());
+ assert!(
+ refresh_result.is_ok(),
+ "Failed to refresh wallet: {:?}",
+ refresh_result.err()
+ );
// Clean up wallet files.
fs::remove_file(wallet_str).expect("Failed to delete test wallet");
@@ -749,7 +923,9 @@ fn test_init_integration_success() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("test_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let wallet = manager
@@ -775,12 +951,20 @@ fn test_init_integration_success() {
let duration = start.elapsed();
println!("Initialization took {:?}", duration);
- assert!(init_result.is_ok(), "Failed to initialize wallet: {:?}", init_result.err());
+ assert!(
+ init_result.is_ok(),
+ "Failed to initialize wallet: {:?}",
+ init_result.err()
+ );
// Perform a refresh operation after initialization.
println!("Refreshing the wallet...");
let refresh_result = wallet.refresh();
- assert!(refresh_result.is_ok(), "Failed to refresh wallet after initialization: {:?}", refresh_result.err());
+ assert!(
+ refresh_result.is_ok(),
+ "Failed to refresh wallet after initialization: {:?}",
+ refresh_result.err()
+ );
// Clean up wallet files.
fs::remove_file(wallet_str).expect("Failed to delete test wallet");
@@ -796,7 +980,9 @@ fn test_set_seed_language_integration() {
// Construct the full path for the wallet within temp_dir.
let wallet_path = temp_dir.path().join("set_seed_language_wallet");
- let wallet_str = wallet_path.to_str().expect("Failed to convert wallet path to string");
+ let wallet_str = wallet_path
+ .to_str()
+ .expect("Failed to convert wallet path to string");
// Create the wallet.
let wallet = manager