Skip to content

Commit 9acd771

Browse files
authored
chore(all): modernized code with built-in min/max (#24124)
1 parent 94068be commit 9acd771

File tree

4 files changed

+5
-26
lines changed

4 files changed

+5
-26
lines changed

baseapp/block_gas_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
175175
}
176176
// check block gas is always consumed
177177
baseGas := uint64(57504) // baseGas is the gas consumed before tx msg
178-
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
179-
if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) {
180-
// capped by gasLimit
181-
expGasConsumed = uint64(simtestutil.DefaultConsensusParams.Block.MaxGas)
182-
}
178+
expGasConsumed := min(addUint64Saturating(tc.gasToConsume, baseGas), uint64(simtestutil.DefaultConsensusParams.Block.MaxGas))
183179
require.Equal(t, int(expGasConsumed), int(ctx.BlockGasMeter().GasConsumed()))
184180
// tx fee is always deducted
185181
require.Equal(t, int64(0), bankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount.Int64())

client/utils.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ func Paginate(numObjs, page, limit, defLimit int) (start, end int) {
3535
}
3636

3737
start = (page - 1) * limit
38-
end = limit + start
39-
40-
if end >= numObjs {
41-
end = numObjs
42-
}
38+
end = min(limit+start, numObjs)
4339

4440
if start >= numObjs {
4541
// page is out of bounds

x/distribution/client/cli/tx.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ func newSplitAndApply(
6161
// split messages into slices of length chunkSize
6262
totalMessages := len(msgs)
6363
for i := 0; i < len(msgs); i += chunkSize {
64-
65-
sliceEnd := i + chunkSize
66-
if sliceEnd > totalMessages {
67-
sliceEnd = totalMessages
68-
}
69-
64+
sliceEnd := min(i+chunkSize, totalMessages)
7065
msgChunk := msgs[i:sliceEnd]
7166
if err := genOrBroadcastFn(clientCtx, fs, msgChunk...); err != nil {
7267
return err

x/group/internal/orm/iterator_property_test.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ func TestPaginationProperty(t *testing.T) {
3636
CountTotal: false,
3737
Reverse: false,
3838
}
39-
end := offset + limit
40-
if end > uint64(len(tableModels)) {
41-
end = uint64(len(tableModels))
42-
}
39+
end := min(offset+limit, uint64(len(tableModels)))
4340
dest := reconstructedTableModels[offset:end]
4441
tableModelsIt := testTableModelIterator(tableModels, nil)
4542
_, err := Paginate(tableModelsIt, pageRequest, &dest)
@@ -65,12 +62,7 @@ func TestPaginationProperty(t *testing.T) {
6562
CountTotal: false,
6663
Reverse: false,
6764
}
68-
69-
end := start + limit
70-
if end > uint64(len(tableModels)) {
71-
end = uint64(len(tableModels))
72-
}
73-
65+
end := min(start+limit, uint64(len(tableModels)))
7466
dest := reconstructedTableModels[start:end]
7567
tableModelsIt := testTableModelIterator(tableModels, key)
7668

0 commit comments

Comments
 (0)