Check unreserve and transfer returnvalues in debug code (#8398)

* Check `unreserve` and `transfer` returnvalues in debug code

fixes #8106

* few more

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Falco Hirschenberger
2021-03-24 18:35:05 +01:00
committed by GitHub
parent f93d7b874e
commit 9a72134188
13 changed files with 66 additions and 34 deletions
+15 -7
View File
@@ -435,7 +435,8 @@ decl_module! {
} else {
// Else this is the curator, willingly giving up their role.
// Give back their deposit.
let _ = T::Currency::unreserve(&curator, bounty.curator_deposit);
let err_amount = T::Currency::unreserve(&curator, bounty.curator_deposit);
debug_assert!(err_amount.is_zero());
// Continue to change bounty status below...
}
},
@@ -548,9 +549,13 @@ decl_module! {
let balance = T::Currency::free_balance(&bounty_account);
let fee = bounty.fee.min(balance); // just to be safe
let payout = balance.saturating_sub(fee);
let _ = T::Currency::unreserve(&curator, bounty.curator_deposit);
let _ = T::Currency::transfer(&bounty_account, &curator, fee, AllowDeath); // should not fail
let _ = T::Currency::transfer(&bounty_account, &beneficiary, payout, AllowDeath); // should not fail
let err_amount = T::Currency::unreserve(&curator, bounty.curator_deposit);
debug_assert!(err_amount.is_zero());
let res = T::Currency::transfer(&bounty_account, &curator, fee, AllowDeath); // should not fail
debug_assert!(res.is_ok());
let res = T::Currency::transfer(&bounty_account, &beneficiary, payout, AllowDeath); // should not fail
debug_assert!(res.is_ok());
*maybe_bounty = None;
BountyDescriptions::remove(bounty_id);
@@ -604,7 +609,8 @@ decl_module! {
},
BountyStatus::Active { curator, .. } => {
// Cancelled by council, refund deposit of the working curator.
let _ = T::Currency::unreserve(&curator, bounty.curator_deposit);
let err_amount = T::Currency::unreserve(&curator, bounty.curator_deposit);
debug_assert!(err_amount.is_zero());
// Then execute removal of the bounty below.
},
BountyStatus::PendingPayout { .. } => {
@@ -621,7 +627,8 @@ decl_module! {
BountyDescriptions::remove(bounty_id);
let balance = T::Currency::free_balance(&bounty_account);
let _ = T::Currency::transfer(&bounty_account, &Self::account_id(), balance, AllowDeath); // should not fail
let res = T::Currency::transfer(&bounty_account, &Self::account_id(), balance, AllowDeath); // should not fail
debug_assert!(res.is_ok());
*maybe_bounty = None;
Self::deposit_event(Event::<T>::BountyCanceled(bounty_id));
@@ -736,7 +743,8 @@ impl<T: Config> pallet_treasury::SpendFunds<T> for Module<T> {
bounty.status = BountyStatus::Funded;
// return their deposit.
let _ = T::Currency::unreserve(&bounty.proposer, bounty.bond);
let err_amount = T::Currency::unreserve(&bounty.proposer, bounty.bond);
debug_assert!(err_amount.is_zero());
// fund the bounty account
imbalance.subsume(T::Currency::deposit_creating(&Self::bounty_account_id(index), bounty.value));