This commit is contained in:
Federico Kunze Küllmer 2021-08-26 11:45:45 -04:00 committed by GitHub
parent b5288399d3
commit 7389770b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 71 additions and 73 deletions

View File

@ -1,15 +1,15 @@
run: run:
tests: false tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m # timeout: 5m
linters: linters:
disable-all: true
enable: enable:
- bodyclose - bodyclose
- deadcode - deadcode
- depguard - depguard
- dogsled - dogsled
- dupl
- errcheck - errcheck
- goconst - goconst
- gocritic - gocritic
@ -20,9 +20,9 @@ linters:
- gosimple - gosimple
- govet - govet
- ineffassign - ineffassign
- interfacer # - lll TODO: enable
- maligned
- misspell - misspell
- maligned
- nakedret - nakedret
- prealloc - prealloc
- scopelint - scopelint
@ -31,39 +31,33 @@ linters:
- stylecheck - stylecheck
- typecheck - typecheck
- unconvert - unconvert
- unused
- unparam - unparam
- misspell - unused
# TODO: address these lint issues - varcheck
- nolintlint
- asciicheck
# - whitespace
# - wsl # - wsl
# - nolintlint
issues: issues:
exclude-rules: exclude-rules:
- text: "Use of weak random number generator" - path: _test\.go
linters: linters:
- gosec - gosec
- text: "comment on exported var" - linters:
linters: - lll
- golint source: "https://"
- text: "don't use an underscore in package name" max-same-issues: 50
linters:
- golint
- text: "ST1003:"
linters:
- stylecheck
- text: "SA1019:"
linters:
- staticcheck
max-issues-per-linter: 10000
max-same-issues: 10000
linters-settings: linters-settings:
dogsled: dogsled:
max-blank-identifiers: 3 max-blank-identifiers: 3
golint:
min-confidence: 0
maligned: maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true suggest-new: true
misspell:
locale: US
nolintlint: nolintlint:
allow-unused: false allow-unused: false
allow-leading-space: true allow-leading-space: true

View File

