Skip to content

Commit

Permalink
Fix various linter warnings (cosmos#5824)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia authored Mar 18, 2020
1 parent a84e02f commit 3db39cd
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion client/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetCheckPassword(prompt, prompt2 string, buf *bufio.Reader) (string, error)
// If the input is not recognized, it returns false and a nil error.
func GetConfirmation(prompt string, buf *bufio.Reader) (bool, error) {
if inputIsTty() {
fmt.Print(fmt.Sprintf("%s [y/N]: ", prompt))
fmt.Printf("%s [y/N]: ", prompt)
}

response, err := readLineFromBuf(buf)
Expand Down
3 changes: 1 addition & 2 deletions crypto/keys/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/pkg/errors"

"github.com/tendermint/crypto/bcrypt"
"github.com/tendermint/tendermint/crypto"
tmcrypto "github.com/tendermint/tendermint/crypto"
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"

Expand Down Expand Up @@ -569,7 +568,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
continue
}

saltBytes := crypto.CRandBytes(16)
saltBytes := tmcrypto.CRandBytes(16)
passwordHash, err := bcrypt.GenerateFromPassword(saltBytes, []byte(pass), 2)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
4 changes: 2 additions & 2 deletions crypto/keys/keyring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,6 @@ func TestSupportedAlgos(t *testing.T) {
t.Cleanup(cleanup)
kb, err := NewKeyring("keybasename", "test", dir, nil)
require.NoError(t, err)
require.Equal(t, []SigningAlgo([]SigningAlgo{"secp256k1"}), kb.SupportedAlgos())
require.Equal(t, []SigningAlgo([]SigningAlgo{"secp256k1"}), kb.SupportedAlgosLedger())
require.Equal(t, []SigningAlgo{"secp256k1"}, kb.SupportedAlgos())
require.Equal(t, []SigningAlgo{"secp256k1"}, kb.SupportedAlgosLedger())
}
3 changes: 2 additions & 1 deletion crypto/keys/mintkey/mintkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestArmorUnarmorPrivKey(t *testing.T) {

// wrong key type
armored = mintkey.ArmorPubKeyBytes(priv.PubKey().Bytes(), "")
decrypted, algo, err = mintkey.UnarmorDecryptPrivKey(armored, "passphrase")
_, _, err = mintkey.UnarmorDecryptPrivKey(armored, "passphrase")
require.Error(t, err)
require.Contains(t, err.Error(), "unrecognized armor type")

Expand Down Expand Up @@ -91,6 +91,7 @@ func TestArmorUnarmorPubKey(t *testing.T) {
armored, err = cstore.ExportPrivKey("Bob", "passphrase", "alessio")
require.NoError(t, err)
_, _, err = mintkey.UnarmorPubKeyBytes(armored)
require.Error(t, err)
require.Equal(t, `couldn't unarmor bytes: unrecognized armor type "TENDERMINT PRIVATE KEY", expected: "TENDERMINT PUBLIC KEY"`, err.Error())

// armor pubkey manually
Expand Down
5 changes: 2 additions & 3 deletions crypto/keys/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/tendermint/tendermint/crypto/secp256k1"

"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -17,15 +16,15 @@ func Test_writeReadLedgerInfo(t *testing.T) {
bz, _ := hex.DecodeString("035AD6810A47F073553FF30D2FCC7E0D3B1C0B74B61A1AAA2582344037151E143A")
copy(tmpKey[:], bz)

lInfo := newLedgerInfo("some_name", tmpKey, *hd.NewFundraiserParams(5, types.CoinType, 1), Secp256k1)
lInfo := newLedgerInfo("some_name", tmpKey, *hd.NewFundraiserParams(5, sdk.CoinType, 1), Secp256k1)
assert.Equal(t, TypeLedger, lInfo.GetType())

path, err := lInfo.GetPath()
assert.NoError(t, err)
assert.Equal(t, "44'/118'/5'/0/1", path.String())
assert.Equal(t,
"cosmospub1addwnpepqddddqg2glc8x4fl7vxjlnr7p5a3czm5kcdp4239sg6yqdc4rc2r5wmxv8p",
types.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, lInfo.GetPubKey()))
sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, lInfo.GetPubKey()))

// Serialize and restore
serialized := marshalInfo(lInfo)
Expand Down
5 changes: 2 additions & 3 deletions store/reexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package store

import (
"github.com/cosmos/cosmos-sdk/store/types"
stypes "github.com/cosmos/cosmos-sdk/store/types"
)

// Import cosmos-sdk/types/store.go for convenience.
Expand All @@ -27,9 +26,9 @@ type (
StoreType = types.StoreType
Queryable = types.Queryable
TraceContext = types.TraceContext
Gas = stypes.Gas
Gas = types.Gas
GasMeter = types.GasMeter
GasConfig = stypes.GasConfig
GasConfig = types.GasConfig
)

// nolint - reexport
Expand Down
12 changes: 6 additions & 6 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ func TestManager_InitGenesis(t *testing.T) {
genesisData = map[string]json.RawMessage{
"module1": json.RawMessage(`{"key": "value"}`),
"module2": json.RawMessage(`{"key": "value"}`)}
mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{abci.ValidatorUpdate{}})
mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module2"])).Times(1).Return([]abci.ValidatorUpdate{abci.ValidatorUpdate{}})
mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}})
mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module2"])).Times(1).Return([]abci.ValidatorUpdate{{}})
require.Panics(t, func() { mm.InitGenesis(ctx, cdc, genesisData) })
}

