diff --git a/.circleci/config.yml b/.circleci/config.yml index aab383460..b4cdb5119 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -50,22 +50,6 @@ jobs: - bin - profiles - lint: - <<: *linux_defaults - parallelism: 1 - steps: - - attach_workspace: - at: /tmp/workspace - - checkout - - restore_cache: - keys: - - go-mod-v1-{{ checksum "go.sum" }} - - run: - name: Lint source - command: | - export PATH=/tmp/workspace/bin:$PATH - make ci-lint - test_sim_app_nondeterminism: <<: *linux_defaults parallelism: 1 @@ -284,9 +268,6 @@ workflows: tags: only: - /^v.*/ - - lint: - requires: - - setup_dependencies - test_sim_app_nondeterminism: requires: - setup_dependencies diff --git a/.golangci.yml b/.golangci.yml index b29f15e40..78b0de8b1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,8 @@ linters: - unused - deadcode - goconst + - gosec + - staticcheck linters-settings: gocyclo: min-complexity: 11 diff --git a/client/input/input.go b/client/input/input.go index f10decad8..0ccf8c1b1 100644 --- a/client/input/input.go +++ b/client/input/input.go @@ -65,23 +65,21 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error) // "y", "Y", "yes", "YES", and "Yes" all count as confirmations. // If the input is not recognized, it returns false and a nil error. func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) { - for { - if inputIsTty() { - fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt)) - } - - response, err := readLineFromBuf(buf) - if err != nil { - return false, err - } - - response = strings.ToLower(strings.TrimSpace(response)) - if response[0] == 'y' { - return true, nil - } - - return false, nil + if inputIsTty() { + fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt)) } + + response, err := readLineFromBuf(buf) + if err != nil { + return false, err + } + + response = strings.ToLower(strings.TrimSpace(response)) + if response[0] == 'y' { + return true, nil + } + + return false, nil } // GetString simply returns the trimmed string output of a given reader. diff --git a/client/rpc/block.go b/client/rpc/block.go index 53177ec3b..b8581a32b 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -117,13 +117,16 @@ func BlockRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { height, err := strconv.ParseInt(vars["height"], 10, 64) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, - "ERROR: Couldn't parse block height. Assumed format is '/block/{height}'.") + "couldn't parse block height. Assumed format is '/block/{height}'.") return } chainHeight, err := GetChainHeight(cliCtx) + if err != nil { + rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height") + return + } if height > chainHeight { - rest.WriteErrorResponse(w, http.StatusNotFound, - "ERROR: Requested block height is bigger then the chain length.") + rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length") return } output, err := getBlock(cliCtx, &height) diff --git a/client/rpc/validators.go b/client/rpc/validators.go index e98db0a0d..5aaa6985c 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -161,13 +161,17 @@ func ValidatorSetRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { height, err := strconv.ParseInt(vars["height"], 10, 64) if err != nil { - rest.WriteErrorResponse(w, http.StatusBadRequest, "ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'.") + rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse block height; assumed format is '/validatorsets/{height}'") return } chainHeight, err := GetChainHeight(cliCtx) + if err != nil { + rest.WriteErrorResponse(w, http.StatusInternalServerError, "failed to parse chain height") + return + } if height > chainHeight { - rest.WriteErrorResponse(w, http.StatusNotFound, "ERROR: Requested block height is bigger then the chain length.") + rest.WriteErrorResponse(w, http.StatusNotFound, "requested block height is bigger then the chain length") return } diff --git a/server/test_helpers.go b/server/test_helpers.go index 1f87a518b..dc52f0c1f 100644 --- a/server/test_helpers.go +++ b/server/test_helpers.go @@ -16,7 +16,7 @@ import ( // Get a free address for a test tendermint server // protocol is either tcp, http, etc func FreeTCPAddr() (addr, port string, err error) { - l, err := net.Listen("tcp", "0.0.0.0:0") + l, err := net.Listen("tcp", "localhost:0") if err != nil { return "", "", err } diff --git a/server/util.go b/server/util.go index 0ac0ff657..20eecfe15 100644 --- a/server/util.go +++ b/server/util.go @@ -99,6 +99,9 @@ func interceptLoadConfig() (conf *cfg.Config, err error) { if conf == nil { conf, err = tcmd.ParseConfig() // NOTE: ParseConfig() creates dir/files as necessary. + if err != nil { + panic(err) + } } appConfigFilePath := filepath.Join(rootDir, "config/app.toml") diff --git a/simapp/export.go b/simapp/export.go index 8e6af96f6..e1fe03e20 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -133,7 +133,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str iter := sdk.KVStoreReversePrefixIterator(store, staking.ValidatorsKey) counter := int16(0) - var valConsAddrs []sdk.ConsAddress for ; iter.Valid(); iter.Next() { addr := sdk.ValAddress(iter.Key()[1:]) validator, found := app.stakingKeeper.GetValidator(ctx, addr) @@ -142,7 +141,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []str } validator.UnbondingHeight = 0 - valConsAddrs = append(valConsAddrs, validator.ConsAddress()) if applyWhiteList && !whiteListMap[addr.String()] { validator.Jailed = true } diff --git a/tests/util.go b/tests/util.go index 070073c2b..4ca219285 100644 --- a/tests/util.go +++ b/tests/util.go @@ -97,7 +97,8 @@ func waitForHeight(height int64, url string) { var res *http.Response var err error for { - res, err = http.Get(url) + // Since this is in a testing file we are accepting nolint to be passed + res, err = http.Get(url) //nolint:gosec if err != nil { panic(err) } @@ -150,7 +151,7 @@ func WaitForStart(url string) { time.Sleep(time.Millisecond * 100) var res *http.Response - res, err = http.Get(url) + res, err = http.Get(url) //nolint:gosec Error is arising in testing files, accepting nolint if err != nil || res == nil { continue } @@ -214,3 +215,5 @@ var cdc = codec.New() func init() { ctypes.RegisterAmino(cdc) } + +//DONTCOVER diff --git a/x/genutil/client/cli/gentx.go b/x/genutil/client/cli/gentx.go index 545b0cecc..2ca9bd629 100644 --- a/x/genutil/client/cli/gentx.go +++ b/x/genutil/client/cli/gentx.go @@ -214,10 +214,10 @@ func readUnsignedGenTxFile(cdc *codec.Codec, r io.Reader) (auth.StdTx, error) { func writeSignedGenTx(cdc *codec.Codec, outputDocument string, tx auth.StdTx) error { outputFile, err := os.OpenFile(outputDocument, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644) - defer outputFile.Close() if err != nil { return err } + defer outputFile.Close() json, err := cdc.MarshalJSON(tx) if err != nil { return err diff --git a/x/gov/simulation/msgs.go b/x/gov/simulation/msgs.go index 7053ec655..8b65fa3d6 100644 --- a/x/gov/simulation/msgs.go +++ b/x/gov/simulation/msgs.go @@ -163,7 +163,7 @@ func operationSimulateMsgVote(k gov.Keeper, acc simulation.Account, proposalID u acc = simulation.RandomAcc(r, accs) } - if proposalID < 0 { + if proposalID < uint64(0) { var ok bool proposalID, ok = randomProposalID(r, k, ctx) if !ok { diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index 726133b57..fb5d9e233 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -42,6 +42,11 @@ func queryBonds(cliCtx context.CLIContext, endpoint string) http.HandlerFunc { bech32validator := vars["validatorAddr"] delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + validatorAddr, err := sdk.ValAddressFromBech32(bech32validator) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())