use super::utils::{assert_output_contains, assert_success, CliTest};
const TEST_WALLET_PASSWORD: &str = "password123";
#[test]
fn test_wallet_create() {
let cli = CliTest::new();
let wallet_path = cli.temp_dir.path().join("test-wallet.json").to_string_lossy().to_string();
let output =
cli.run(&["wallet", "create", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
assert_success(&output);
assert_output_contains(&output, "Creating");
assert!(std::path::Path::new(&wallet_path).exists());
}
#[test]
fn test_wallet_open_and_close() {
let cli = CliTest::new();
let wallet_path = cli.temp_dir.path().join("test-wallet.json").to_string_lossy().to_string();
let create_output =
cli.run(&["wallet", "create", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
assert_success(&create_output);
let open_output =
cli.run(&["wallet", "open", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
assert_success(&open_output);
assert_output_contains(&open_output, "Opened Successfully");
let close_output = cli.run(&["wallet", "close"]);
assert_success(&close_output);
assert_output_contains(&close_output, "No wallet");
}
#[test]
#[ignore] fn test_wallet_create_address() {
let cli = CliTest::new();
let wallet_path = cli.temp_dir.path().join("test-wallet.json").to_string_lossy().to_string();
cli.run(&["wallet", "create", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
cli.run(&["wallet", "open", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
let output = cli.run(&["wallet", "create-address", "--count", "1"]);
assert_success(&output);
assert_output_contains(&output, "New address created");
}
#[test]
fn test_wallet_list_address() {
let cli = CliTest::new();
let wallet_path = cli.temp_dir.path().join("test-wallet.json").to_string_lossy().to_string();
cli.run(&["wallet", "create", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
let output = cli.run(&["wallet", "list"]);
assert!(!output.status.success());
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("No wallet open"),
"Expected error message 'No wallet open', got: {stderr}"
);
}
#[test]
#[ignore] fn test_wallet_balance() {
let cli = CliTest::new();
let wallet_path = cli.temp_dir.path().join("test-wallet.json").to_string_lossy().to_string();
cli.run(&["wallet", "create", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
cli.run(&["wallet", "open", "--path", &wallet_path, "--password", TEST_WALLET_PASSWORD]);
cli.run(&["wallet", "create-address", "--count", "1"]);
let output = cli.run(&["wallet", "balance"]);
assert_success(&output);
}