chore(all): modernized code with built-in min/max (#24124)

This commit is contained in:
quantix9 2025-03-25 23:43:05 +08:00 committed by GitHub
parent 94068be123
commit 9acd7716dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 26 deletions

View File

@ -175,11 +175,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
}
// check block gas is always consumed
baseGas := uint64(57504) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) {
// capped by gasLimit
expGasConsumed = uint64(simtestutil.DefaultConsensusParams.Block.MaxGas)
}
expGasConsumed := min(addUint64Saturating(tc.gasToConsume, baseGas), uint64(simtestutil.DefaultConsensusParams.Block.MaxGas))
require.Equal(t, int(expGasConsumed), int(ctx.BlockGasMeter().GasConsumed()))
// tx fee is always deducted
require.Equal(t, int64(0), bankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount.Int64())

View File

@ -35,11 +35,7 @@ func Paginate(numObjs, page, limit, defLimit int) (start, end int) {
}
start = (page - 1) * limit
end = limit + start
if end >= numObjs {
end = numObjs
}
end = min(limit+start, numObjs)
if start >= numObjs {
// page is out of bounds

View File

@ -61,12 +61,7 @@ func newSplitAndApply(
// split messages into slices of length chunkSize
totalMessages := len(msgs)
for i := 0; i < len(msgs); i += chunkSize {
sliceEnd := i + chunkSize
if sliceEnd > totalMessages {
sliceEnd = totalMessages
}
sliceEnd := min(i+chunkSize, totalMessages)
msgChunk := msgs[i:sliceEnd]
if err := genOrBroadcastFn(clientCtx, fs, msgChunk...); err != nil {
return err

View File

@ -36,10 +36,7 @@ func TestPaginationProperty(t *testing.T) {
CountTotal: false,
Reverse: false,
}
end := offset + limit
if end > uint64(len(tableModels)) {
end = uint64(len(tableModels))
}
end := min(offset+limit, uint64(len(tableModels)))
dest := reconstructedTableModels[offset:end]
tableModelsIt := testTableModelIterator(tableModels, nil)
_, err := Paginate(tableModelsIt, pageRequest, &dest)
@ -65,12 +62,7 @@ func TestPaginationProperty(t *testing.T) {
CountTotal: false,
Reverse: false,
}
end := start + limit
if end > uint64(len(tableModels)) {
end = uint64(len(tableModels))
}
end := min(start+limit, uint64(len(tableModels)))
dest := reconstructedTableModels[start:end]
tableModelsIt := testTableModelIterator(tableModels, key)