From ef59041fccec4de65785d40c305063287d5eac04 Mon Sep 17 00:00:00 2001 From: jinoosss Date: Wed, 27 Nov 2024 14:29:30 +0900 Subject: [PATCH] fix: fix a test --- serve/filters/subscription/gas_test.go | 4 ++-- serve/methods/gas.go | 15 +++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/serve/filters/subscription/gas_test.go b/serve/filters/subscription/gas_test.go index 55b0746..47253f8 100644 --- a/serve/filters/subscription/gas_test.go +++ b/serve/filters/subscription/gas_test.go @@ -18,7 +18,7 @@ func TestGasPriceSubscription_WriteResponse(t *testing.T) { var ( capturedWrite any - mockTxResults = []*types.TxResult{} + mockBlock = &types.Block{} mockGasPrices = []*methods.GasPrice{} ) @@ -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) diff --git a/serve/methods/gas.go b/serve/methods/gas.go index 96dca39..3e79835 100644 --- a/serve/methods/gas.go +++ b/serve/methods/gas.go @@ -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++ @@ -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++ @@ -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 -}