Skip to content

Commit

Permalink
fix: add better error in market pallet for insufficient funds
Browse files Browse the repository at this point in the history
  • Loading branch information
th7nder committed Jan 27, 2025
1 parent 6d6043c commit 18eb23d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,10 @@ pub mod pallet {
amount: BalanceOf<T>,
) -> DispatchResult {
BalanceTable::<T>::try_mutate(account_id, |balance| -> DispatchResult {
ensure!(
balance.locked >= amount,
Error::<T>::InsufficientLockedFunds
);
balance.locked = balance
.locked
.checked_sub(&amount)
Expand Down
2 changes: 1 addition & 1 deletion pallets/market/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ fn test_unlock_funds() {

assert_err!(
unlock_funds::<Test>(&account::<Test>(PROVIDER), 60),
DispatchError::Arithmetic(ArithmeticError::Underflow)
Error::<Test>::InsufficientLockedFunds
);
assert_eq!(
BalanceTable::<Test>::get(account::<Test>(PROVIDER)),
Expand Down

0 comments on commit 18eb23d

Please sign in to comment.