use crate::{
amount::{Amount, NegativeAllowed, NonNegative, MAX_MONEY},
value_balance::{ValueBalance, ValueBalanceError},
};
#[test]
fn ironwood_pool_enforces_non_negative_balance() {
let _init_guard = zebra_test::init();
let chain = ValueBalance::<NonNegative>::zero()
.add_chain_value_pool_change(ValueBalance::from_ironwood_amount(
Amount::<NegativeAllowed>::try_from(100).expect("valid amount"),
))
.expect("adding positive ironwood value to an empty pool is valid");
assert_eq!(
chain.ironwood_amount(),
Amount::<NonNegative>::try_from(100).expect("valid amount"),
);
let error = chain
.add_chain_value_pool_change(ValueBalance::from_ironwood_amount(
Amount::<NegativeAllowed>::try_from(-101).expect("valid amount"),
))
.expect_err("draining the ironwood pool below zero must be rejected");
assert!(matches!(error, ValueBalanceError::Ironwood(_)));
}
#[test]
fn total_over_max_money_is_rejected() {
let _init_guard = zebra_test::init();
let mut chain = ValueBalance::<NonNegative>::zero();
chain.set_transparent_value_balance(ValueBalance::from_transparent_amount(
Amount::try_from(MAX_MONEY).expect("MAX_MONEY is a valid amount"),
));
let error = chain
.add_chain_value_pool_change(ValueBalance::from_sprout_amount(
Amount::<NegativeAllowed>::try_from(MAX_MONEY).expect("MAX_MONEY is a valid amount"),
))
.expect_err("a total exceeding MAX_MONEY must be rejected");
assert!(matches!(error, ValueBalanceError::Total(_)));
}
#[test]
fn ironwood_included_in_remaining_transaction_value() {
let _init_guard = zebra_test::init();
let value_balance =
ValueBalance::<NegativeAllowed>::from_ironwood_amount(Amount::try_from(50).expect("valid"));
assert_eq!(
value_balance
.remaining_transaction_value()
.expect("positive ironwood value is valid remaining transaction value"),
Amount::<NonNegative>::try_from(50).expect("valid amount"),
);
}