diff --git a/client/input/input.go b/client/input/input.go index 95f32281e..73dd822fd 100644 --- a/client/input/input.go +++ b/client/input/input.go @@ -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) diff --git a/crypto/keys/keyring.go b/crypto/keys/keyring.go index 450b0d32b..0a76c9606 100644 --- a/crypto/keys/keyring.go +++ b/crypto/keys/keyring.go @@ -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" @@ -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) diff --git a/crypto/keys/keyring_test.go b/crypto/keys/keyring_test.go index dd179a0c1..f52140965 100644 --- a/crypto/keys/keyring_test.go +++ b/crypto/keys/keyring_test.go @@ -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()) } diff --git a/crypto/keys/mintkey/mintkey_test.go b/crypto/keys/mintkey/mintkey_test.go index dd978c13e..ffeea07c4 100644 --- a/crypto/keys/mintkey/mintkey_test.go +++ b/crypto/keys/mintkey/mintkey_test.go @@ -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") @@ -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 diff --git a/crypto/keys/types_test.go b/crypto/keys/types_test.go index 1376c3bbb..3c18f4cf1 100644 --- a/crypto/keys/types_test.go +++ b/crypto/keys/types_test.go @@ -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" ) @@ -17,7 +16,7 @@ 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() @@ -25,7 +24,7 @@ func Test_writeReadLedgerInfo(t *testing.T) { 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) diff --git a/store/reexport.go b/store/reexport.go index 913a8c55a..9e4dba0ed 100644 --- a/store/reexport.go +++ b/store/reexport.go @@ -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. @@ -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 diff --git a/types/module/module_test.go b/types/module/module_test.go index 65df4e8ea..fa5b17ab3 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -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) }) } @@ -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) }) } diff --git a/types/rest/rest_test.go b/types/rest/rest_test.go index e760627b4..db842696e 100644 --- a/types/rest/rest_test.go +++ b/types/rest/rest_test.go @@ -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 @@ -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) } @@ -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) @@ -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") } diff --git a/types/staking_test.go b/types/staking_test.go index ddeab0d07..34c165a67 100644 --- a/types/staking_test.go +++ b/types/staking_test.go @@ -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) { diff --git a/version/version_test.go b/version/version_test.go index d125b9946..25616b5f3 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -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()) } diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index f4a60a87e..57eceaea6 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -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" @@ -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, )