Skip to content

Commit

Permalink
fix: fix a test
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Nov 27, 2024
1 parent 3ff010d commit ef59041
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
4 changes: 2 additions & 2 deletions serve/filters/subscription/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGasPriceSubscription_WriteResponse(t *testing.T) {
var (
capturedWrite any

mockTxResults = []*types.TxResult{}
mockBlock = &types.Block{}
mockGasPrices = []*methods.GasPrice{}
)

Expand All @@ -36,7 +36,7 @@ func TestGasPriceSubscription_WriteResponse(t *testing.T) {
gasPriceSubscription := NewGasPriceSubscription(mockConn)

// Write the response
require.NoError(t, gasPriceSubscription.WriteResponse("", mockTxResults))
require.NoError(t, gasPriceSubscription.WriteResponse("", mockBlock))

// Make sure the captured data matches
require.NotNil(t, capturedWrite)
Expand Down
15 changes: 3 additions & 12 deletions serve/methods/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func calculateGasFeePerBlock(block *types.Block) map[string]*gasFeeTotalInfo {
gasFeeInfo[denom] = info
}

info.Low = min(info.Low, amount)
info.Low = minInt64WithDefault(info.Low, amount)
info.High = max(info.High, amount)
info.TotalAmount += amount
info.TotalCount++
Expand All @@ -73,7 +73,7 @@ func calculateGasFee(currentInfo, blockInfo *gasFeeTotalInfo) *gasFeeTotalInfo {
currentInfo = &gasFeeTotalInfo{}
}

currentInfo.Low = min(currentInfo.Low, blockInfo.Low)
currentInfo.Low = minInt64WithDefault(currentInfo.Low, blockInfo.Low)
currentInfo.High = max(currentInfo.High, blockInfo.High)
currentInfo.TotalAmount += blockInfo.TotalAmount / blockInfo.TotalCount
currentInfo.TotalCount++
Expand Down Expand Up @@ -103,19 +103,10 @@ func calculateGasPrices(gasFeeInfoMap map[string]*gasFeeTotalInfo) []*GasPrice {

// min calculates the smaller of two values, or returns the new value
// if the current value is uninitialized (0).
func min(current, newValue int64) int64 {
func minInt64WithDefault(current, newValue int64) int64 {
if current == 0 || newValue < current {
return newValue
}

return current
}

// max calculates the larger of two values.
func max(current, newValue int64) int64 {
if newValue > current {
return newValue
}

return current
}

0 comments on commit ef59041

Please sign in to comment.