51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use aicoin::wallet::Wallet;
|
|
use std::fs;
|
|
use tempfile::TempDir;
|
|
|
|
#[test]
|
|
fn test_wallet_creation() {
|
|
let wallet = Wallet::new(Some("did:plc:test123".to_string()));
|
|
|
|
assert!(!wallet.address.is_empty());
|
|
assert!(!wallet.public_key.is_empty());
|
|
assert_eq!(wallet.atproto_did, Some("did:plc:test123".to_string()));
|
|
assert!(wallet.get_private_key_hex().is_some());
|
|
}
|
|
|
|
#[test]
|
|
fn test_wallet_from_private_key() {
|
|
let wallet1 = Wallet::new(None);
|
|
let private_key = wallet1.get_private_key_hex().unwrap();
|
|
|
|
let wallet2 = Wallet::from_private_key(&private_key, None).unwrap();
|
|
|
|
assert_eq!(wallet1.address, wallet2.address);
|
|
assert_eq!(wallet1.public_key, wallet2.public_key);
|
|
}
|
|
|
|
#[test]
|
|
fn test_wallet_export_import() {
|
|
let temp_dir = TempDir::new().unwrap();
|
|
let wallet_file = temp_dir.path().join("wallet.json");
|
|
|
|
let wallet1 = Wallet::new(Some("did:plc:test456".to_string()));
|
|
wallet1.export_to_file(wallet_file.to_str().unwrap()).unwrap();
|
|
|
|
let wallet2 = Wallet::import_from_file(wallet_file.to_str().unwrap()).unwrap();
|
|
|
|
assert_eq!(wallet1.address, wallet2.address);
|
|
assert_eq!(wallet1.public_key, wallet2.public_key);
|
|
assert_eq!(wallet1.atproto_did, wallet2.atproto_did);
|
|
}
|
|
|
|
#[test]
|
|
fn test_wallet_import_nonexistent_file() {
|
|
let result = Wallet::import_from_file("/nonexistent/wallet.json");
|
|
assert!(result.is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn test_invalid_private_key() {
|
|
let result = Wallet::from_private_key("invalid_hex", None);
|
|
assert!(result.is_err());
|
|
} |