Skip to content

Commit

Permalink
test: expand tx size test to test different values
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Sep 18, 2024
1 parent f6f08c6 commit 4832d1b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/ante/tx_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
17 changes: 15 additions & 2 deletions app/ante/tx_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/blob/types/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4832d1b

Please sign in to comment.