mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-04-28 04:13:14 +00:00
add tests
This commit is contained in:
parent
629a3d1ef6
commit
35b469d738
@ -101,6 +101,7 @@ pub unsafe extern "C" fn wallet_ffi_create_account_private(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (account_id, _chain_index) = wallet.create_new_account_private(None);
|
let (account_id, _chain_index) = wallet.create_new_account_private(None);
|
||||||
|
println!("_chain_index: {_chain_index}");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
(*out_account_id).data = *account_id.value();
|
(*out_account_id).data = *account_id.value();
|
||||||
|
|||||||
@ -1,18 +1,23 @@
|
|||||||
use std::ffi::{c_char, CString};
|
use std::{
|
||||||
|
ffi::{c_char, CString},
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
|
|
||||||
|
use tokio::runtime::Handle;
|
||||||
use wallet::WalletCore;
|
use wallet::WalletCore;
|
||||||
use wallet_ffi::{error, FfiBytes32, FfiError, WalletHandle};
|
use wallet_ffi::{error, FfiBytes32, FfiError, WalletHandle};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn wallet_ffi_init_runtime() -> error::WalletFfiError;
|
|
||||||
|
|
||||||
fn wallet_ffi_destroy(handle: *mut WalletHandle);
|
|
||||||
|
|
||||||
fn wallet_ffi_create_account_public(
|
fn wallet_ffi_create_account_public(
|
||||||
handle: *mut WalletHandle,
|
handle: *mut WalletHandle,
|
||||||
out_account_id: *mut FfiBytes32,
|
out_account_id: *mut FfiBytes32,
|
||||||
) -> error::WalletFfiError;
|
) -> error::WalletFfiError;
|
||||||
|
|
||||||
|
fn wallet_ffi_create_account_private(
|
||||||
|
handle: *mut WalletHandle,
|
||||||
|
out_account_id: *mut FfiBytes32,
|
||||||
|
) -> error::WalletFfiError;
|
||||||
|
|
||||||
fn wallet_ffi_create_new(
|
fn wallet_ffi_create_new(
|
||||||
config_path: *const c_char,
|
config_path: *const c_char,
|
||||||
storage_path: *const c_char,
|
storage_path: *const c_char,
|
||||||
@ -24,42 +29,101 @@ extern "C" {
|
|||||||
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[test]
|
unsafe fn new_wallet_ffi_for_tests(password: &str) -> *mut WalletHandle {
|
||||||
fn test() {
|
|
||||||
unsafe {
|
|
||||||
let result = wallet_ffi_init_runtime();
|
|
||||||
println!("wallet init runtim result: {:?}", result);
|
|
||||||
}
|
|
||||||
|
|
||||||
let tempdir = tempdir().unwrap();
|
let tempdir = tempdir().unwrap();
|
||||||
let config_path = tempdir.path().join("wallet_config.json");
|
let config_path = tempdir.path().join("wallet_config.json");
|
||||||
let storage_path = tempdir.path().join("storage.json");
|
let storage_path = tempdir.path().join("storage.json");
|
||||||
let config_path_c = CString::new(config_path.to_str().unwrap()).unwrap();
|
let config_path_c = CString::new(config_path.to_str().unwrap()).unwrap();
|
||||||
let storage_path_c = CString::new(storage_path.to_str().unwrap()).unwrap();
|
let storage_path_c = CString::new(storage_path.to_str().unwrap()).unwrap();
|
||||||
let password = CString::new("").unwrap();
|
let password = CString::new(password).unwrap();
|
||||||
|
|
||||||
unsafe {
|
wallet_ffi_create_new(
|
||||||
let wallet_handle = wallet_ffi_create_new(
|
config_path_c.as_ptr(),
|
||||||
config_path_c.as_ptr(),
|
storage_path_c.as_ptr(),
|
||||||
storage_path_c.as_ptr(),
|
password.as_ptr(),
|
||||||
password.as_ptr(),
|
)
|
||||||
);
|
}
|
||||||
|
|
||||||
let mut out_account_id = FfiBytes32::from_bytes([0; 32]);
|
fn new_wallet_rust_for_tests(password: &str) -> WalletCore {
|
||||||
|
let tempdir = tempdir().unwrap();
|
||||||
let result = wallet_ffi_create_account_public(
|
let config_path = tempdir.path().join("wallet_config.json");
|
||||||
wallet_handle,
|
let storage_path = tempdir.path().join("storage.json");
|
||||||
(&mut out_account_id) as *mut FfiBytes32,
|
|
||||||
);
|
WalletCore::new_init_storage(
|
||||||
println!("{:?}", out_account_id.data);
|
config_path.to_path_buf(),
|
||||||
println!("create result: {:?}", result);
|
storage_path.to_path_buf(),
|
||||||
|
None,
|
||||||
let result = wallet_ffi_save(wallet_handle);
|
password.to_string(),
|
||||||
println!("save result: {:?}", result);
|
)
|
||||||
|
.unwrap()
|
||||||
wallet_ffi_destroy(wallet_handle);
|
}
|
||||||
}
|
|
||||||
// let mut wallet_core = WalletCore::new_update_chain(config_path.to_path_buf(),
|
#[test]
|
||||||
// storage_path.to_path_buf(), None).unwrap(); let (account_id, _) =
|
fn test_create_public_accounts() {
|
||||||
// wallet_core.create_new_account_public(None); println!("{:?}", account_id);
|
let password = "password_for_tests";
|
||||||
|
let n_accounts = 10;
|
||||||
|
// First `n_accounts` public accounts created with Rust wallet
|
||||||
|
let new_public_account_ids_rust = {
|
||||||
|
let mut account_ids = Vec::new();
|
||||||
|
|
||||||
|
let mut wallet_rust = new_wallet_rust_for_tests(password);
|
||||||
|
for _ in 0..n_accounts {
|
||||||
|
let account_id = wallet_rust.create_new_account_public(None).0;
|
||||||
|
account_ids.push(*account_id.value());
|
||||||
|
}
|
||||||
|
account_ids
|
||||||
|
};
|
||||||
|
|
||||||
|
// First `n_accounts` public accounts created with wallet FFI
|
||||||
|
let new_public_account_ids_ffi = unsafe {
|
||||||
|
let mut account_ids = Vec::new();
|
||||||
|
|
||||||
|
let wallet_ffi_handle = new_wallet_ffi_for_tests(password);
|
||||||
|
for _ in 0..n_accounts {
|
||||||
|
let mut out_account_id = FfiBytes32::from_bytes([0; 32]);
|
||||||
|
wallet_ffi_create_account_public(
|
||||||
|
wallet_ffi_handle,
|
||||||
|
(&mut out_account_id) as *mut FfiBytes32,
|
||||||
|
);
|
||||||
|
account_ids.push(out_account_id.data);
|
||||||
|
}
|
||||||
|
account_ids
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(new_public_account_ids_ffi, new_public_account_ids_rust)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_create_private_accounts() {
|
||||||
|
let password = "password_for_tests";
|
||||||
|
let n_accounts = 10;
|
||||||
|
// First `n_accounts` private accounts created with Rust wallet
|
||||||
|
let new_private_account_ids_rust = {
|
||||||
|
let mut account_ids = Vec::new();
|
||||||
|
|
||||||
|
let mut wallet_rust = new_wallet_rust_for_tests(password);
|
||||||
|
for _ in 0..n_accounts {
|
||||||
|
let account_id = wallet_rust.create_new_account_private(None).0;
|
||||||
|
account_ids.push(*account_id.value());
|
||||||
|
}
|
||||||
|
account_ids
|
||||||
|
};
|
||||||
|
|
||||||
|
// First `n_accounts` private accounts created with wallet FFI
|
||||||
|
let new_private_account_ids_ffi = unsafe {
|
||||||
|
let mut account_ids = Vec::new();
|
||||||
|
|
||||||
|
let wallet_ffi_handle = new_wallet_ffi_for_tests(password);
|
||||||
|
for _ in 0..n_accounts {
|
||||||
|
let mut out_account_id = FfiBytes32::from_bytes([0; 32]);
|
||||||
|
wallet_ffi_create_account_private(
|
||||||
|
wallet_ffi_handle,
|
||||||
|
(&mut out_account_id) as *mut FfiBytes32,
|
||||||
|
);
|
||||||
|
account_ids.push(out_account_id.data);
|
||||||
|
}
|
||||||
|
account_ids
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(new_private_account_ids_ffi, new_private_account_ids_rust)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user