Expand Down Expand Up @@ -239,13 +239,13 @@ func TestManager_EndBlock(t *testing.T) {

req := abci.RequestEndBlock{Height: 10}

mockAppModule1.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{abci.ValidatorUpdate{}})
mockAppModule1.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}})
mockAppModule2.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1)
ret := mm.EndBlock(sdk.Context{}, req)
require.Equal(t, []abci.ValidatorUpdate{abci.ValidatorUpdate{}}, ret.ValidatorUpdates)
require.Equal(t, []abci.ValidatorUpdate{{}}, ret.ValidatorUpdates)

// test panic
mockAppModule1.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{abci.ValidatorUpdate{}})
mockAppModule2.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{abci.ValidatorUpdate{}})
mockAppModule1.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}})
mockAppModule2.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}})
require.Panics(t, func() { mm.EndBlock(sdk.Context{}, req) })
}
9 changes: 6 additions & 3 deletions types/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ func TestReadRESTReq(t *testing.T) {

// test OK
ReadRESTReq(w, req, codec.New(), &br)
require.Equal(t, BaseReq{ChainID: "alessio", Memo: "text"}, br)
res := w.Result()
t.Cleanup(func() { res.Body.Close() })
require.Equal(t, BaseReq{ChainID: "alessio", Memo: "text"}, br)
require.Equal(t, http.StatusOK, res.StatusCode)

// test non valid JSON
Expand All @@ -247,6 +248,7 @@ func TestReadRESTReq(t *testing.T) {
ReadRESTReq(w, req, codec.New(), &br)
require.Equal(t, br, br)
res = w.Result()
t.Cleanup(func() { res.Body.Close() })
require.Equal(t, http.StatusBadRequest, res.StatusCode)
}

Expand All @@ -255,6 +257,7 @@ func TestWriteSimulationResponse(t *testing.T) {
w := httptest.NewRecorder()
WriteSimulationResponse(w, codec.New(), 10)
res := w.Result()
t.Cleanup(func() { res.Body.Close() })
require.Equal(t, http.StatusOK, res.StatusCode)
bs, err := ioutil.ReadAll(res.Body)
require.NoError(t, err)
Expand Down Expand Up @@ -361,13 +364,13 @@ func TestPostProcessResponseBare(t *testing.T) {
got, err = ioutil.ReadAll(res.Body)
require.NoError(t, err)
t.Cleanup(func() { res.Body.Close() })
require.Equal(t, []string([]string{"application/json"}), res.Header["Content-Type"])
require.Equal(t, []string{"application/json"}, res.Header["Content-Type"])
require.Equal(t, `{"error":"couldn't marshal"}`, string(got))
}

type badJSONMarshaller struct{}

func (_ badJSONMarshaller) MarshalJSON() ([]byte, error) {
func (badJSONMarshaller) MarshalJSON() ([]byte, error) {
return nil, errors.New("couldn't marshal")
}

Expand Down
8 changes: 4 additions & 4 deletions types/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ func TestBondStatus(t *testing.T) {
require.False(t, sdk.Unbonded.Equal(sdk.Bonded))
require.False(t, sdk.Unbonded.Equal(sdk.Unbonding))
require.False(t, sdk.Bonded.Equal(sdk.Unbonding))
require.Panicsf(t, func() { sdk.BondStatus(0).String() }, "invalid bond status")
require.Equal(t, sdk.BondStatusUnbonded, sdk.BondStatus(sdk.Unbonded).String())
require.Equal(t, sdk.BondStatusBonded, sdk.BondStatus(sdk.Bonded).String())
require.Equal(t, sdk.BondStatusUnbonding, sdk.BondStatus(sdk.Unbonding).String())
require.Panicsf(t, func() { _ = sdk.BondStatus(0).String() }, "invalid bond status")
require.Equal(t, sdk.BondStatusUnbonded, sdk.Unbonded.String())
require.Equal(t, sdk.BondStatusBonded, sdk.Bonded.String())
require.Equal(t, sdk.BondStatusUnbonding, sdk.Unbonding.String())
}

func TestTokensToConsensusPower(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func TestInfo_String(t *testing.T) {
BuildTags: "netgo,ledger",
GoVersion: "go version go1.14 linux/amd64",
}
want := fmt.Sprintf(`testapp: 1.0.0
want := `testapp: 1.0.0
git commit: 1b78457135a4104bc3af97f20654d49e2ea87454
build tags: netgo,ledger
go version go1.14 linux/amd64`)
go version go1.14 linux/amd64`
require.Equal(t, want, info.String())
}

Expand Down
3 changes: 1 addition & 2 deletions x/auth/ante/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ante
import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
err "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/tendermint/tendermint/crypto"
Expand Down Expand Up @@ -68,7 +67,7 @@ func (vmd ValidateMemoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

memoLength := len(memoTx.GetMemo())
if uint64(memoLength) > params.MaxMemoCharacters {
return ctx, err.Wrapf(err.ErrMemoTooLarge,
return ctx, sdkerrors.Wrapf(sdkerrors.ErrMemoTooLarge,
"maximum number of characters is %d but received %d characters",
params.MaxMemoCharacters, memoLength,
)
Expand Down

0 comments on commit 3db39cd

Please sign in to comment.