58 lines
1.5 KiB
Rust
58 lines
1.5 KiB
Rust
use aicoin::blockchain::Transaction;
|
|
use aicoin::wallet::Wallet;
|
|
|
|
#[test]
|
|
fn test_transaction_signing() {
|
|
let wallet = Wallet::new(None);
|
|
let mut transaction = Transaction::new(
|
|
wallet.address.clone(),
|
|
"recipient_address".to_string(),
|
|
100.0,
|
|
Some("did:plc:test789".to_string()),
|
|
);
|
|
|
|
assert!(transaction.signature.is_none());
|
|
|
|
if let Some(ref signing_key) = wallet.private_key {
|
|
transaction.sign(signing_key);
|
|
assert!(transaction.signature.is_some());
|
|
|
|
// Verify signature
|
|
let verifying_key = wallet.get_verifying_key().unwrap();
|
|
assert!(transaction.verify_signature(&verifying_key));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_transaction_hash() {
|
|
let tx1 = Transaction::new(
|
|
"from".to_string(),
|
|
"to".to_string(),
|
|
100.0,
|
|
None,
|
|
);
|
|
|
|
let tx2 = Transaction::new(
|
|
"from".to_string(),
|
|
"to".to_string(),
|
|
100.0,
|
|
None,
|
|
);
|
|
|
|
// Same parameters but different timestamps should produce different hashes
|
|
assert_ne!(tx1.calculate_hash(), tx2.calculate_hash());
|
|
}
|
|
|
|
#[test]
|
|
fn test_transaction_with_atproto_did() {
|
|
let transaction = Transaction::new(
|
|
"from".to_string(),
|
|
"to".to_string(),
|
|
50.0,
|
|
Some("did:plc:user123".to_string()),
|
|
);
|
|
|
|
assert_eq!(transaction.atproto_did, Some("did:plc:user123".to_string()));
|
|
assert_eq!(transaction.amount, 50.0);
|
|
assert_eq!(transaction.fee, 0.05);
|
|
} |