mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-09 17:49:42 +00:00
fix tests
This commit is contained in:
parent
145198a078
commit
9d2abc76a1
@ -341,7 +341,7 @@ async fn private_transfer_to_owned_account_continuous_run_path() -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get the newly created account's keys
|
// Get the newly created account's keys
|
||||||
let (to_keys, _, _) = ctx
|
let (to_keys, _, to_identifier) = ctx
|
||||||
.wallet()
|
.wallet()
|
||||||
.storage()
|
.storage()
|
||||||
.user_data
|
.user_data
|
||||||
@ -356,7 +356,7 @@ async fn private_transfer_to_owned_account_continuous_run_path() -> Result<()> {
|
|||||||
to_label: None,
|
to_label: None,
|
||||||
to_npk: Some(hex::encode(to_keys.nullifier_public_key.0)),
|
to_npk: Some(hex::encode(to_keys.nullifier_public_key.0)),
|
||||||
to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)),
|
to_vpk: Some(hex::encode(to_keys.viewing_public_key.0)),
|
||||||
to_identifier: 0,
|
to_identifier,
|
||||||
amount: 100,
|
amount: 100,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1139,7 +1139,7 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get keys for foreign mint (claiming path)
|
// Get keys for foreign mint (claiming path)
|
||||||
let (holder_keys, _, _) = ctx
|
let (holder_keys, _, holder_identifier) = ctx
|
||||||
.wallet()
|
.wallet()
|
||||||
.storage()
|
.storage()
|
||||||
.user_data
|
.user_data
|
||||||
@ -1155,7 +1155,7 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> {
|
|||||||
holder_label: None,
|
holder_label: None,
|
||||||
holder_npk: Some(hex::encode(holder_keys.nullifier_public_key.0)),
|
holder_npk: Some(hex::encode(holder_keys.nullifier_public_key.0)),
|
||||||
holder_vpk: Some(hex::encode(holder_keys.viewing_public_key.0)),
|
holder_vpk: Some(hex::encode(holder_keys.viewing_public_key.0)),
|
||||||
holder_identifier: 0,
|
holder_identifier,
|
||||||
amount: mint_amount,
|
amount: mint_amount,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,11 @@ unsafe extern "C" {
|
|||||||
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_private_accounts_key(
|
fn wallet_ffi_create_private_accounts_key(
|
||||||
handle: *mut WalletHandle,
|
handle: *mut WalletHandle,
|
||||||
out_keys: *mut FfiPrivateAccountKeys,
|
out_keys: *mut FfiPrivateAccountKeys,
|
||||||
@ -684,14 +689,11 @@ fn wallet_ffi_init_private_account_auth_transfer() -> Result<()> {
|
|||||||
let home = tempfile::tempdir()?;
|
let home = tempfile::tempdir()?;
|
||||||
let wallet_ffi_handle = new_wallet_ffi_with_test_context_config(&ctx, home.path())?;
|
let wallet_ffi_handle = new_wallet_ffi_with_test_context_config(&ctx, home.path())?;
|
||||||
|
|
||||||
// Create a new receiving key and derive account_id for identifier=0
|
// Create a new private account
|
||||||
let out_account_id: FfiBytes32 = unsafe {
|
let mut out_account_id = FfiBytes32::default();
|
||||||
let mut out_keys = FfiPrivateAccountKeys::default();
|
unsafe {
|
||||||
wallet_ffi_create_private_accounts_key(wallet_ffi_handle, &raw mut out_keys);
|
wallet_ffi_create_account_private(wallet_ffi_handle, &raw mut out_account_id);
|
||||||
let account_id = nssa::AccountId::from((&out_keys.npk(), 0_u128));
|
}
|
||||||
wallet_ffi_free_private_account_keys(&raw mut out_keys);
|
|
||||||
(&account_id).into()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Call the init function
|
// Call the init function
|
||||||
let mut transfer_result = FfiTransferResult::default();
|
let mut transfer_result = FfiTransferResult::default();
|
||||||
|
|||||||
@ -533,25 +533,49 @@ mod tests {
|
|||||||
.key_map
|
.key_map
|
||||||
.get_mut(&ChainIndex::from_str("/1").unwrap())
|
.get_mut(&ChainIndex::from_str("/1").unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
acc.value.1.push((0, nssa::Account { balance: 2, ..nssa::Account::default() }));
|
acc.value.1.push((
|
||||||
|
0,
|
||||||
|
nssa::Account {
|
||||||
|
balance: 2,
|
||||||
|
..nssa::Account::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
let acc = tree
|
let acc = tree
|
||||||
.key_map
|
.key_map
|
||||||
.get_mut(&ChainIndex::from_str("/2").unwrap())
|
.get_mut(&ChainIndex::from_str("/2").unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
acc.value.1.push((0, nssa::Account { balance: 3, ..nssa::Account::default() }));
|
acc.value.1.push((
|
||||||
|
0,
|
||||||
|
nssa::Account {
|
||||||
|
balance: 3,
|
||||||
|
..nssa::Account::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
let acc = tree
|
let acc = tree
|
||||||
.key_map
|
.key_map
|
||||||
.get_mut(&ChainIndex::from_str("/0/1").unwrap())
|
.get_mut(&ChainIndex::from_str("/0/1").unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
acc.value.1.push((0, nssa::Account { balance: 5, ..nssa::Account::default() }));
|
acc.value.1.push((
|
||||||
|
0,
|
||||||
|
nssa::Account {
|
||||||
|
balance: 5,
|
||||||
|
..nssa::Account::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
let acc = tree
|
let acc = tree
|
||||||
.key_map
|
.key_map
|
||||||
.get_mut(&ChainIndex::from_str("/1/0").unwrap())
|
.get_mut(&ChainIndex::from_str("/1/0").unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
acc.value.1.push((0, nssa::Account { balance: 6, ..nssa::Account::default() }));
|
acc.value.1.push((
|
||||||
|
0,
|
||||||
|
nssa::Account {
|
||||||
|
balance: 6,
|
||||||
|
..nssa::Account::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
// Update account_id_map for nodes that now have entries
|
// Update account_id_map for nodes that now have entries
|
||||||
for chain_index_str in ["/1", "/2", "/0/1", "/1/0"] {
|
for chain_index_str in ["/1", "/2", "/0/1", "/1/0"] {
|
||||||
|
|||||||
@ -174,7 +174,13 @@ mod tests {
|
|||||||
// /2
|
// /2
|
||||||
let second_chain_index = key_tree_private.generate_new_node_layered().unwrap();
|
let second_chain_index = key_tree_private.generate_new_node_layered().unwrap();
|
||||||
|
|
||||||
key_tree_private.key_map.get(&second_chain_index).expect("Node was just inserted").value.0.clone()
|
key_tree_private
|
||||||
|
.key_map
|
||||||
|
.get(&second_chain_index)
|
||||||
|
.expect("Node was just inserted")
|
||||||
|
.value
|
||||||
|
.0
|
||||||
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -62,6 +62,56 @@ pub unsafe extern "C" fn wallet_ffi_create_account_public(
|
|||||||
WalletFfiError::Success
|
WalletFfiError::Success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a new private account, storing a default account entry in local storage.
|
||||||
|
///
|
||||||
|
/// This is the private-account equivalent of `wallet_ffi_create_account_public`.
|
||||||
|
/// It generates a key node, assigns a random identifier, and inserts a default
|
||||||
|
/// account record so the account can immediately be used with
|
||||||
|
/// `wallet_ffi_register_private_account`.
|
||||||
|
///
|
||||||
|
/// # Parameters
|
||||||
|
/// - `handle`: Valid wallet handle
|
||||||
|
/// - `out_account_id`: Output pointer for the new account ID (32 bytes)
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// - `Success` on successful creation
|
||||||
|
/// - Error code on failure
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// - `handle` must be a valid wallet handle from `wallet_ffi_create_new` or `wallet_ffi_open`
|
||||||
|
/// - `out_account_id` must be a valid pointer to a `FfiBytes32` struct
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn wallet_ffi_create_account_private(
|
||||||
|
handle: *mut WalletHandle,
|
||||||
|
out_account_id: *mut FfiBytes32,
|
||||||
|
) -> WalletFfiError {
|
||||||
|
let wrapper = match get_wallet(handle) {
|
||||||
|
Ok(w) => w,
|
||||||
|
Err(e) => return e,
|
||||||
|
};
|
||||||
|
|
||||||
|
if out_account_id.is_null() {
|
||||||
|
print_error("Null output pointer for account_id");
|
||||||
|
return WalletFfiError::NullPointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut wallet = match wrapper.core.lock() {
|
||||||
|
Ok(w) => w,
|
||||||
|
Err(e) => {
|
||||||
|
print_error(format!("Failed to lock wallet: {e}"));
|
||||||
|
return WalletFfiError::InternalError;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let (account_id, _chain_index) = wallet.create_new_account_private(None);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
(*out_account_id).data = *account_id.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
WalletFfiError::Success
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new private key node.
|
/// Create a new private key node.
|
||||||
///
|
///
|
||||||
/// Returns the nullifier public key (npk) and viewing public key (vpk) to share with
|
/// Returns the nullifier public key (npk) and viewing public key (vpk) to share with
|
||||||
|
|||||||
@ -242,6 +242,29 @@ typedef struct FfiTransferResult {
|
|||||||
enum WalletFfiError wallet_ffi_create_account_public(struct WalletHandle *handle,
|
enum WalletFfiError wallet_ffi_create_account_public(struct WalletHandle *handle,
|
||||||
struct FfiBytes32 *out_account_id);
|
struct FfiBytes32 *out_account_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new private account, storing a default account entry in local storage.
|
||||||
|
*
|
||||||
|
* This is the private-account equivalent of `wallet_ffi_create_account_public`.
|
||||||
|
* It generates a key node, assigns a random identifier, and inserts a default
|
||||||
|
* account record so the account can immediately be used with
|
||||||
|
* `wallet_ffi_register_private_account`.
|
||||||
|
*
|
||||||
|
* # Parameters
|
||||||
|
* - `handle`: Valid wallet handle
|
||||||
|
* - `out_account_id`: Output pointer for the new account ID (32 bytes)
|
||||||
|
*
|
||||||
|
* # Returns
|
||||||
|
* - `Success` on successful creation
|
||||||
|
* - Error code on failure
|
||||||
|
*
|
||||||
|
* # Safety
|
||||||
|
* - `handle` must be a valid wallet handle from `wallet_ffi_create_new` or `wallet_ffi_open`
|
||||||
|
* - `out_account_id` must be a valid pointer to a `FfiBytes32` struct
|
||||||
|
*/
|
||||||
|
enum WalletFfiError wallet_ffi_create_account_private(struct WalletHandle *handle,
|
||||||
|
struct FfiBytes32 *out_account_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new private key node.
|
* Create a new private key node.
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user