cl: split balance test

This commit is contained in:
David Rusu 2024-06-12 00:08:53 -04:00
parent fe6764d56e
commit 06a085a295
1 changed files with 35 additions and 24 deletions

View File

@ -30,33 +30,44 @@ impl Note {
}
#[test]
fn test_note_balance() {
// balances are blinded
let a = Note::new(10, "NMO");
assert_ne!(a.balance(12.into()), a.balance(8.into()));
// balances are deterministic
assert_eq!(a.balance(12.into()), a.balance(12.into()));
// balances are be homomorphic
let r = Scalar::from(32);
let ten = Note::new(10, "NMO");
let eight = Note::new(8, "NMO");
let two = Note::new(2, "NMO");
assert_eq!(ten.balance(r) - eight.balance(r), two.balance(r - r));
assert_eq!(
ten.balance(54.into()) - ten.balance(48.into()),
Note::new(0, "NMO").balance(6.into())
);
// Unit's differentiate between values.
let d = Note::new(10, "ETH");
assert_ne!(a.balance(r), d.balance(r));
fn test_balance_zero_unitless() {
// Zero is the same across all units
let r = Scalar::from(32);
assert_eq!(
Note::new(0, "NMO").balance(r),
Note::new(0, "ETH").balance(r)
);
}
#[test]
fn test_balance_blinding() {
// balances are blinded
let r1 = Scalar::from(12);
let r2 = Scalar::from(8);
let a = Note::new(10, "NMO");
assert_ne!(a.balance(r1), a.balance(r2));
assert_eq!(a.balance(r1), a.balance(r1));
}
#[test]
fn test_balance_units() {
// Unit's differentiate between values.
let nmo = Note::new(10, "NMO");
let eth = Note::new(10, "ETH");
let r = Scalar::from(1337);
assert_ne!(nmo.balance(r), eth.balance(r));
}
#[test]
fn test_balance_homomorphism() {
let r = Scalar::from(32);
let ten = Note::new(10, "NMO");
let eight = Note::new(8, "NMO");
let two = Note::new(2, "NMO");
assert_eq!(ten.balance(r) - eight.balance(r), two.balance(0.into()));
assert_eq!(
ten.balance(54.into()) - ten.balance(48.into()),
Note::new(0, "NMO").balance(6.into())
);
}