@ -320,11 +320,11 @@ func initGenFiles(
numValidators int, numValidators int,
) error { ) error {
appGenState := mbm.DefaultGenesis(clientCtx.JSONCodec) appGenState := mbm.DefaultGenesis(clientCtx.Codec)
// set the accounts in the genesis state // set the accounts in the genesis state
var authGenState authtypes.GenesisState var authGenState authtypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState)
accounts, err := authtypes.PackAccounts(genAccounts) accounts, err := authtypes.PackAccounts(genAccounts)
if err != nil { if err != nil {
@ -332,44 +332,44 @@ func initGenFiles(
} }
authGenState.Accounts = accounts authGenState.Accounts = accounts
appGenState[authtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&authGenState) appGenState[authtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&authGenState)
// set the balances in the genesis state // set the balances in the genesis state
var bankGenState banktypes.GenesisState var bankGenState banktypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)
bankGenState.Balances = genBalances bankGenState.Balances = genBalances
appGenState[banktypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&bankGenState) appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState)
var stakingGenState stakingtypes.GenesisState var stakingGenState stakingtypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[stakingtypes.ModuleName], &stakingGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[stakingtypes.ModuleName], &stakingGenState)
stakingGenState.Params.BondDenom = coinDenom stakingGenState.Params.BondDenom = coinDenom
appGenState[stakingtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&stakingGenState) appGenState[stakingtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&stakingGenState)
var govGenState govtypes.GenesisState var govGenState govtypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState)
govGenState.DepositParams.MinDeposit[0].Denom = coinDenom govGenState.DepositParams.MinDeposit[0].Denom = coinDenom
appGenState[govtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&govGenState) appGenState[govtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&govGenState)
var mintGenState mintypes.GenesisState var mintGenState mintypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[mintypes.ModuleName], &mintGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[mintypes.ModuleName], &mintGenState)
mintGenState.Params.MintDenom = coinDenom mintGenState.Params.MintDenom = coinDenom
appGenState[mintypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&mintGenState) appGenState[mintypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&mintGenState)
var crisisGenState crisistypes.GenesisState var crisisGenState crisistypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState)
crisisGenState.ConstantFee.Denom = coinDenom crisisGenState.ConstantFee.Denom = coinDenom
appGenState[crisistypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&crisisGenState) appGenState[crisistypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&crisisGenState)
var evmGenState evmtypes.GenesisState var evmGenState evmtypes.GenesisState
clientCtx.JSONCodec.MustUnmarshalJSON(appGenState[evmtypes.ModuleName], &evmGenState) clientCtx.Codec.MustUnmarshalJSON(appGenState[evmtypes.ModuleName], &evmGenState)
evmGenState.Params.EvmDenom = coinDenom evmGenState.Params.EvmDenom = coinDenom
appGenState[evmtypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(&evmGenState) appGenState[evmtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&evmGenState)
appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")
if err != nil { if err != nil {
@ -416,7 +416,7 @@ func collectGenFiles(
return err 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 { if err != nil {
return err return err
} }

View File

@ -39,12 +39,12 @@ func TestSetBech32Prefixes(t *testing.T) {
func TestSetCoinType(t *testing.T) { func TestSetCoinType(t *testing.T) {
config := sdk.GetConfig() config := sdk.GetConfig()
require.Equal(t, sdk.CoinType, int(config.GetCoinType())) require.Equal(t, sdk.CoinType, int(config.GetCoinType()))
require.Equal(t, sdk.FullFundraiserPath, config.GetFullFundraiserPath()) require.Equal(t, sdk.FullFundraiserPath, config.GetFullBIP44Path())
SetBip44CoinType(config) SetBip44CoinType(config)
require.Equal(t, int(ethermint.Bip44CoinType), int(config.GetCoinType())) require.Equal(t, int(ethermint.Bip44CoinType), int(config.GetCoinType()))
require.Equal(t, sdk.GetConfig().GetCoinType(), 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) { func TestHDPath(t *testing.T) {

View File

@ -76,12 +76,12 @@ func (privKey PrivKey) Type() string {
return KeyType return KeyType
} }
// MarshalAmino overrides Amino binary marshalling. // MarshalAmino overrides Amino binary marshaling.
func (privKey PrivKey) MarshalAmino() ([]byte, error) { func (privKey PrivKey) MarshalAmino() ([]byte, error) {
return privKey.Key, nil return privKey.Key, nil
} }
// UnmarshalAmino overrides Amino binary marshalling. // UnmarshalAmino overrides Amino binary marshaling.
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error { func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
if len(bz) != PrivKeySize { if len(bz) != PrivKeySize {
return fmt.Errorf("invalid privkey size, expected %d got %d", PrivKeySize, len(bz)) 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 return nil
} }
// MarshalAminoJSON overrides Amino JSON marshalling. // MarshalAminoJSON overrides Amino JSON marshaling.
func (privKey PrivKey) MarshalAminoJSON() ([]byte, error) { func (privKey PrivKey) MarshalAminoJSON() ([]byte, error) {
// When we marshal to Amino JSON, we don't marshal the "key" field itself, // When we marshal to Amino JSON, we don't marshal the "key" field itself,
// just its contents (i.e. the key bytes). // just its contents (i.e. the key bytes).
return privKey.MarshalAmino() return privKey.MarshalAmino()
} }
// UnmarshalAminoJSON overrides Amino JSON marshalling. // UnmarshalAminoJSON overrides Amino JSON marshaling.
func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error { func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error {
return privKey.UnmarshalAmino(bz) 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()) 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) { func (pubKey PubKey) MarshalAmino() ([]byte, error) {
return pubKey.Key, nil return pubKey.Key, nil
} }
// UnmarshalAmino overrides Amino binary marshalling. // UnmarshalAmino overrides Amino binary marshaling.
func (pubKey *PubKey) UnmarshalAmino(bz []byte) error { func (pubKey *PubKey) UnmarshalAmino(bz []byte) error {
if len(bz) != PubKeySize { if len(bz) != PubKeySize {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidPubKey, "invalid pubkey size, expected %d, got %d", PubKeySize, len(bz)) 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 return nil
} }
// MarshalAminoJSON overrides Amino JSON marshalling. // MarshalAminoJSON overrides Amino JSON marshaling.
func (pubKey PubKey) MarshalAminoJSON() ([]byte, error) { func (pubKey PubKey) MarshalAminoJSON() ([]byte, error) {
// When we marshal to Amino JSON, we don't marshal the "key" field itself, // When we marshal to Amino JSON, we don't marshal the "key" field itself,
// just its contents (i.e. the key bytes). // just its contents (i.e. the key bytes).
return pubKey.MarshalAmino() return pubKey.MarshalAmino()
} }
// UnmarshalAminoJSON overrides Amino JSON marshalling. // UnmarshalAminoJSON overrides Amino JSON marshaling.
func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error { func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error {
return pubKey.UnmarshalAmino(bz) return pubKey.UnmarshalAmino(bz)
} }

View File

@ -56,7 +56,7 @@ func (a *InternalAPI) BlockProfile(file string, nsec uint) error {
// CpuProfile turns on CPU profiling for nsec seconds and writes // CpuProfile turns on CPU profiling for nsec seconds and writes
// profile data to file. // 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) a.logger.Debug("debug_cpuProfile", "file", file, "nsec", nsec)
if err := a.StartCPUProfile(file); err != nil { if err := a.StartCPUProfile(file); err != nil {
return err return err

View File

@ -893,7 +893,7 @@ func (e *PublicAPI) GetProof(address common.Address, storageKeys []string, block
func (e *PublicAPI) getBlockNumber(blockNrOrHash rpctypes.BlockNumberOrHash) (rpctypes.BlockNumber, error) { func (e *PublicAPI) getBlockNumber(blockNrOrHash rpctypes.BlockNumberOrHash) (rpctypes.BlockNumber, error) {
switch { switch {
case blockNrOrHash.BlockHash == nil && blockNrOrHash.BlockNumber == nil: 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: case blockNrOrHash.BlockHash != nil:
blockHeader, err := e.backend.HeaderByHash(*blockNrOrHash.BlockHash) blockHeader, err := e.backend.HeaderByHash(*blockNrOrHash.BlockHash)
if err != nil { if err != nil {

View File

@ -191,7 +191,7 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su
txHash := common.BytesToHash(tmtypes.Tx(data.Tx).Hash()) 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 // TODO(rjl493456442) Send a batch of tx hashes in one notification
err = notifier.Notify(rpcSub.ID, txHash) err = notifier.Notify(rpcSub.ID, txHash)
if err != nil { if err != nil {

View File

@ -39,7 +39,7 @@ type PrivateAccountAPI struct {
// NewAPI creates an instance of the public Personal Eth API. // NewAPI creates an instance of the public Personal Eth API.
func NewAPI(logger log.Logger, clientCtx client.Context, backend backend.Backend) *PrivateAccountAPI { func NewAPI(logger log.Logger, clientCtx client.Context, backend backend.Backend) *PrivateAccountAPI {
cfg := sdk.GetConfig() cfg := sdk.GetConfig()
basePath := cfg.GetFullFundraiserPath() basePath := cfg.GetFullBIP44Path()
iterator, err := ethermint.NewHDPathIterator(basePath, true) iterator, err := ethermint.NewHDPathIterator(basePath, true)
if err != nil { if err != nil {

View File

@ -74,7 +74,7 @@ func Call(t *testing.T, method string, params interface{}) *Response {
if HOST == "" { if HOST == "" {
HOST = "http://localhost:8545" 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) require.NoError(t, err)
decoder := json.NewDecoder(res.Body) decoder := json.NewDecoder(res.Body)
@ -102,7 +102,7 @@ func CallWithError(method string, params interface{}) (*Response, error) {
if HOST == "" { if HOST == "" {
HOST = "http://localhost:8545" 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 { if err != nil {
return nil, err return nil, err
} }
@ -222,7 +222,6 @@ func DeployTestContractWithFunction(t *testing.T, addr []byte) hexutil.Bytes {
return hash return hash
} }
//nolint
func GetTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} { func GetTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
param := []string{hash.String()} param := []string{hash.String()}
rpcRes := Call(t, "eth_getTransactionReceipt", param) rpcRes := Call(t, "eth_getTransactionReceipt", param)

View File

@ -66,7 +66,6 @@ func InitGenesis(
func ExportGenesis(ctx sdk.Context, k *keeper.Keeper, ak types.AccountKeeper) *types.GenesisState { func ExportGenesis(ctx sdk.Context, k *keeper.Keeper, ak types.AccountKeeper) *types.GenesisState {
k.WithContext(ctx) k.WithContext(ctx)
// nolint: prealloc
var ethGenAccounts []types.GenesisAccount var ethGenAccounts []types.GenesisAccount
ak.IterateAccounts(ctx, func(account authtypes.AccountI) bool { ak.IterateAccounts(ctx, func(account authtypes.AccountI) bool {
ethAccount, ok := account.(*ethermint.EthAccount) ethAccount, ok := account.(*ethermint.EthAccount)

View File

@ -1,6 +1,7 @@
package cli package cli
import ( import (
"context"
"fmt" "fmt"
"strconv" "strconv"
@ -37,8 +38,9 @@ func GetBlockGasCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "block-gas [height]", Use: "block-gas [height]",
Short: "Get the block gas used at a given block 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.", Long: `Get the block gas used at a given block height.
Args: cobra.RangeArgs(0, 1), 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 { RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd) clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil { if err != nil {
@ -47,13 +49,10 @@ func GetBlockGasCmd() *cobra.Command {
ctx := cmd.Context() ctx := cmd.Context()
if len(args) == 1 { if len(args) == 1 {
height := args[0] ctx, err = getContextHeight(ctx, args[0])
_, err := strconv.ParseInt(height, 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("invalid height: %w", err) return err
} }
ctx = metadata.AppendToOutgoingContext(ctx, grpctypes.GRPCBlockHeightHeader, height)
} }
queryClient := types.NewQueryClient(clientCtx) queryClient := types.NewQueryClient(clientCtx)
@ -104,8 +103,9 @@ func GetBaseFeeCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "base-fee [height]", Use: "base-fee [height]",
Short: "Get the base fee amount at a given block 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.", Long: `Get the base fee amount at a given block height.
Args: cobra.RangeArgs(0, 1), 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 { RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd) clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil { if err != nil {
@ -114,13 +114,10 @@ func GetBaseFeeCmd() *cobra.Command {
ctx := cmd.Context() ctx := cmd.Context()
if len(args) == 1 { if len(args) == 1 {
height := args[0] ctx, err = getContextHeight(ctx, args[0])
_, err := strconv.ParseInt(height, 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("invalid height: %w", err) return err
} }
ctx = metadata.AppendToOutgoingContext(ctx, grpctypes.GRPCBlockHeightHeader, height)
} }
queryClient := types.NewQueryClient(clientCtx) queryClient := types.NewQueryClient(clientCtx)
@ -137,3 +134,12 @@ func GetBaseFeeCmd() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd) flags.AddQueryFlagsToCmd(cmd)
return 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
}