From 96bd7d21e8be7916d69397d3a024a64cf9837944 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 22 Aug 2024 16:11:14 -0400 Subject: [PATCH] lint --- .golangci.yml | 2 +- testutils/testutils.go | 2 +- x/feemarket/ante/fee.go | 6 +++--- x/feemarket/ante/fee_test.go | 4 ++-- x/feemarket/ante/suite/suite.go | 3 ++- x/feemarket/fuzz/aimd_eip1559_test.go | 8 ++++---- x/feemarket/fuzz/eip1559_test.go | 6 +++--- x/feemarket/post/fee.go | 2 +- x/feemarket/types/state.go | 2 +- x/feemarket/types/state_test.go | 4 ++-- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 54547c3..f00a33c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -9,7 +9,7 @@ linters: disable-all: true enable: - dogsled - - exportloopref + - copyloopvar - goconst - gocritic - gofumpt diff --git a/testutils/testutils.go b/testutils/testutils.go index 2777e78..0bb4dbd 100644 --- a/testutils/testutils.go +++ b/testutils/testutils.go @@ -43,7 +43,7 @@ func RandomAccounts(r *rand.Rand, n int) []Account { func CreateRandomTx(txCfg client.TxConfig, account Account, nonce, numberMsgs, timeout uint64, gasLimit uint64, fees ...sdk.Coin) (authsigning.Tx, error) { msgs := make([]sdk.Msg, numberMsgs) - for i := 0; i < int(numberMsgs); i++ { + for i := 0; i < int(numberMsgs); i++ { //nolint:gosec msgs[i] = &banktypes.MsgSend{ FromAddress: account.Address.String(), ToAddress: account.Address.String(), diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 6d7cc77..6bd15fd 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -115,7 +115,7 @@ func (dfd feeMarketCheckDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simula payCoin = feeCoins[0] } - feeGas := int64(feeTx.GetGas()) + feeGas := int64(feeTx.GetGas()) //nolint:gosec minGasPrice, err := dfd.feemarketKeeper.GetMinGasPrice(ctx, payCoin.GetDenom()) if err != nil { @@ -153,7 +153,7 @@ func (dfd feeMarketCheckDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simula return ctx, err } - ctx = ctx.WithPriority(GetTxPriority(priorityFee, int64(gas), baseGasPrice)) + ctx = ctx.WithPriority(GetTxPriority(priorityFee, int64(gas), baseGasPrice)) //nolint:gosec return next(ctx, tx, simulate) } @@ -237,7 +237,7 @@ func CheckTxFee(ctx sdk.Context, gasPrice sdk.DecCoin, feeCoin sdk.Coin, feeGas // Determine the required fees by multiplying each required minimum gas // price by the gas, where fee = ceil(minGasPrice * gas). - gasConsumed := int64(ctx.GasMeter().GasConsumed()) + gasConsumed := int64(ctx.GasMeter().GasConsumed()) //nolint:gosec gcDec := sdkmath.LegacyNewDec(gasConsumed) glDec := sdkmath.LegacyNewDec(feeGas) diff --git a/x/feemarket/ante/fee_test.go b/x/feemarket/ante/fee_test.go index b90971a..4a81bd6 100644 --- a/x/feemarket/ante/fee_test.go +++ b/x/feemarket/ante/fee_test.go @@ -20,7 +20,7 @@ func TestAnteHandleMock(t *testing.T) { // Same data for every test case gasLimit := antesuite.NewTestGasLimit() - validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit)) + validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit)) //nolint:gosec validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount.TruncateInt())) validFeeDifferentDenom := sdk.NewCoins(sdk.NewCoin("atom", math.Int(validFeeAmount))) @@ -210,7 +210,7 @@ func TestAnteHandle(t *testing.T) { // Same data for every test case gasLimit := antesuite.NewTestGasLimit() - validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit)) + validFeeAmount := types.DefaultMinBaseGasPrice.MulInt64(int64(gasLimit)) //nolint:gosec validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount.TruncateInt())) validFeeDifferentDenom := sdk.NewCoins(sdk.NewCoin("atom", math.Int(validFeeAmount))) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 3e0d2ec..5113539 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -1,9 +1,10 @@ package suite import ( - storetypes "cosmossdk.io/store/types" "testing" + storetypes "cosmossdk.io/store/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" txsigning "cosmossdk.io/x/tx/signing" diff --git a/x/feemarket/fuzz/aimd_eip1559_test.go b/x/feemarket/fuzz/aimd_eip1559_test.go index 46df28d..ef0c331 100644 --- a/x/feemarket/fuzz/aimd_eip1559_test.go +++ b/x/feemarket/fuzz/aimd_eip1559_test.go @@ -142,16 +142,16 @@ func TestAIMDGasPrice(t *testing.T) { // EIP-1559 fee market implementation. func CreateRandomAIMDParams(t *rapid.T) types.Params { a := rapid.Uint64Range(1, 1000).Draw(t, "alpha") - alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(1000)) + alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(1000)) //nolint:gosec b := rapid.Uint64Range(50, 99).Draw(t, "beta") - beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100)) + beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100)) //nolint:gosec g := rapid.Uint64Range(10, 50).Draw(t, "gamma") - gamma := math.LegacyNewDec(int64(g)).Quo(math.LegacyNewDec(100)) + gamma := math.LegacyNewDec(int64(g)).Quo(math.LegacyNewDec(100)) //nolint:gosec d := rapid.Uint64Range(1, 1000).Draw(t, "delta") - delta := math.LegacyNewDec(int64(d)).Quo(math.LegacyNewDec(1000)) + delta := math.LegacyNewDec(int64(d)).Quo(math.LegacyNewDec(1000)) //nolint:gosec targetBlockUtilization := rapid.Uint64Range(1, 30_000_000).Draw(t, "target_block_utilization") maxBlockUtilization := rapid.Uint64Range(targetBlockUtilization, targetBlockUtilization*5).Draw(t, "max_block_utilization") diff --git a/x/feemarket/fuzz/eip1559_test.go b/x/feemarket/fuzz/eip1559_test.go index c17b142..64be719 100644 --- a/x/feemarket/fuzz/eip1559_test.go +++ b/x/feemarket/fuzz/eip1559_test.go @@ -77,13 +77,13 @@ func TestGasPrice(t *testing.T) { // EIP-1559 fee market implementation. func CreateRandomParams(t *rapid.T) types.Params { a := rapid.Uint64Range(1, 1000).Draw(t, "alpha") - alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(1000)) + alpha := math.LegacyNewDec(int64(a)).Quo(math.LegacyNewDec(1000)) //nolint:gosec b := rapid.Uint64Range(50, 99).Draw(t, "beta") - beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100)) + beta := math.LegacyNewDec(int64(b)).Quo(math.LegacyNewDec(100)) //nolint:gosec g := rapid.Uint64Range(10, 50).Draw(t, "gamma") - gamma := math.LegacyNewDec(int64(g)).Quo(math.LegacyNewDec(100)) + gamma := math.LegacyNewDec(int64(g)).Quo(math.LegacyNewDec(100)) //nolint:gosec maxBlockUtilization := rapid.Uint64Range(2, 30_000_000).Draw(t, "max_block_utilization") diff --git a/x/feemarket/post/fee.go b/x/feemarket/post/fee.go index 108af3e..2a9801a 100644 --- a/x/feemarket/post/fee.go +++ b/x/feemarket/post/fee.go @@ -102,7 +102,7 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul payCoin = feeCoins[0] } - feeGas := int64(feeTx.GetGas()) + feeGas := int64(feeTx.GetGas()) //nolint:gosec minGasPrice, err := dfd.feemarketKeeper.GetMinGasPrice(ctx, payCoin.GetDenom()) if err != nil { diff --git a/x/feemarket/types/state.go b/x/feemarket/types/state.go index d76ff20..bedd715 100644 --- a/x/feemarket/types/state.go +++ b/x/feemarket/types/state.go @@ -156,7 +156,7 @@ func (s *State) GetAverageUtilization(params Params) math.LegacyDec { // ValidateBasic performs basic validation on the state. func (s *State) ValidateBasic() error { - if s.Window == nil || len(s.Window) == 0 { + if s.Window == nil { return fmt.Errorf("block utilization window cannot be nil or empty") } diff --git a/x/feemarket/types/state_test.go b/x/feemarket/types/state_test.go index 0083f36..39ce757 100644 --- a/x/feemarket/types/state_test.go +++ b/x/feemarket/types/state_test.go @@ -351,7 +351,7 @@ func TestState_UpdateBaseGasPrice(t *testing.T) { expectedLR := prevLR.Add(params.Alpha) expectedLRAdjustment := (expectedLR.Mul(expectedUtilization)).Add(math.LegacyOneDec()) - expectedNetUtilization := math.LegacyNewDec(-1 * int64(params.TargetBlockUtilization()) / 2) + expectedNetUtilization := math.LegacyNewDec(-1 * int64(params.TargetBlockUtilization()) / 2) //nolint:gosec deltaDiff := expectedNetUtilization.Mul(params.Delta) expectedGasPrice := prevBF.Mul(expectedLRAdjustment).Add(deltaDiff) @@ -381,7 +381,7 @@ func TestState_UpdateBaseGasPrice(t *testing.T) { expectedLR := prevLR.Add(params.Alpha) expectedLRAdjustment := (expectedLR.Mul(expectedUtilization)).Add(math.LegacyOneDec()) - expectedNetUtilization := math.LegacyNewDec(int64(params.MaxBlockUtilization) / 4) + expectedNetUtilization := math.LegacyNewDec(int64(params.MaxBlockUtilization) / 4) //nolint:gosec deltaDiff := expectedNetUtilization.Mul(params.Delta) expectedGasPrice := prevBGS.Mul(expectedLRAdjustment).Add(deltaDiff) require.Equal(t, expectedLR, lr)