From 4af5651c9e978cb7c31e225779683154baf807ed Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Mon, 15 Jun 2026 11:53:07 +0300 Subject: [PATCH] fix(wallet_ffi): fiull restoration reproduction --- integration_tests/tests/wallet_ffi.rs | 31 ++++++++++++++++++++++++++- lez/wallet-ffi/src/wallet.rs | 18 +++++++++++++--- lez/wallet/src/lib.rs | 10 ++++++--- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/integration_tests/tests/wallet_ffi.rs b/integration_tests/tests/wallet_ffi.rs index 92b82a7c..f47435bd 100644 --- a/integration_tests/tests/wallet_ffi.rs +++ b/integration_tests/tests/wallet_ffi.rs @@ -26,7 +26,8 @@ use log::info; use tempfile::tempdir; use wallet::account::HumanReadableAccount; use wallet_ffi::{ - FfiAccount, FfiAccountList, FfiBytes32, FfiPrivateAccountKeys, FfiPublicAccountKey, FfiTransferResult, FfiU128, WalletHandle, error, wallet::FfiCreateWalletResult + FfiAccount, FfiAccountList, FfiBytes32, FfiPrivateAccountKeys, FfiPublicAccountKey, + FfiTransferResult, FfiU128, WalletHandle, error, wallet::FfiCreateWalletResult, }; unsafe extern "C" { @@ -1399,6 +1400,34 @@ fn restore_keys_from_seed_ffi() -> Result<()> { u128::from_le_bytes(out_balance) }; + // Get the account list with FFI method + let wallet_ffi_account_list = unsafe { + let mut out_list = FfiAccountList::default(); + wallet_ffi_list_accounts(wallet_ffi_handle, &raw mut out_list).unwrap(); + out_list + }; + + let wallet_ffi_account_list_slice = unsafe { + core::slice::from_raw_parts( + wallet_ffi_account_list.entries, + wallet_ffi_account_list.count, + ) + }; + + // All created accounts must appear in the list + let listed_public_ids: HashSet<_> = wallet_ffi_account_list_slice + .iter() + .filter(|e| e.is_public) + .map(|e| hex::encode(e.account_id.data)) + .collect(); + + info!("Current list of accounts: {listed_public_ids:?}"); + + info!("Private acc to be restored 1 {:?}", hex::encode(private_account_id_1.data)); + info!("Private acc to be restored 2 {:?}", hex::encode(private_account_id_2.data)); + info!("Pub acc to be restored 1 {:?}", hex::encode(public_account_id_1.data)); + info!("Pub acc to be restored 2 {:?}", hex::encode(public_account_id_2.data)); + assert_eq!(private_account_id_1_balance, 100); assert_eq!(private_account_id_2_balance, 101); assert_eq!(public_account_id_1_balance, 102); diff --git a/lez/wallet-ffi/src/wallet.rs b/lez/wallet-ffi/src/wallet.rs index 02c79e5c..485e4841 100644 --- a/lez/wallet-ffi/src/wallet.rs +++ b/lez/wallet-ffi/src/wallet.rs @@ -7,10 +7,10 @@ use std::{ sync::Mutex, }; -use wallet::WalletCore; +use wallet::{cli::execute_keys_restoration, WalletCore}; use crate::{ - c_str_to_string, + block_on, c_str_to_string, error::{print_error, WalletFfiError}, types::WalletHandle, }; @@ -276,12 +276,24 @@ pub unsafe extern "C" fn wallet_ffi_restore_data( return WalletFfiError::NullPointer; }; - match wallet.restore_storage(&mnemonic, &password) { + let res = match wallet.restore_storage(&mnemonic, &password) { Ok(()) => WalletFfiError::Success, Err(e) => { print_error(format!("Failed to restore wallet data: {e}")); WalletFfiError::StorageError } + }; + + if res == WalletFfiError::Success { + match block_on(execute_keys_restoration(&mut wallet, 10)) { + Ok(_) => WalletFfiError::Success, + Err(err) => { + print_error(format!("Failed to restore wallet data: {err}")); + WalletFfiError::StorageError + } + } + } else { + res } } diff --git a/lez/wallet/src/lib.rs b/lez/wallet/src/lib.rs index 90ef43b0..b4e52721 100644 --- a/lez/wallet/src/lib.rs +++ b/lez/wallet/src/lib.rs @@ -879,13 +879,17 @@ impl WalletCore { #[cfg(test)] mod tests { - use std::{ffi::{CStr, CString}, str::FromStr}; + use std::{ + ffi::{CStr, CString}, + str::FromStr, + }; -use bip39::Mnemonic; + use bip39::Mnemonic; #[test] fn mnemonic_roundtrip() { - let mnemonic = Mnemonic::from_entropy(&[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]).unwrap(); + let mnemonic = + Mnemonic::from_entropy(&[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]).unwrap(); let c_mnemonic_string = CString::new(mnemonic.to_string()).unwrap();