Skip to content

Commit

Permalink
chore: lint tests (evmos#1194)
Browse files Browse the repository at this point in the history
* fix the first 50 lint issues

* 110 issues remaining

* 54 issues remaining

* 54 issues remaining

* adjust max-same-issues to 200

* more errcheck lints

* 29 errcheck lints remain

* 28 errcheck lints remain

* 24 errcheck lints remain

* 22 errcheck lints remaining

* tests fully linted

* Update .golangci.yml

* Update CHANGELOG.md

* ignore the token in proposal_test.go

* add a .gitleaksignore file

* allow the token on line 252 of proposal_test.go

* golangci-lint run ./... --fix

* Update x/erc20/keeper/evm_hooks_test.go

Co-authored-by: Tomas Guerra <[email protected]>

* cleanup pr

* address @GAtom22 review

Co-authored-by: Tomas Guerra <[email protected]>
Co-authored-by: Federico Kunze Küllmer <[email protected]>
  • Loading branch information
3 people authored Jan 14, 2023
1 parent 04a3250 commit 1d45142
Show file tree
Hide file tree
Showing 82 changed files with 509 additions and 456 deletions.
44 changes: 13 additions & 31 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
run:
tests: false
# timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
tests: true
timeout: 5m
concurrency: 4

linters:
enable:
# - bodyclose
- depguard
- dogsled
- dupl
Expand All @@ -20,39 +19,22 @@ linters:
- ineffassign
# - lll TODO: enable
- misspell
# - maligned
- nakedret
- prealloc
- exportloopref
- staticcheck
# - structcheck
- stylecheck
- typecheck
- unconvert
# - unparam
- unparam
- unused
# - nolintlint
- nolintlint
- asciicheck
# - exhaustive
- exportloopref
- gofumpt
- gomodguard
# - nestif
# - nlreturn
# - noctx
# - rowserrcheck
# - whitespace
# - wsl

issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
- linters:
- lll
source: "https://"
max-same-issues: 50


linters-settings:
dogsled:
Expand All @@ -72,10 +54,10 @@ linters-settings:
lang-version: "1.19"
gomodguard:
blocked:
versions: # List of blocked module version constraints
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
versions: # List of blocked module version constraints
- https://github.com/etcd-io/etcd: # Blocked module with version constraint
version: ">= 3.4.10 || ~3.3.23" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-15114; CVE-2020-15136; CVE-2020-15115" # Reason why the version constraint exists. (Optional)
- https://github.com/dgrijalva/jwt-go: # Blocked module with version constraint
version: ">= 4.0.0-preview1" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
reason: "CVE-2020-26160" # Reason why the version constraint exists. (Optional)
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

- (tests) [\1194](https://github.com/evmos/evmos/pull/1194) Lint tests so they are consistent with non-test code.
- (deps) [\#1176](https://github.com/evmos/evmos/pull/1176) Bump Cosmos SDK to [`v0.46.7`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.7)
- (ci) [#1138](https://github.com/evmos/evmos/pull/1138) Add Golang dependency vulnerability checker.
- (docs) [\#1090](https://github.com/evmos/evmos/pull/1090) Add audits page to documentation.
Expand Down
2 changes: 1 addition & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
anteHandler = newEthAnteHandler(options)
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newLegacyCosmosAnteHandlerEip712(options) // nolint: staticcheck
anteHandler = newLegacyCosmosAnteHandlerEip712(options)
default:
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
Expand Down
2 changes: 1 addition & 1 deletion app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
// Note: signature verification uses EIP instead of the cosmos signature validator
// nolint: staticcheck
//nolint: staticcheck
ethante.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
Expand Down
8 changes: 4 additions & 4 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (suite *AnteTestSuite) SetupTest(isCheckTx bool) {
suite.denom = claimstypes.DefaultClaimsDenom
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
evmParams.EvmDenom = suite.denom
suite.app.EvmKeeper.SetParams(suite.ctx, evmParams)
_ = suite.app.EvmKeeper.SetParams(suite.ctx, evmParams)
}

func TestAnteTestSuite(t *testing.T) {
Expand Down Expand Up @@ -102,7 +102,7 @@ func (suite *AnteTestSuite) CommitAfter(t time.Duration) {
suite.ctx = suite.app.BaseApp.NewContext(false, header)
}

func (s *AnteTestSuite) CreateTestTxBuilder(gasPrice math.Int, denom string, msgs ...sdk.Msg) client.TxBuilder {
func (suite *AnteTestSuite) CreateTestTxBuilder(gasPrice math.Int, denom string, msgs ...sdk.Msg) client.TxBuilder {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
gasLimit := uint64(1000000)

Expand All @@ -116,7 +116,7 @@ func (s *AnteTestSuite) CreateTestTxBuilder(gasPrice math.Int, denom string, msg
return txBuilder
}

func (s *AnteTestSuite) CreateEthTestTxBuilder(msgEthereumTx *evmtypes.MsgEthereumTx) client.TxBuilder {
func (suite *AnteTestSuite) CreateEthTestTxBuilder(msgEthereumTx *evmtypes.MsgEthereumTx) client.TxBuilder {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{})
s.Require().NoError(err)
Expand All @@ -139,7 +139,7 @@ func (s *AnteTestSuite) CreateEthTestTxBuilder(msgEthereumTx *evmtypes.MsgEthere
return txBuilder
}

func (s *AnteTestSuite) BuildTestEthTx(
func (suite *AnteTestSuite) BuildTestEthTx(
from common.Address,
to common.Address,
gasPrice *big.Int,
Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (app *Evmos) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []s
app.DistrKeeper.SetFeePool(ctx, feePool)

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
if err != nil { // nolint:gosimple // this lets us stop in case there's an error
if err != nil { //nolint:gosimple // this lets us stop in case there's an error
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion app/sigverify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestConsumeSignatureVerificationGas(t *testing.T) {
expectedCost1 := expectedGasCostByKeys(pkSet1)

for i := 0; i < len(pkSet1); i++ {
stdSig := legacytx.StdSignature{PubKey: pkSet1[i], Signature: sigSet1[i]}
stdSig := legacytx.StdSignature{PubKey: pkSet1[i], Signature: sigSet1[i]} //nolint:staticcheck
sigV2, err := legacytx.StdSignatureToSignatureV2(cdc, stdSig)
require.NoError(t, err)
err = multisig.AddSignatureV2(multisignature1, sigV2, pkSet1)
Expand Down
2 changes: 1 addition & 1 deletion app/tps_counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestTPSCounter(t *testing.T) {
tpc := newTPSCounter(wlog)
tpc.reportPeriod = 5 * time.Millisecond
ctx, cancel := context.WithCancel(context.Background())
go tpc.start(ctx)
go tpc.start(ctx) //nolint:errcheck

// Concurrently increment the counter.
n := 50
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v11/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (suite *UpgradeTestSuite) TestDistributeRewards() {
suite.Require().True(ok, "error converting rewards")

var validatorAddresses []string
validatorDelegations := make(map[string]sdk.Int)
validatorDelegations := make(map[string]math.Int)
actualRewards := math.ZeroInt()

for _, allocation := range v11.Allocations {
Expand Down
6 changes: 4 additions & 2 deletions app/upgrades/v9/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ func (suite *UpgradeTestSuite) TestReturnFundsFromCommunityPool() {
sender := sdk.AccAddress(address.Bytes())
res, _ := sdk.NewIntFromString(v9.MaxRecover)
coins := sdk.NewCoins(sdk.NewCoin("aevmos", res))
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
err = suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.Require().NoError(err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
suite.Require().NoError(err)
err = suite.app.DistrKeeper.FundCommunityPool(suite.ctx, coins, sender)
suite.Require().NoError(err)

Expand Down
24 changes: 15 additions & 9 deletions app/upgrades/v9_1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (suite *UpgradeTestSuite) TestMigrateFaucetBalance() {
expectedSuccess bool
}{
{
"Mainnet - sucess",
"Mainnet - success",
evmostypes.MainnetChainID + "-4",
func() {
// send funds to the community pool
Expand All @@ -97,8 +97,10 @@ func (suite *UpgradeTestSuite) TestMigrateFaucetBalance() {
sender := sdk.AccAddress(address.Bytes())
res, _ := sdk.NewIntFromString(v9.MaxRecover)
coins := sdk.NewCoins(sdk.NewCoin("aevmos", res))
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
err = suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.Require().NoError(err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
suite.Require().NoError(err)
err = suite.app.DistrKeeper.FundCommunityPool(suite.ctx, coins, sender)
suite.Require().NoError(err)

Expand All @@ -107,7 +109,7 @@ func (suite *UpgradeTestSuite) TestMigrateFaucetBalance() {
},
true,
},
{
{ //nolint:dupl
"Mainnet - first account > MaxRecover",
evmostypes.MainnetChainID + "-4",
func() {
Expand All @@ -118,8 +120,10 @@ func (suite *UpgradeTestSuite) TestMigrateFaucetBalance() {
sender := sdk.AccAddress(address.Bytes())
res, _ := sdk.NewIntFromString(v9.MaxRecover)
coins := sdk.NewCoins(sdk.NewCoin("aevmos", res))
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
err = suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.Require().NoError(err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
suite.Require().NoError(err)
err = suite.app.DistrKeeper.FundCommunityPool(suite.ctx, coins, sender)
suite.Require().NoError(err)

Expand All @@ -130,7 +134,7 @@ func (suite *UpgradeTestSuite) TestMigrateFaucetBalance() {
},
false,
},
{
{ //nolint:dupl
"Mainnet - middle account > MaxRecover",
evmostypes.MainnetChainID + "-4",
func() {
Expand All @@ -141,8 +145,10 @@ func (suite *UpgradeTestSuite) TestMigrateFaucetBalance() {
sender := sdk.AccAddress(address.Bytes())
res, _ := sdk.NewIntFromString(v9.MaxRecover)
coins := sdk.NewCoins(sdk.NewCoin("aevmos", res))
suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
err = suite.app.BankKeeper.MintCoins(suite.ctx, types.ModuleName, coins)
suite.Require().NoError(err)
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, sender, coins)
suite.Require().NoError(err)
err = suite.app.DistrKeeper.FundCommunityPool(suite.ctx, coins, sender)
suite.Require().NoError(err)

Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package statik

// unnamed import of statik for swagger UI support
// override ethermint statik by importing it
// nolint
//nolint
import _ "github.com/evmos/ethermint/client/docs/statik"

// This just for fixing the error in importing empty github.com/evmos/ethermint/client/docs/statik
2 changes: 1 addition & 1 deletion cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func SetBech32Prefixes(config *sdk.Config) {
func SetBip44CoinType(config *sdk.Config) {
config.SetCoinType(ethermint.Bip44CoinType)
config.SetPurpose(sdk.Purpose) // Shared
config.SetFullFundraiserPath(ethermint.BIP44HDPath) // nolint: staticcheck
config.SetFullFundraiserPath(ethermint.BIP44HDPath) //nolint: staticcheck
}

// RegisterDenoms registers the base and display denominations to the SDK.
Expand Down
2 changes: 1 addition & 1 deletion contracts/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var (
//go:embed compiled_contracts/ERC20MinterBurnerDecimals.json
ERC20MinterBurnerDecimalsJSON []byte // nolint: golint
ERC20MinterBurnerDecimalsJSON []byte //nolint: golint

// ERC20MinterBurnerDecimalsContract is the compiled erc20 contract
ERC20MinterBurnerDecimalsContract evmtypes.CompiledContract
Expand Down
2 changes: 1 addition & 1 deletion contracts/erc20DirectBalanceManipulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// a predefined C is given a massive allowance on B.
var (
//go:embed compiled_contracts/ERC20DirectBalanceManipulation.json
ERC20DirectBalanceManipulationJSON []byte // nolint: golint
ERC20DirectBalanceManipulationJSON []byte //nolint: golint

// ERC20DirectBalanceManipulationContract is the compiled erc20 contract
ERC20DirectBalanceManipulationContract evmtypes.CompiledContract
Expand Down
2 changes: 1 addition & 1 deletion contracts/erc20maliciousdelayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// a predefined C is given a massive allowance on B.
var (
//go:embed compiled_contracts/ERC20MaliciousDelayed.json
ERC20MaliciousDelayedJSON []byte // nolint: golint
ERC20MaliciousDelayedJSON []byte //nolint: golint

// ERC20MaliciousDelayedContract is the compiled erc20 contract
ERC20MaliciousDelayedContract evmtypes.CompiledContract
Expand Down
18 changes: 9 additions & 9 deletions ibc/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type MockIBCModule struct {

// OnChanOpenInit implements the Module interface
// It calls the underlying app's OnChanOpenInit callback.
func (m MockIBCModule) OnChanOpenInit(
func (m MockIBCModule) OnChanOpenInit( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
Expand All @@ -41,7 +41,7 @@ func (m MockIBCModule) OnChanOpenInit(

// OnChanOpenTry implements the Module interface.
// It calls the underlying app's OnChanOpenTry callback.
func (m MockIBCModule) OnChanOpenTry(
func (m MockIBCModule) OnChanOpenTry( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
Expand All @@ -57,7 +57,7 @@ func (m MockIBCModule) OnChanOpenTry(

// OnChanOpenAck implements the Module interface.
// It calls the underlying app's OnChanOpenAck callback.
func (m MockIBCModule) OnChanOpenAck(
func (m MockIBCModule) OnChanOpenAck( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
portID,
channelID,
Expand All @@ -70,7 +70,7 @@ func (m MockIBCModule) OnChanOpenAck(

// OnChanOpenConfirm implements the Module interface.
// It calls the underlying app's OnChanOpenConfirm callback.
func (m MockIBCModule) OnChanOpenConfirm(
func (m MockIBCModule) OnChanOpenConfirm( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
portID,
channelID string,
Expand All @@ -81,7 +81,7 @@ func (m MockIBCModule) OnChanOpenConfirm(

// OnChanCloseInit implements the Module interface
// It calls the underlying app's OnChanCloseInit callback.
func (m MockIBCModule) OnChanCloseInit(
func (m MockIBCModule) OnChanCloseInit( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
portID,
channelID string,
Expand All @@ -92,7 +92,7 @@ func (m MockIBCModule) OnChanCloseInit(

// OnChanCloseConfirm implements the Module interface.
// It calls the underlying app's OnChanCloseConfirm callback.
func (m MockIBCModule) OnChanCloseConfirm(
func (m MockIBCModule) OnChanCloseConfirm( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
portID,
channelID string,
Expand All @@ -103,7 +103,7 @@ func (m MockIBCModule) OnChanCloseConfirm(

// OnRecvPacket implements the Module interface.
// It calls the underlying app's OnRecvPacket callback.
func (m MockIBCModule) OnRecvPacket(
func (m MockIBCModule) OnRecvPacket( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
Expand All @@ -114,7 +114,7 @@ func (m MockIBCModule) OnRecvPacket(

// OnAcknowledgementPacket implements the Module interface.
// It calls the underlying app's OnAcknowledgementPacket callback.
func (m MockIBCModule) OnAcknowledgementPacket(
func (m MockIBCModule) OnAcknowledgementPacket( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
packet channeltypes.Packet,
acknowledgement []byte,
Expand All @@ -126,7 +126,7 @@ func (m MockIBCModule) OnAcknowledgementPacket(

// OnTimeoutPacket implements the Module interface.
// It calls the underlying app's OnTimeoutPacket callback.
func (m MockIBCModule) OnTimeoutPacket(
func (m MockIBCModule) OnTimeoutPacket( //nolint:govet // we can copy locks here because it is a test
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (s *IntegrationTestSuite) runInitialNode() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// wait untill node starts and produce some blocks
// wait until node starts and produce some blocks
err = s.upgradeManager.WaitForHeight(ctx, 5)
s.Require().NoError(err)

Expand Down
Loading

0 comments on commit 1d45142

Please sign in to comment.