mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-02-19 04:43:36 +00:00
Following the work done in https://github.com/logos-blockchain/lssa/pull/292 and the comment on extending the work https://github.com/logos-blockchain/lssa/pull/292#pullrequestreview-3672282664, this commit introduces a new `--label` option to the `wallet account new` sub command. **Usage**: ``` wallet account new public --label "Public test account" wallet account new private --label "Private test account" ``` Labels have to be unique across all accounts in the wallet storage. The commit also adds tests, which make use of the `WalletSubCommand` trait functions (hence the change to make it a `pub trait`).
131 lines
3.5 KiB
Rust
131 lines
3.5 KiB
Rust
use anyhow::Result;
|
|
use integration_tests::TestContext;
|
|
use log::info;
|
|
use nssa::program::Program;
|
|
use tokio::test;
|
|
use wallet::cli::{
|
|
Command,
|
|
account::{AccountSubcommand, NewSubcommand},
|
|
execute_subcommand,
|
|
};
|
|
|
|
#[test]
|
|
async fn get_existing_account() -> Result<()> {
|
|
let ctx = TestContext::new().await?;
|
|
|
|
let account = ctx
|
|
.sequencer_client()
|
|
.get_account(ctx.existing_public_accounts()[0])
|
|
.await?
|
|
.account;
|
|
|
|
assert_eq!(
|
|
account.program_owner,
|
|
Program::authenticated_transfer_program().id()
|
|
);
|
|
assert_eq!(account.balance, 10000);
|
|
assert!(account.data.is_empty());
|
|
assert_eq!(account.nonce, 0);
|
|
|
|
info!("Successfully retrieved account with correct details");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
async fn new_public_account_with_label() -> Result<()> {
|
|
let mut ctx = TestContext::new().await?;
|
|
|
|
let label = "my-test-public-account".to_string();
|
|
let command = Command::Account(AccountSubcommand::New(NewSubcommand::Public {
|
|
cci: None,
|
|
label: Some(label.clone()),
|
|
}));
|
|
|
|
let result = execute_subcommand(ctx.wallet_mut(), command).await?;
|
|
|
|
// Extract the account_id from the result
|
|
let account_id = match result {
|
|
wallet::cli::SubcommandReturnValue::RegisterAccount { account_id } => account_id,
|
|
_ => panic!("Expected RegisterAccount return value"),
|
|
};
|
|
|
|
// Verify the label was stored
|
|
let stored_label = ctx
|
|
.wallet()
|
|
.storage()
|
|
.labels
|
|
.get(&account_id.to_string())
|
|
.expect("Label should be stored for the new account");
|
|
|
|
assert_eq!(stored_label.to_string(), label);
|
|
|
|
info!("Successfully created public account with label");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
async fn new_private_account_with_label() -> Result<()> {
|
|
let mut ctx = TestContext::new().await?;
|
|
|
|
let label = "my-test-private-account".to_string();
|
|
let command = Command::Account(AccountSubcommand::New(NewSubcommand::Private {
|
|
cci: None,
|
|
label: Some(label.clone()),
|
|
}));
|
|
|
|
let result = execute_subcommand(ctx.wallet_mut(), command).await?;
|
|
|
|
// Extract the account_id from the result
|
|
let account_id = match result {
|
|
wallet::cli::SubcommandReturnValue::RegisterAccount { account_id } => account_id,
|
|
_ => panic!("Expected RegisterAccount return value"),
|
|
};
|
|
|
|
// Verify the label was stored
|
|
let stored_label = ctx
|
|
.wallet()
|
|
.storage()
|
|
.labels
|
|
.get(&account_id.to_string())
|
|
.expect("Label should be stored for the new account");
|
|
|
|
assert_eq!(stored_label.to_string(), label);
|
|
|
|
info!("Successfully created private account with label");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
async fn new_public_account_without_label() -> Result<()> {
|
|
let mut ctx = TestContext::new().await?;
|
|
|
|
let command = Command::Account(AccountSubcommand::New(NewSubcommand::Public {
|
|
cci: None,
|
|
label: None,
|
|
}));
|
|
|
|
let result = execute_subcommand(ctx.wallet_mut(), command).await?;
|
|
|
|
// Extract the account_id from the result
|
|
let account_id = match result {
|
|
wallet::cli::SubcommandReturnValue::RegisterAccount { account_id } => account_id,
|
|
_ => panic!("Expected RegisterAccount return value"),
|
|
};
|
|
|
|
// Verify no label was stored
|
|
assert!(
|
|
!ctx.wallet()
|
|
.storage()
|
|
.labels
|
|
.contains_key(&account_id.to_string()),
|
|
"No label should be stored when not provided"
|
|
);
|
|
|
|
info!("Successfully created public account without label");
|
|
|
|
Ok(())
|
|
}
|