Skip to content

Commit

Permalink
Return error if asset amount is zero
Browse files Browse the repository at this point in the history
This is primarily for the sake of symmetry
(`pool_join_with_exact_pool_amount` raises `MathApproximation` if the
asset amount is zero). Furthermore, calling this extrinsic with zero as
parameter is rather non-sensical, but, more importantly, this check
ensures that on-one can ever get free pool tokens.
  • Loading branch information
maltekliemann committed Mar 28, 2022
1 parent 256281a commit ef0855b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions zrml/swaps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,7 @@ mod pallet {
asset_amount: BalanceOf<T>,
min_pool_amount: BalanceOf<T>,
) -> Result<Weight, DispatchError> {
ensure!(asset_amount != Zero::zero(), Error::<T>::MathApproximation);
let pool = Pallet::<T>::pool_by_id(pool_id)?;
let pool_ref = &pool;
let pool_account_id = Pallet::<T>::pool_account_id(pool_id);
Expand Down
12 changes: 12 additions & 0 deletions zrml/swaps/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,18 @@ fn pool_amount_must_not_be_zero() {
});
}

#[test]
fn asset_amount_must_not_be_zero() {
ExtBuilder::default().build().execute_with(|| {
create_initial_pool_with_funds_for_alice(ScoringRule::CPMM, true);

assert_noop!(
Swaps::pool_join_with_exact_asset_amount(alice_signed(), 0, ASSET_A, 0, 0),
crate::Error::<Runtime>::MathApproximation
);
});
}

#[test]
fn pool_exit_decreases_correct_pool_parameters() {
ExtBuilder::default().build().execute_with(|| {
Expand Down

0 comments on commit ef0855b

Please sign in to comment.