Skip to content

Commit

Permalink
265 audit pdm 003 test coverage (#316)
Browse files Browse the repository at this point in the history
* Fix bug with infinite allowance

* Add more tests

* Add even more tests

* Some refactoring

* Fix `should_return_allowance()` test
  • Loading branch information
ebma authored Oct 20, 2023
1 parent e4c19e3 commit 35807d5
Show file tree
Hide file tree
Showing 2 changed files with 423 additions and 49 deletions.
13 changes: 6 additions & 7 deletions pallets/orml-currencies-allowance-extension/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<T: Config> Pallet<T> {
Approvals::<T>::try_mutate_exists(
(id, &owner, delegate),
|maybe_approved| -> DispatchResult {
let mut approved = maybe_approved.take().ok_or(Error::<T>::Unapproved)?;
let approved = maybe_approved.take().ok_or(Error::<T>::Unapproved)?;
let remaining = approved.checked_sub(&amount).ok_or(Error::<T>::Unapproved)?;

<orml_currencies::Pallet<T> as MultiCurrency<T::AccountId>>::transfer(
Expand All @@ -308,14 +308,13 @@ impl<T: Config> Pallet<T> {
amount,
)?;

if remaining.is_zero() {
// Don't decrement allowance if it is set to the max value (which acts as infinite allowance)
if approved == BalanceOf::<T>::max_value() {
*maybe_approved = Some(approved);
} else if remaining.is_zero() {
*maybe_approved = None;
} else {
//decrement allowance only if it isn't max value (which acts as infinite allowance)
if approved != BalanceOf::<T>::max_value() {
approved = remaining;
}
*maybe_approved = Some(approved);
*maybe_approved = Some(remaining);
}
Ok(())
},
Expand Down
Loading

0 comments on commit 35807d5

Please sign in to comment.