Skip to content

Commit

Permalink
fix: understandable error when there is no fee provided but required
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed May 16, 2024
1 parent 4829289 commit 32005e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions x/tax/keeper/custom_tx_fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (k Keeper) CustomTxFeeChecker(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64
baseDenom := k.GetParams(ctx).BaseDenom
minimumFeeRequired := sdk.NewCoin(baseDenom, minGasPrices[0].Amount.Mul(glDec).Ceil().RoundInt())

// if there are no fees provided
if feeCoins.Len() == 0 {
return nil, 0, errors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees)
}

// if there are no fees paid in the base asset
if ok, _ := feeCoins.Find(baseDenom); !ok {
// Get Fee Param for select dex based on the feeCoins provided
Expand Down
12 changes: 11 additions & 1 deletion x/tax/keeper/custom_tx_fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestCustomTxFeeCheckerSuccessfulInNLS(t *testing.T) {
}

// Fail to pay fees in unsupported denom.
func TestCustomTxFeeCheckerSuccessfulInUnsupportedDenom(t *testing.T) {
func TestCustomTxFeeCheckerFailWhenUnsupportedDenom(t *testing.T) {
taxKeeper, ctx, _ := keepertest.TaxKeeper(t, true, sdk.DecCoins{sdk.NewDecCoin("unls", sdk.NewInt(1))})
// create a new CustomTxFeeChecker
feeTx := keepertest.MockFeeTx{
Expand Down Expand Up @@ -240,3 +240,13 @@ func TestCustomTxFeeCheckerFailOnZeroFees(t *testing.T) {
_, _, err := taxKeeper.CustomTxFeeChecker(ctx, feeTx)
require.Error(t, err)
}

// Successfully pay fees in unls which represents NLS. Minimum gas prices set to unls.
func TestCustomTxFeeCheckerFailWhenEmptyFee(t *testing.T) {
taxKeeper, ctx, _ := keepertest.TaxKeeper(t, true, sdk.DecCoins{sdk.NewDecCoin("unls", sdk.NewInt(1))})
// create a new CustomTxFeeChecker
feeTx := keepertest.MockFeeTx{}

_, _, err := taxKeeper.CustomTxFeeChecker(ctx, feeTx)
require.Error(t, err)
}

0 comments on commit 32005e1

Please sign in to comment.