From 32005e13d97a502f9d4581d85650be63b50baaad Mon Sep 17 00:00:00 2001 From: Lockwarr Date: Thu, 16 May 2024 16:06:48 +0300 Subject: [PATCH] fix: understandable error when there is no fee provided but required --- x/tax/keeper/custom_tx_fee_checker.go | 5 +++++ x/tax/keeper/custom_tx_fee_checker_test.go | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/x/tax/keeper/custom_tx_fee_checker.go b/x/tax/keeper/custom_tx_fee_checker.go index fe6306c4..a720ffc0 100644 --- a/x/tax/keeper/custom_tx_fee_checker.go +++ b/x/tax/keeper/custom_tx_fee_checker.go @@ -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 diff --git a/x/tax/keeper/custom_tx_fee_checker_test.go b/x/tax/keeper/custom_tx_fee_checker_test.go index 9cc0a5ac..5d896db5 100644 --- a/x/tax/keeper/custom_tx_fee_checker_test.go +++ b/x/tax/keeper/custom_tx_fee_checker_test.go @@ -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{ @@ -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) +}