mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-01-30 18:42:15 +00:00
Additional tests
This commit is contained in:
parent
51b1b54863
commit
581d882a5f
@ -1313,11 +1313,22 @@ impl LightWallet {
|
||||
}
|
||||
|
||||
let start_time = now();
|
||||
if tos.len() == 0 {
|
||||
return Err("Need at least one destination address".to_string());
|
||||
}
|
||||
|
||||
// Check for duplicates in the to list
|
||||
if tos.len() > 1 {
|
||||
let mut to_addresses = tos.iter().map(|t| t.0.to_string()).collect::<Vec<_>>();
|
||||
to_addresses.sort();
|
||||
for i in 0..to_addresses.len()-1 {
|
||||
if to_addresses[i] == to_addresses[i+1] {
|
||||
return Err(format!("To address {} is duplicated", to_addresses[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let total_value = tos.iter().map(|to| to.1).sum::<u64>();
|
||||
|
||||
// TODO: Check for duplicates in destination addresses
|
||||
|
||||
println!(
|
||||
"0: Creating transaction sending {} ztoshis to {} addresses",
|
||||
total_value, tos.len()
|
||||
|
@ -1407,6 +1407,17 @@ fn test_bad_send() {
|
||||
let raw_tx = wallet.send_to_address(branch_id, &ss, &so,
|
||||
vec![(&ext_taddr, AMOUNT1 + 10, None)]);
|
||||
assert!(raw_tx.err().unwrap().contains("Insufficient verified funds"));
|
||||
|
||||
// Duplicated addresses
|
||||
let raw_tx = wallet.send_to_address(branch_id, &ss, &so,
|
||||
vec![(&ext_taddr, AMOUNT1 + 10, None),
|
||||
(&ext_taddr, AMOUNT1 + 10, None)]);
|
||||
assert!(raw_tx.err().unwrap().contains("duplicate"));
|
||||
|
||||
// No addresses
|
||||
let raw_tx = wallet.send_to_address(branch_id, &ss, &so, vec![]);
|
||||
assert!(raw_tx.err().unwrap().contains("at least one"));
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1698,6 +1709,30 @@ fn test_lock_unlock() {
|
||||
assert_eq!(taddr1, wallet2.address_from_sk(&tkeys[1]));
|
||||
assert_eq!(taddr2, wallet2.address_from_sk(&tkeys[2]));
|
||||
}
|
||||
|
||||
// Remove encryption from a unlocked wallet should succeed
|
||||
wallet2.remove_encryption("somepassword".to_string()).unwrap();
|
||||
assert_eq!(seed, wallet2.seed);
|
||||
|
||||
// Now encrypt with a different password
|
||||
wallet2.encrypt("newpassword".to_string()).unwrap();
|
||||
assert_eq!([0u8; 32], wallet2.seed); // Seed is cleared out
|
||||
|
||||
// Locking should fail because it is already locked
|
||||
assert!(wallet2.lock().is_err());
|
||||
|
||||
// The old password shouldn't work
|
||||
assert!(wallet2.remove_encryption("somepassword".to_string()).is_err());
|
||||
|
||||
// Remove encryption with the right password
|
||||
wallet2.remove_encryption("newpassword".to_string()).unwrap();
|
||||
assert_eq!(seed, wallet2.seed);
|
||||
|
||||
// Unlocking a wallet without encryption is an error
|
||||
assert!(wallet2.remove_encryption("newpassword".to_string()).is_err());
|
||||
// Can't lock/unlock a wallet that's not encrypted
|
||||
assert!(wallet2.lock().is_err());
|
||||
assert!(wallet2.unlock("newpassword".to_string()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user