Bug fix of currencies implementation for pallet-balances (#11875)

* Add test

* Fix the bug

* Add similar test for named reservable

* Extend test with "overflow" repatriation

* Expand test for `NamedReservableCurrency`

* Add notes about return values meaning
This commit is contained in:
Dmitry Novikov
2022-08-29 14:22:40 +03:00
committed by GitHub
parent 39db847714
commit 674e73caf0
2 changed files with 40 additions and 1 deletions
+5 -1
View File
@@ -1000,6 +1000,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Is a no-op if:
/// - the value to be moved is zero; or
/// - the `slashed` id equal to `beneficiary` and the `status` is `Reserved`.
///
/// NOTE: returns actual amount of transferred value in `Ok` case.
fn do_transfer_reserved(
slashed: &T::AccountId,
beneficiary: &T::AccountId,
@@ -1013,7 +1015,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
if slashed == beneficiary {
return match status {
Status::Free => Ok(Self::unreserve(slashed, value)),
Status::Free => Ok(value.saturating_sub(Self::unreserve(slashed, value))),
Status::Reserved => Ok(value.saturating_sub(Self::reserved_balance(slashed))),
}
}
@@ -1785,6 +1787,8 @@ where
/// Unreserve some funds, returning any amount that was unable to be unreserved.
///
/// Is a no-op if the value to be unreserved is zero or the account does not exist.
///
/// NOTE: returns amount value which wasn't successfully unreserved.
fn unreserve(who: &T::AccountId, value: Self::Balance) -> Self::Balance {
if value.is_zero() {
return Zero::zero()