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:
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

View File

@ -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
}

View File

@ -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) {

View File

@ -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)
}

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
// 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

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) {
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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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)

View File

@ -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)

View File

@ -1,6 +1,7 @@
package cli
import (
"context"
"fmt"
"strconv"
@ -37,7 +38,8 @@ 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.",
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)
@ -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,7 +103,8 @@ 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.",
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)
@ -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
}