mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 08:11:04 +00:00
fungible::Unbalanced::decrease_balance: Handle precision properly (#2823)
This commit is contained in:
@@ -146,7 +146,7 @@ fn unbalanced_trait_decrease_balance_works_2() {
|
||||
assert_eq!(Balances::total_balance_on_hold(&1337), 60);
|
||||
assert_noop!(
|
||||
Balances::decrease_balance(&1337, 40, Exact, Expendable, Polite),
|
||||
Error::<Test>::InsufficientBalance
|
||||
TokenError::FundsUnavailable
|
||||
);
|
||||
assert_eq!(Balances::decrease_balance(&1337, 39, Exact, Expendable, Polite), Ok(39));
|
||||
assert_eq!(<Balances as fungible::Inspect<_>>::balance(&1337), 1);
|
||||
@@ -468,3 +468,28 @@ fn emit_events_with_changing_freezes() {
|
||||
assert_eq!(events(), [RuntimeEvent::Balances(crate::Event::Thawed { who: 1, amount: 15 })]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn withdraw_precision_exact_works() {
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(1)
|
||||
.monied(true)
|
||||
.build_and_execute_with(|| {
|
||||
assert_ok!(Balances::set_freeze(&TestId::Foo, &1, 10));
|
||||
assert_eq!(Balances::account(&1).free, 10);
|
||||
assert_eq!(Balances::account(&1).frozen, 10);
|
||||
|
||||
// `BestEffort` will not reduce anything
|
||||
assert_ok!(<Balances as fungible::Balanced<_>>::withdraw(
|
||||
&1, 5, BestEffort, Preserve, Polite
|
||||
));
|
||||
|
||||
assert_eq!(Balances::account(&1).free, 10);
|
||||
assert_eq!(Balances::account(&1).frozen, 10);
|
||||
|
||||
assert_noop!(
|
||||
<Balances as fungible::Balanced<_>>::withdraw(&1, 5, Exact, Preserve, Polite),
|
||||
TokenError::FundsUnavailable
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user