use crate::{
amount::{Amount, NegativeAllowed, NonNegative},
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 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"),
);
}