From 7389770b10c5a7f6d4b2c31b752f365d1359e246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Thu, 26 Aug 2021 11:45:45 -0400 Subject: [PATCH] ci: lint (#500) --- .golangci.yml | 44 ++++++++++------------ client/testnet.go | 32 ++++++++-------- cmd/config/config_test.go | 4 +- crypto/ethsecp256k1/ethsecp256k1.go | 16 ++++---- ethereum/rpc/namespaces/debug/internal.go | 2 +- ethereum/rpc/namespaces/eth/api.go | 2 +- ethereum/rpc/namespaces/eth/filters/api.go | 2 +- ethereum/rpc/namespaces/personal/api.go | 2 +- tests/rpc/utils.go | 5 +-- x/evm/genesis.go | 1 - x/feemarket/client/cli/query.go | 34 ++++++++++------- 11 files changed, 71 insertions(+), 73 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 19463f15..81ba5f93 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,15 +1,15 @@ run: tests: false -# # timeout for analysis, e.g. 30s, 5m, default is 1m -# timeout: 5m + # timeout for analysis, e.g. 30s, 5m, default is 1m + # timeout: 5m linters: - disable-all: true enable: - bodyclose - deadcode - depguard - dogsled + - dupl - errcheck - goconst - gocritic @@ -20,9 +20,9 @@ linters: - gosimple - govet - ineffassign - - interfacer - - maligned + # - lll TODO: enable - misspell + - maligned - nakedret - prealloc - scopelint @@ -31,39 +31,33 @@ linters: - stylecheck - typecheck - unconvert - - unused - unparam - - misspell - # TODO: address these lint issues + - unused + - varcheck + - nolintlint + - asciicheck + # - whitespace # - wsl - # - nolintlint issues: exclude-rules: - - text: "Use of weak random number generator" + - path: _test\.go linters: - gosec - - text: "comment on exported var" - linters: - - golint - - text: "don't use an underscore in package name" - linters: - - golint - - text: "ST1003:" - linters: - - stylecheck - - text: "SA1019:" - linters: - - staticcheck - max-issues-per-linter: 10000 - max-same-issues: 10000 + - linters: + - lll + source: "https://" + max-same-issues: 50 linters-settings: dogsled: max-blank-identifiers: 3 + golint: + min-confidence: 0 maligned: - # print struct with more effective memory layout or not, false by default suggest-new: true + misspell: + locale: US nolintlint: allow-unused: false allow-leading-space: true diff --git a/client/testnet.go b/client/testnet.go index b3353b85..8a2efa96 100644 --- a/client/testnet.go +++ b/client/testnet.go @@ -320,11 +320,11 @@ func initGenFiles( numValidators int, ) error { - appGenState := mbm.DefaultGenesis(clientCtx.JSONCodec) + appGenState := mbm.DefaultGenesis(clientCtx.Codec) // set the accounts in the genesis state var authGenState authtypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) accounts, err := authtypes.PackAccounts(genAccounts) if err != nil { @@ -332,44 +332,44 @@ func initGenFiles( } authGenState.Accounts = accounts - appGenState[authtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&authGenState) + appGenState[authtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&authGenState) // set the balances in the genesis state var bankGenState banktypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) bankGenState.Balances = genBalances - appGenState[banktypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&bankGenState) + appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState) var stakingGenState stakingtypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[stakingtypes.ModuleName], &stakingGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[stakingtypes.ModuleName], &stakingGenState) stakingGenState.Params.BondDenom = coinDenom - appGenState[stakingtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&stakingGenState) + appGenState[stakingtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&stakingGenState) var govGenState govtypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState) govGenState.DepositParams.MinDeposit[0].Denom = coinDenom - appGenState[govtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&govGenState) + appGenState[govtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&govGenState) var mintGenState mintypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[mintypes.ModuleName], &mintGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[mintypes.ModuleName], &mintGenState) mintGenState.Params.MintDenom = coinDenom - appGenState[mintypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&mintGenState) + appGenState[mintypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&mintGenState) var crisisGenState crisistypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState) crisisGenState.ConstantFee.Denom = coinDenom - appGenState[crisistypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&crisisGenState) + appGenState[crisistypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&crisisGenState) var evmGenState evmtypes.GenesisState - clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[evmtypes.ModuleName], &evmGenState) + clientCtx.Codec.MustUnmarshalJSON(appGenState[evmtypes.ModuleName], &evmGenState) evmGenState.Params.EvmDenom = coinDenom - appGenState[evmtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&evmGenState) + appGenState[evmtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&evmGenState) appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") if err != nil { @@ -416,7 +416,7 @@ func collectGenFiles( return err } - nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.JSONCodec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator) + nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, *genDoc, genBalIterator) if err != nil { return err } diff --git a/cmd/config/config_test.go b/cmd/config/config_test.go index 9f1bd541..187031a2 100644 --- a/cmd/config/config_test.go +++ b/cmd/config/config_test.go @@ -39,12 +39,12 @@ func TestSetBech32Prefixes(t *testing.T) { func TestSetCoinType(t *testing.T) { config := sdk.GetConfig() require.Equal(t, sdk.CoinType, int(config.GetCoinType())) - require.Equal(t, sdk.FullFundraiserPath, config.GetFullFundraiserPath()) + require.Equal(t, sdk.FullFundraiserPath, config.GetFullBIP44Path()) SetBip44CoinType(config) require.Equal(t, int(ethermint.Bip44CoinType), int(config.GetCoinType())) require.Equal(t, sdk.GetConfig().GetCoinType(), config.GetCoinType()) - require.Equal(t, sdk.GetConfig().GetFullFundraiserPath(), config.GetFullFundraiserPath()) + require.Equal(t, sdk.GetConfig().GetFullBIP44Path(), config.GetFullBIP44Path()) } func TestHDPath(t *testing.T) { diff --git a/crypto/ethsecp256k1/ethsecp256k1.go b/crypto/ethsecp256k1/ethsecp256k1.go index 2a22ae63..c921738a 100644 --- a/crypto/ethsecp256k1/ethsecp256k1.go +++ b/crypto/ethsecp256k1/ethsecp256k1.go @@ -76,12 +76,12 @@ func (privKey PrivKey) Type() string { return KeyType } -// MarshalAmino overrides Amino binary marshalling. +// MarshalAmino overrides Amino binary marshaling. func (privKey PrivKey) MarshalAmino() ([]byte, error) { return privKey.Key, nil } -// UnmarshalAmino overrides Amino binary marshalling. +// UnmarshalAmino overrides Amino binary marshaling. func (privKey *PrivKey) UnmarshalAmino(bz []byte) error { if len(bz) != PrivKeySize { return fmt.Errorf("invalid privkey size, expected %d got %d", PrivKeySize, len(bz)) @@ -91,14 +91,14 @@ func (privKey *PrivKey) UnmarshalAmino(bz []byte) error { return nil } -// MarshalAminoJSON overrides Amino JSON marshalling. +// MarshalAminoJSON overrides Amino JSON marshaling. func (privKey PrivKey) MarshalAminoJSON() ([]byte, error) { // When we marshal to Amino JSON, we don't marshal the "key" field itself, // just its contents (i.e. the key bytes). return privKey.MarshalAmino() } -// UnmarshalAminoJSON overrides Amino JSON marshalling. +// UnmarshalAminoJSON overrides Amino JSON marshaling. func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error { return privKey.UnmarshalAmino(bz) } @@ -163,12 +163,12 @@ func (pubKey PubKey) Equals(other cryptotypes.PubKey) bool { return pubKey.Type() == other.Type() && bytes.Equal(pubKey.Bytes(), other.Bytes()) } -// MarshalAmino overrides Amino binary marshalling. +// MarshalAmino overrides Amino binary marshaling. func (pubKey PubKey) MarshalAmino() ([]byte, error) { return pubKey.Key, nil } -// UnmarshalAmino overrides Amino binary marshalling. +// UnmarshalAmino overrides Amino binary marshaling. func (pubKey *PubKey) UnmarshalAmino(bz []byte) error { if len(bz) != PubKeySize { return sdkerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "invalid pubkey size, expected %d, got %d", PubKeySize, len(bz)) @@ -178,14 +178,14 @@ func (pubKey *PubKey) UnmarshalAmino(bz []byte) error { return nil } -// MarshalAminoJSON overrides Amino JSON marshalling. +// MarshalAminoJSON overrides Amino JSON marshaling. func (pubKey PubKey) MarshalAminoJSON() ([]byte, error) { // When we marshal to Amino JSON, we don't marshal the "key" field itself, // just its contents (i.e. the key bytes). return pubKey.MarshalAmino() } -// UnmarshalAminoJSON overrides Amino JSON marshalling. +// UnmarshalAminoJSON overrides Amino JSON marshaling. func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error { return pubKey.UnmarshalAmino(bz) } diff --git a/ethereum/rpc/namespaces/debug/internal.go b/ethereum/rpc/namespaces/debug/internal.go index 6675af81..be8dec57 100644 --- a/ethereum/rpc/namespaces/debug/internal.go +++ b/ethereum/rpc/namespaces/debug/internal.go @@ -56,7 +56,7 @@ func (a *InternalAPI) BlockProfile(file string, nsec uint) error { // CpuProfile turns on CPU profiling for nsec seconds and writes // profile data to file. -func (a *InternalAPI) CpuProfile(file string, nsec uint) error { // nolint: golint +func (a *InternalAPI) CpuProfile(file string, nsec uint) error { // nolint: golint, stylecheck a.logger.Debug("debug_cpuProfile", "file", file, "nsec", nsec) if err := a.StartCPUProfile(file); err != nil { return err diff --git a/ethereum/rpc/namespaces/eth/api.go b/ethereum/rpc/namespaces/eth/api.go index 5935e7f5..4b908643 100644 --- a/ethereum/rpc/namespaces/eth/api.go +++ b/ethereum/rpc/namespaces/eth/api.go @@ -893,7 +893,7 @@ func (e *PublicAPI) GetProof(address common.Address, storageKeys []string, block func (e *PublicAPI) getBlockNumber(blockNrOrHash rpctypes.BlockNumberOrHash) (rpctypes.BlockNumber, error) { switch { case blockNrOrHash.BlockHash == nil && blockNrOrHash.BlockNumber == nil: - return rpctypes.EthEarliestBlockNumber, fmt.Errorf("BlockHash and BlockNumber cannot be both nil") + return rpctypes.EthEarliestBlockNumber, fmt.Errorf("types BlockHash and BlockNumber cannot be both nil") case blockNrOrHash.BlockHash != nil: blockHeader, err := e.backend.HeaderByHash(*blockNrOrHash.BlockHash) if err != nil { diff --git a/ethereum/rpc/namespaces/eth/filters/api.go b/ethereum/rpc/namespaces/eth/filters/api.go index f52ef5ec..c65dc43e 100644 --- a/ethereum/rpc/namespaces/eth/filters/api.go +++ b/ethereum/rpc/namespaces/eth/filters/api.go @@ -191,7 +191,7 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su txHash := common.BytesToHash(tmtypes.Tx(data.Tx).Hash()) - // To keep the original behaviour, send a single tx hash in one notification. + // To keep the original behavior, send a single tx hash in one notification. // TODO(rjl493456442) Send a batch of tx hashes in one notification err = notifier.Notify(rpcSub.ID, txHash) if err != nil { diff --git a/ethereum/rpc/namespaces/personal/api.go b/ethereum/rpc/namespaces/personal/api.go index 0b955727..af5bd2aa 100644 --- a/ethereum/rpc/namespaces/personal/api.go +++ b/ethereum/rpc/namespaces/personal/api.go @@ -39,7 +39,7 @@ type PrivateAccountAPI struct { // NewAPI creates an instance of the public Personal Eth API. func NewAPI(logger log.Logger, clientCtx client.Context, backend backend.Backend) *PrivateAccountAPI { cfg := sdk.GetConfig() - basePath := cfg.GetFullFundraiserPath() + basePath := cfg.GetFullBIP44Path() iterator, err := ethermint.NewHDPathIterator(basePath, true) if err != nil { diff --git a/tests/rpc/utils.go b/tests/rpc/utils.go index b3bbab88..e287be40 100644 --- a/tests/rpc/utils.go +++ b/tests/rpc/utils.go @@ -74,7 +74,7 @@ func Call(t *testing.T, method string, params interface{}) *Response { if HOST == "" { HOST = "http://localhost:8545" } - res, err := http.Post(HOST, "application/json", bytes.NewBuffer(req)) //nolint:gosec + res, err := http.Post(HOST, "application/json", bytes.NewBuffer(req)) // nolint:gosec require.NoError(t, err) decoder := json.NewDecoder(res.Body) @@ -102,7 +102,7 @@ func CallWithError(method string, params interface{}) (*Response, error) { if HOST == "" { HOST = "http://localhost:8545" } - res, err := http.Post(HOST, "application/json", bytes.NewBuffer(req)) //nolint:gosec + res, err := http.Post(HOST, "application/json", bytes.NewBuffer(req)) // nolint:gosec if err != nil { return nil, err } @@ -222,7 +222,6 @@ func DeployTestContractWithFunction(t *testing.T, addr []byte) hexutil.Bytes { return hash } -//nolint func GetTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} { param := []string{hash.String()} rpcRes := Call(t, "eth_getTransactionReceipt", param) diff --git a/x/evm/genesis.go b/x/evm/genesis.go index 0b487353..f207c92e 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -66,7 +66,6 @@ func InitGenesis( func ExportGenesis(ctx sdk.Context, k *keeper.Keeper, ak types.AccountKeeper) *types.GenesisState { k.WithContext(ctx) - // nolint: prealloc var ethGenAccounts []types.GenesisAccount ak.IterateAccounts(ctx, func(account authtypes.AccountI) bool { ethAccount, ok := account.(*ethermint.EthAccount) diff --git a/x/feemarket/client/cli/query.go b/x/feemarket/client/cli/query.go index 42ff7813..db51c1f0 100644 --- a/x/feemarket/client/cli/query.go +++ b/x/feemarket/client/cli/query.go @@ -1,6 +1,7 @@ package cli import ( + "context" "fmt" "strconv" @@ -37,8 +38,9 @@ func GetBlockGasCmd() *cobra.Command { cmd := &cobra.Command{ Use: "block-gas [height]", Short: "Get the block gas used at a given block height", - Long: "Get the block gas used at a given block height. If the height is not provided, it will use the latest height from context.", - Args: cobra.RangeArgs(0, 1), + Long: `Get the block gas used at a given block height. +If the height is not provided, it will use the latest height from context`, + Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -47,13 +49,10 @@ func GetBlockGasCmd() *cobra.Command { ctx := cmd.Context() if len(args) == 1 { - height := args[0] - _, err := strconv.ParseInt(height, 10, 64) + ctx, err = getContextHeight(ctx, args[0]) if err != nil { - return fmt.Errorf("invalid height: %w", err) + return err } - - ctx = metadata.AppendToOutgoingContext(ctx, grpctypes.GRPCBlockHeightHeader, height) } queryClient := types.NewQueryClient(clientCtx) @@ -104,8 +103,9 @@ func GetBaseFeeCmd() *cobra.Command { cmd := &cobra.Command{ Use: "base-fee [height]", Short: "Get the base fee amount at a given block height", - Long: "Get the base fee amount at a given block height. If the height is not provided, it will use the latest height from context.", - Args: cobra.RangeArgs(0, 1), + Long: `Get the base fee amount at a given block height. +If the height is not provided, it will use the latest height from context.`, + Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -114,13 +114,10 @@ func GetBaseFeeCmd() *cobra.Command { ctx := cmd.Context() if len(args) == 1 { - height := args[0] - _, err := strconv.ParseInt(height, 10, 64) + ctx, err = getContextHeight(ctx, args[0]) if err != nil { - return fmt.Errorf("invalid height: %w", err) + return err } - - ctx = metadata.AppendToOutgoingContext(ctx, grpctypes.GRPCBlockHeightHeader, height) } queryClient := types.NewQueryClient(clientCtx) @@ -137,3 +134,12 @@ func GetBaseFeeCmd() *cobra.Command { flags.AddQueryFlagsToCmd(cmd) return cmd } + +func getContextHeight(ctx context.Context, height string) (context.Context, error) { + _, err := strconv.ParseInt(height, 10, 64) + if err != nil { + return ctx, fmt.Errorf("invalid height: %w", err) + } + + return metadata.AppendToOutgoingContext(ctx, grpctypes.GRPCBlockHeightHeader, height), nil +}