Skip to content

Commit

Permalink
chg: remove SetGasMeter call and fix mempool test accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello33 committed Jan 31, 2024
1 parent 7a803b3 commit 0884eac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
)

params := dfd.accountKeeper.GetParams(ctx)
gas := params.GetMaxTxGas()

fee := feeTx.GetFee()
if !simulate {
Expand All @@ -68,7 +67,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
return ctx, err
}

newCtx := SetGasMeter(simulate, ctx, gas).WithPriority(priority)
newCtx := ctx.WithPriority(priority)

return next(newCtx, tx, simulate)
}
Expand Down
20 changes: 10 additions & 10 deletions x/auth/ante/fee_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante_test

import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"testing"

"github.com/golang/mock/gomock"
Expand All @@ -14,7 +15,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

func TestDeductFeeDecorator_ZeroGas(t *testing.T) {
Expand Down Expand Up @@ -50,7 +50,6 @@ func TestDeductFeeDecorator_ZeroGas(t *testing.T) {
}

func TestEnsureMempoolFees(t *testing.T) {
t.Skip("skipping test as not relevant to Heimdall (no checkTx")
s := SetupTestSuite(t, true) // setup
s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder()

Expand All @@ -68,23 +67,24 @@ func TestEnsureMempoolFees(t *testing.T) {
s.txBuilder.SetFeeAmount(feeAmount)
s.txBuilder.SetGasLimit(gasLimit)

s.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), accs[0].acc.GetAddress(), authtypes.FeeCollectorName, feeAmount).Return(nil).Times(3)
// called once more than vanilla cosmos-sdk as decorator will not throw an error for heimdall (CheckTx is disabled)
s.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), accs[0].acc.GetAddress(), authtypes.FeeCollectorName, feeAmount).Return(nil).Times(4)

privs, accNums, accSeqs := []cryptotypes.PrivKey{accs[0].priv}, []uint64{0}, []uint64{0}
tx, err := s.CreateTestTx(s.ctx, privs, accNums, accSeqs, s.ctx.ChainID(), signing.SignMode_SIGN_MODE_DIRECT)
require.NoError(t, err)

// Set high gas price so standard test fee fails
atomPrice := sdk.NewDecCoinFromDec("matic", math.LegacyNewDec(20))
highGasPrice := []sdk.DecCoin{atomPrice}
maticPrice := sdk.NewDecCoinFromDec("matic", math.LegacyNewDec(20))
highGasPrice := []sdk.DecCoin{maticPrice}
s.ctx = s.ctx.WithMinGasPrices(highGasPrice)

// Set IsCheckTx to true
s.ctx = s.ctx.WithIsCheckTx(true)

// antehandler errors with insufficient fees
_, err = antehandler(s.ctx, tx, false)
require.NotNil(t, err, "Decorator should have errored on too low fee for local gasPrice")
require.Nil(t, err, "Decorator will not throw an error for heimdall as CheckTx is disabled")

// antehandler should not error since we do not check minGasPrice in simulation mode
cacheCtx, _ := s.ctx.CacheContext()
Expand All @@ -101,15 +101,15 @@ func TestEnsureMempoolFees(t *testing.T) {
// Set IsCheckTx back to true for testing sufficient mempool fee
s.ctx = s.ctx.WithIsCheckTx(true)

atomPrice = sdk.NewDecCoinFromDec("atom", math.LegacyNewDec(0).Quo(math.LegacyNewDec(100000)))
lowGasPrice := []sdk.DecCoin{atomPrice}
maticPrice = sdk.NewDecCoinFromDec("matic", math.LegacyNewDec(0).Quo(math.LegacyNewDec(1000000000000000)))
lowGasPrice := []sdk.DecCoin{maticPrice}
s.ctx = s.ctx.WithMinGasPrices(lowGasPrice)

newCtx, err := antehandler(s.ctx, tx, false)
require.Nil(t, err, "Decorator should not have errored on fee higher than local gasPrice")
// Priority is the smallest gas price amount in any denom. Since we have only 1 gas price
// of 10atom, the priority here is 10.
require.Equal(t, int64(10), newCtx.Priority())
// of 1000000000matic, the priority here is 1000000000.
require.Equal(t, int64(1000000000), newCtx.Priority())
}

func TestDeductFees(t *testing.T) {
Expand Down

0 comments on commit 0884eac

Please sign in to comment.