Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
ci: lint (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored Aug 26, 2021
1 parent b528839 commit 7389770
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 73 deletions.
44 changes: 19 additions & 25 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,9 +20,9 @@ linters:
- gosimple
- govet
- ineffassign
- interfacer
- maligned
# - lll TODO: enable
- misspell
- maligned
- nakedret
- prealloc
- scopelint
Expand All @@ -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
Expand Down
32 changes: 16 additions & 16 deletions client/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,56 +320,56 @@ 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 {
return err
}

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 {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions crypto/ethsecp256k1/ethsecp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
}
Expand Down Expand Up @@ -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))
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ethereum/rpc/namespaces/debug/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ethereum/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ethereum/rpc/namespaces/eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ethereum/rpc/namespaces/personal/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions tests/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 20 additions & 14 deletions x/feemarket/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"context"
"fmt"
"strconv"

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}

0 comments on commit 7389770

Please sign in to comment.