From 4832d1b0f32f025b3bcbbcbed688bf51493696db Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 18 Sep 2024 14:40:27 +0200 Subject: [PATCH] test: expand tx size test to test different values --- app/ante/tx_size.go | 3 ++- app/ante/tx_size_test.go | 17 +++++++++++++++-- x/blob/types/payforblob.go | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/ante/tx_size.go b/app/ante/tx_size.go index 0f6c1ba919..356f6f2646 100644 --- a/app/ante/tx_size.go +++ b/app/ante/tx_size.go @@ -145,6 +145,7 @@ func consumeGasForTxSize(ctx sdk.Context, txBytes uint64, params auth.Params) { ctx.GasMeter().ConsumeGas(params.TxSizeCostPerByte*txBytes, "txSize") } else { // From v3 onwards, we should get txSizeCostPerByte from appconsts - ctx.GasMeter().ConsumeGas(appconsts.TxSizeCostPerByte(ctx.BlockHeader().Version.App)*txBytes, "txSize") + txSizeCostPerByte := appconsts.TxSizeCostPerByte(ctx.BlockHeader().Version.App) + ctx.GasMeter().ConsumeGas(txSizeCostPerByte*txBytes, "txSize") } } diff --git a/app/ante/tx_size_test.go b/app/ante/tx_size_test.go index 0756524bd7..6b6bdbd80b 100644 --- a/app/ante/tx_size_test.go +++ b/app/ante/tx_size_test.go @@ -25,10 +25,15 @@ import ( "github.com/tendermint/tendermint/proto/tendermint/version" ) +const TxSizeCostPerByte = 8 + func setup() (*app.App, sdk.Context, client.Context, error) { app, _, _ := testutil.NewTestAppWithGenesisSet(app.DefaultConsensusParams()) ctx := app.NewContext(false, tmproto.Header{}) - app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) + params := authtypes.DefaultParams() + // Override default with a different TxSizeCostPerByte value for testing + params.TxSizeCostPerByte = TxSizeCostPerByte + app.AccountKeeper.SetParams(ctx, params) ctx = ctx.WithBlockHeight(1) // Set up TxConfig. @@ -90,7 +95,15 @@ func TestConsumeGasForTxSize(t *testing.T) { txBytes, err := clientCtx.TxConfig.TxJSONEncoder()(tx) require.Nil(t, err, "Cannot marshal tx: %v", err) - expectedGas := sdk.Gas(len(txBytes)) * appconsts.TxSizeCostPerByte(appconsts.LatestVersion) + // expected TxSizeCostPerByte is different for each version + var txSizeCostPerByte uint64 + if tc.version == v2.Version { + txSizeCostPerByte = TxSizeCostPerByte + } else { + txSizeCostPerByte = appconsts.TxSizeCostPerByte(tc.version) + } + + expectedGas := sdk.Gas(len(txBytes)) * txSizeCostPerByte // set suite.ctx with TxBytes manually ctx = ctx.WithTxBytes(txBytes) diff --git a/x/blob/types/payforblob.go b/x/blob/types/payforblob.go index 88f583ba80..b49eb05394 100644 --- a/x/blob/types/payforblob.go +++ b/x/blob/types/payforblob.go @@ -161,7 +161,7 @@ func EstimateGas(blobSizes []uint32, gasPerByte uint32, txSizeCost uint64) uint6 return GasToConsume(blobSizes, gasPerByte) + (txSizeCost * BytesPerBlobInfo * uint64(len(blobSizes))) + PFBGasFixedCost } -// DefaultEstimateGas runs EstimateGas with the system defaults. +// DefaultEstimateGas runs EstimateGas with the system defaults. func DefaultEstimateGas(blobSizes []uint32) uint64 { return EstimateGas(blobSizes, appconsts.DefaultGasPerBlobByte, appconsts.DefaultTxSizeCostPerByte) }