diff --git a/.golangci.yml b/.golangci.yml index 2d8691018d..44b2b0a3e0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,6 +45,9 @@ issues: text: "SA1019:" linters: - staticcheck + - text: "SA1019: codec.NewAminoCodec is deprecated" # TODO remove once migration path is set out + linters: + - staticcheck - text: "leading space" linters: - nolintlint diff --git a/CHANGELOG.md b/CHANGELOG.md index e60a1c8da0..da053caf17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -801,7 +801,6 @@ replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8 * [#11334](https://github.com/cosmos/cosmos-sdk/pull/11334) Move `x/gov/types/v1beta2` to `x/gov/types/v1`. * (x/auth/middleware) [#11413](https://github.com/cosmos/cosmos-sdk/pull/11413) Refactor tx middleware to be extensible on tx fee logic. Merged `MempoolFeeMiddleware` and `TxPriorityMiddleware` functionalities into `DeductFeeMiddleware`, make the logic extensible using the `TxFeeChecker` option, the current fee logic is preserved by the default `checkTxFeeWithValidatorMinGasPrices` implementation. Change `RejectExtensionOptionsMiddleware` to `NewExtensionOptionsMiddleware` which is extensible with the `ExtensionOptionChecker` option. Unpack the tx extension options `Any`s to interface `TxExtensionOptionI`. * (migrations) [#11556](https://github.com/cosmos/cosmos-sdk/pull/11556#issuecomment-1091385011) Remove migration code from 0.42 and below. To use previous migrations, checkout previous versions of the cosmos-sdk. -* (x/authz,consensus,crisis,slashing) [#15675](https://github.com/cosmos/cosmos-sdk/pull/15675) Remove ModuleCdc as `NewAminoCodec` is depreacted. ### Client Breaking Changes diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 791444dc50..4d803df078 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -48,7 +48,7 @@ const ( var _ abci.Application = (*BaseApp)(nil) // BaseApp reflects the ABCI application implementation. -type BaseApp struct { //nolint: maligned +type BaseApp struct { // initialized on creation logger log.Logger name string // application name from abci.Info diff --git a/client/grpc_query.go b/client/grpc_query.go index b79e2a1f68..6ae3d9b8b8 100644 --- a/client/grpc_query.go +++ b/client/grpc_query.go @@ -2,7 +2,6 @@ package client import ( gocontext "context" - "errors" "fmt" "reflect" "strconv" @@ -142,7 +141,3 @@ func (ctx Context) gRPCCodec() encoding.Codec { return pc.GRPCCodec() } - -// errCodecNotSet is return by failingInterfaceRegistry in case there are attempt to decode -// or encode a type which contains an interface field. -var errCodecNotSet = errors.New("client: cannot encode or decode type which requires the application specific codec") diff --git a/codec/proto_codec.go b/codec/proto_codec.go index f6cf06189d..965954ae2d 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -151,9 +151,7 @@ func (pc *ProtoCodec) MustUnmarshalLengthPrefixed(bz []byte, ptr gogoproto.Messa // it marshals to JSON using proto codec. // NOTE: this function must be used with a concrete type which // implements proto.Message. For interface please use the codec.MarshalInterfaceJSON -// -//nolint:stdmethods -func (pc *ProtoCodec) MarshalJSON(o gogoproto.Message) ([]byte, error) { +func (pc *ProtoCodec) MarshalJSON(o gogoproto.Message) ([]byte, error) { //nolint:stdmethods // we don't want to implement Marshaler interface if o == nil { return nil, fmt.Errorf("cannot protobuf JSON encode nil") } diff --git a/codec/types/any.go b/codec/types/any.go index 5ecc297f8e..334bed7463 100644 --- a/codec/types/any.go +++ b/codec/types/any.go @@ -1,4 +1,3 @@ -// nolint package types import ( @@ -11,6 +10,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) +// nolint:revive // XXX is reqired for proto compatibility type Any struct { // A URL/resource name that uniquely identifies the type of the serialized // protocol buffer message. This string must contain at least diff --git a/codec/types/any_internal_test.go b/codec/types/any_internal_test.go index b2b12b123b..f413f95528 100644 --- a/codec/types/any_internal_test.go +++ b/codec/types/any_internal_test.go @@ -17,7 +17,7 @@ func (d Dog) Greet() string { return d.Name } func (d *Dog) Reset() { d.Name = "" } func (d *Dog) String() string { return d.Name } func (d *Dog) ProtoMessage() {} -func (d *Dog) XXX_MessageName() string { return "tests/dog" } //nolint:revive +func (d *Dog) XXX_MessageName() string { return "tests/dog" } //nolint:revive // XXX_ prefix is required type Animal interface { Greet() string diff --git a/codec/types/any_test.go b/codec/types/any_test.go index 656344414a..06c0f5b418 100644 --- a/codec/types/any_test.go +++ b/codec/types/any_test.go @@ -19,7 +19,7 @@ var _ proto.Message = (*errOnMarshal)(nil) var errAlways = fmt.Errorf("always erroring") -func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { //nolint:revive +func (eom *errOnMarshal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { //nolint:revive // XXX_ prefix is intentional return nil, errAlways } diff --git a/codec/types/types_test.go b/codec/types/types_test.go index 2c24a87ce0..4bb3f7d609 100644 --- a/codec/types/types_test.go +++ b/codec/types/types_test.go @@ -44,7 +44,7 @@ var ( func (dog FakeDog) Reset() {} func (dog FakeDog) String() string { return "fakedog" } func (dog FakeDog) ProtoMessage() {} -func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) } //nolint:revive +func (dog FakeDog) XXX_MessageName() string { return proto.MessageName(&testdata.Dog{}) } //nolint:revive // XXX_ prefix is intentional func (dog FakeDog) Greet() string { return "fakedog" } func TestRegister(t *testing.T) { diff --git a/crypto/hd/hdpath_test.go b/crypto/hd/hdpath_test.go index 126a2a24f0..cce81df86f 100644 --- a/crypto/hd/hdpath_test.go +++ b/crypto/hd/hdpath_test.go @@ -185,7 +185,7 @@ func TestDeriveHDPathRange(t *testing.T) { } } -func ExampleStringifyPathParams() { //nolint:govet +func ExampleStringifyPathParams() { //nolint:govet // ignore naming convention path := hd.NewParams(44, 0, 0, false, 0) fmt.Println(path.String()) path = hd.NewParams(44, 33, 7, true, 9) @@ -195,7 +195,7 @@ func ExampleStringifyPathParams() { //nolint:govet // m/44'/33'/7'/1/9 } -func ExampleSomeBIP32TestVecs() { //nolint:govet +func ExampleSomeBIP32TestVecs() { //nolint:govet // ignore naming convention seed := mnemonicToSeed("barrel original fuel morning among eternal " + "filter ball stove pluck matrix mechanic") master, ch := hd.ComputeMastersFromSeed(seed) diff --git a/crypto/keys/multisig/amino.go b/crypto/keys/multisig/amino.go index 8c83b27021..1973a31a66 100644 --- a/crypto/keys/multisig/amino.go +++ b/crypto/keys/multisig/amino.go @@ -66,7 +66,7 @@ func tmToProto(tmPk tmMultisig) (*LegacyAminoPubKey, error) { } // MarshalAminoJSON overrides amino JSON unmarshaling. -func (m LegacyAminoPubKey) MarshalAminoJSON() (tmMultisig, error) { //nolint:golint,revive +func (m LegacyAminoPubKey) MarshalAminoJSON() (tmMultisig, error) { //nolint:golint,revive // we need to override the default amino JSON marshaling return protoToTm(&m) } diff --git a/crypto/keys/secp256k1/secp256k1.go b/crypto/keys/secp256k1/secp256k1.go index 380f16420d..a4860fbb92 100644 --- a/crypto/keys/secp256k1/secp256k1.go +++ b/crypto/keys/secp256k1/secp256k1.go @@ -11,7 +11,7 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/cometbft/cometbft/crypto" secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4" - "golang.org/x/crypto/ripemd160" //nolint: staticcheck + "golang.org/x/crypto/ripemd160" //nolint: staticcheck // keep around for backwards compatibility "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" diff --git a/crypto/ledger/encode_test.go b/crypto/ledger/encode_test.go index 099c8e91a3..b5b06d04f3 100644 --- a/crypto/ledger/encode_test.go +++ b/crypto/ledger/encode_test.go @@ -24,7 +24,7 @@ func checkAminoJSON(t *testing.T, src, dst interface{}, isNil bool) { require.Nil(t, err, "%+v", err) } -func ExamplePrintRegisteredTypes() { +func ExamplePrintRegisteredTypes() { //nolint:govet // ignore for examples _ = cdc.PrintTypes(os.Stdout) // | Type | Name | Prefix | Length | Notes | // | ---- | ---- | ------ | ----- | ------ | diff --git a/server/grpc/gogoreflection/fix_registration.go b/server/grpc/gogoreflection/fix_registration.go index 7d7d3dce2b..58cc60c4a7 100644 --- a/server/grpc/gogoreflection/fix_registration.go +++ b/server/grpc/gogoreflection/fix_registration.go @@ -7,7 +7,7 @@ import ( gogoproto "github.com/cosmos/gogoproto/proto" _ "github.com/cosmos/cosmos-proto" // look above - "github.com/golang/protobuf/proto" //nolint:staticcheck + "github.com/golang/protobuf/proto" //nolint:staticcheck // migrate in a future pr ) func getFileDescriptor(filePath string) []byte { @@ -18,7 +18,7 @@ func getFileDescriptor(filePath string) []byte { return fd } - return proto.FileDescriptor(filePath) //nolint:staticcheck + return proto.FileDescriptor(filePath) //nolint:staticcheck // keep for backward compatibility } func getMessageType(name string) reflect.Type { @@ -27,7 +27,7 @@ func getMessageType(name string) reflect.Type { return typ } - return proto.MessageType(name) //nolint:staticcheck + return proto.MessageType(name) //nolint:staticcheck // keep for backward compatibility } func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc { @@ -39,8 +39,7 @@ func getExtension(extID int32, m proto.Message) *gogoproto.ExtensionDesc { } // check into proto registry - //nolint:staticcheck - for id, desc := range proto.RegisteredExtensions(m) { + for id, desc := range proto.RegisteredExtensions(m) { //nolint:staticcheck // kept for backwards compatibility if id == extID { return &gogoproto.ExtensionDesc{ ExtendedType: desc.ExtendedType, @@ -67,7 +66,7 @@ func getExtensionsNumbers(m proto.Message) []int32 { return out } - protoExts := proto.RegisteredExtensions(m) //nolint:staticcheck + protoExts := proto.RegisteredExtensions(m) //nolint:staticcheck // kept for backwards compatibility out = make([]int32, 0, len(protoExts)) for id := range protoExts { out = append(out, id) diff --git a/server/grpc/gogoreflection/serverreflection.go b/server/grpc/gogoreflection/serverreflection.go index a7be3e4690..55fb9ad5fe 100644 --- a/server/grpc/gogoreflection/serverreflection.go +++ b/server/grpc/gogoreflection/serverreflection.go @@ -46,7 +46,7 @@ import ( "sort" "sync" - //nolint: staticcheck + //nolint: staticcheck // keep this import for backward compatibility "github.com/golang/protobuf/proto" dpb "github.com/golang/protobuf/protoc-gen-go/descriptor" "google.golang.org/grpc" diff --git a/server/mock/app.go b/server/mock/app.go index 5c977b53d2..078bf2adf6 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -47,7 +47,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { Methods: []grpc.MethodDesc{ { MethodName: "Test", - Handler: _Msg_Test_Handler, + Handler: MsgTestHandler, }, }, } @@ -147,7 +147,7 @@ type MsgServerImpl struct { capKeyMainStore *storetypes.KVStoreKey } -func _Msg_Test_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { //nolint:revive +func MsgTestHandler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { // nolint: revive // refactor this in a followup pr in := new(KVStoreTx) if err := dec(in); err != nil { return nil, err diff --git a/server/mock/tx.go b/server/mock/tx.go index 8201504095..e494fc470c 100644 --- a/server/mock/tx.go +++ b/server/mock/tx.go @@ -121,13 +121,14 @@ func decodeTx(txBytes []byte) (sdk.Tx, error) { var tx sdk.Tx split := bytes.Split(txBytes, []byte("=")) - if len(split) == 1 { //nolint:gocritic + switch len(split) { + case 1: k := split[0] tx = &KVStoreTx{k, k, txBytes, nil} - } else if len(split) == 2 { + case 2: k, v := split[0], split[1] tx = &KVStoreTx{k, v, txBytes, nil} - } else { + default: return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "too many '='") } diff --git a/tests/integration/aminojson/aminojson_test.go b/tests/integration/aminojson/aminojson_test.go index 0bdb983073..796f440828 100644 --- a/tests/integration/aminojson/aminojson_test.go +++ b/tests/integration/aminojson/aminojson_test.go @@ -783,8 +783,8 @@ func TestDecimalMutation(t *testing.T) { // prior to the merge of https://github.com/cosmos/cosmos-sdk/pull/15506 // gogoproto.Marshal would mutate Decimal fields changing JSON output as shown in the assertions below - //require.NotEqual(t, `{"rate":"0","max_rate":"0","max_change_rate":"0"}`, string(rateBz)) - //require.Equal(t, + // require.NotEqual(t, `{"rate":"0","max_rate":"0","max_change_rate":"0"}`, string(rateBz)) + // require.Equal(t, // `{"rate":"0.000000000000000000","max_rate":"0.000000000000000000","max_change_rate":"0.000000000000000000"}`, // string(rateBz)) diff --git a/types/coin_test.go b/types/coin_test.go index 9f8dad0cd8..28f20fe9b1 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -1293,21 +1293,19 @@ func (s *coinTestSuite) TestCoinValidate() { t := s.T() t.Run(tc.name, func(t *testing.T) { err := tc.coin.Validate() - if tc.wantErr == "" { + switch { + case tc.wantErr == "": if err != nil { t.Errorf("Unexpected error: %v", err) } return - } else { - if err == nil { - t.Error("Expected an error") - } else if !strings.Contains(err.Error(), tc.wantErr) { - t.Errorf("Error mismatch\n\tGot: %q\nWant: %q", err, tc.wantErr) - } + case err == nil: + t.Error("Expected an error") + case !strings.Contains(err.Error(), tc.wantErr): + t.Errorf("Error mismatch\n\tGot: %q\nWant: %q", err, tc.wantErr) } }) } - } func (s *coinTestSuite) TestCoinAminoEncoding() { diff --git a/types/context_test.go b/types/context_test.go index 3a605d0a09..926f28dba1 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -139,7 +139,7 @@ func (s *contextTestSuite) TestContextWithCustom() { s.Require().Equal(cp, ctx.WithConsensusParams(cp).ConsensusParams()) // test inner context - newContext := context.WithValue(ctx.Context(), "key", "value") //nolint:golint,staticcheck,revive + newContext := context.WithValue(ctx.Context(), struct{}{}, "value") s.Require().NotEqual(ctx.Context(), ctx.WithContext(newContext).Context()) } diff --git a/types/module/simulation.go b/types/module/simulation.go index 036ef3a9f7..00d0d00dd0 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -33,7 +33,7 @@ type HasProposalMsgs interface { // HasProposalContents defines the contents that can be used to simulate legacy governance (v1beta1) proposals type HasProposalContents interface { // content functions used to simulate governance proposals - ProposalContents(simState SimulationState) []simulation.WeightedProposalContent //nolint:staticcheck + ProposalContents(simState SimulationState) []simulation.WeightedProposalContent //nolint:staticcheck // legacy v1beta1 governance } // SimulationManager defines a simulation manager that provides the high level utility @@ -151,7 +151,7 @@ type SimulationState struct { GenTimestamp time.Time // genesis timestamp UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules - //nolint:staticcheck + //nolint:staticcheck // legacy used for testing LegacyProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key ProposalMsgs []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key } diff --git a/types/utils.go b/types/utils.go index 8496380938..02f022d1d4 100644 --- a/types/utils.go +++ b/types/utils.go @@ -75,13 +75,13 @@ func ParseTimeBytes(bz []byte) (time.Time, error) { } // Parses an encoded type using FormatTimeKey back into a time.Time -func ParseTime(T any) (time.Time, error) { //nolint:gocritic +func ParseTime(t any) (time.Time, error) { var ( result time.Time err error ) - switch t := T.(type) { + switch t := t.(type) { case time.Time: result, err = t, nil case []byte: diff --git a/x/auth/keeper/migrations.go b/x/auth/keeper/migrations.go index 5f75deaa96..62e8b851fd 100644 --- a/x/auth/keeper/migrations.go +++ b/x/auth/keeper/migrations.go @@ -63,7 +63,7 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error { // set the account without map to accAddr to accNumber. // // NOTE: This is used for testing purposes only. -func (m Migrator) V45_SetAccount(ctx sdk.Context, acc sdk.AccountI) error { //nolint:revive +func (m Migrator) V45SetAccount(ctx sdk.Context, acc sdk.AccountI) error { addr := acc.GetAddress() store := m.keeper.storeService.OpenKVStore(ctx) diff --git a/x/auth/migrations/v3/store_test.go b/x/auth/migrations/v3/store_test.go index 93d1b49b9b..df48533de9 100644 --- a/x/auth/migrations/v3/store_test.go +++ b/x/auth/migrations/v3/store_test.go @@ -68,7 +68,7 @@ func TestMigrateMapAccAddressToAccNumberKey(t *testing.T) { // migrator m := keeper.NewMigrator(accountKeeper, app.GRPCQueryRouter(), legacySubspace) // set the account to store with map acc addr to acc number - require.NoError(t, m.V45_SetAccount(ctx, acc)) + require.NoError(t, m.V45SetAccount(ctx, acc)) testCases := []struct { name string diff --git a/x/auth/signing/verify.go b/x/auth/signing/verify.go index 826df596bc..3ed7df8546 100644 --- a/x/auth/signing/verify.go +++ b/x/auth/signing/verify.go @@ -49,7 +49,7 @@ func VerifySignature(ctx context.Context, pubKey cryptotypes.PubKey, signerData // checks if the sign mode handler supports SignModeHandlerWithContext, in // which case it passes the context.Context argument. Otherwise, it fallbacks // to GetSignBytes. -func GetSignBytesWithContext(h SignModeHandler, ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) { //nolint:revive +func GetSignBytesWithContext(h SignModeHandler, ctx context.Context, mode signing.SignMode, data SignerData, tx sdk.Tx) ([]byte, error) { //nolint:revive // refactor this in a future pr hWithCtx, ok := h.(SignModeHandlerWithContext) if ok { return hWithCtx.GetSignBytesWithContext(ctx, mode, data, tx) diff --git a/x/auth/tx/builder_test.go b/x/auth/tx/builder_test.go index 68e13ebe3d..5aa19e5e6e 100644 --- a/x/auth/tx/builder_test.go +++ b/x/auth/tx/builder_test.go @@ -24,7 +24,7 @@ func TestTxBuilder(t *testing.T) { marshaler := codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) txBuilder := newBuilder(nil) - memo := "sometestmemo" //nolint:goconst + memo := "testmemo" msgs := []sdk.Msg{testdata.NewTestMsg(addr)} accSeq := uint64(2) // Arbitrary account sequence any, err := codectypes.NewAnyWithValue(pubkey) diff --git a/x/auth/tx/service.go b/x/auth/tx/service.go index c4bfb2b665..9f4d56a931 100644 --- a/x/auth/tx/service.go +++ b/x/auth/tx/service.go @@ -6,7 +6,7 @@ import ( "strings" gogogrpc "github.com/cosmos/gogoproto/grpc" - "github.com/golang/protobuf/proto" //nolint:staticcheck + "github.com/golang/protobuf/proto" //nolint:staticcheck // keep legacy for now "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" diff --git a/x/authz/codec/cdc.go b/x/authz/codec/cdc.go index a329ad1170..520e435afd 100644 --- a/x/authz/codec/cdc.go +++ b/x/authz/codec/cdc.go @@ -6,7 +6,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var Amino = codec.NewLegacyAmino() +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(Amino) +) func init() { cryptocodec.RegisterCrypto(Amino) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index c7d539fcf4..d23ef9c623 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -41,7 +41,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { var ( amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) //nolint:staticcheck // TODO: remove once amino is removed + ModuleCdc = codec.NewAminoCodec(amino) ) func init() { diff --git a/x/consensus/types/codec.go b/x/consensus/types/codec.go index 32f009ccdb..205596743f 100644 --- a/x/consensus/types/codec.go +++ b/x/consensus/types/codec.go @@ -27,7 +27,10 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/consensus/MsgUpdateParams") } -var amino = codec.NewLegacyAmino() +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) func init() { RegisterLegacyAminoCodec(amino) diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index b469f00514..189c48a6ff 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -29,7 +29,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var aminoCdc = codec.NewLegacyAmino() +var ( + aminoCdc = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(aminoCdc) +) func init() { RegisterLegacyAminoCodec(aminoCdc) diff --git a/x/distribution/keeper/msg_server.go b/x/distribution/keeper/msg_server.go index a52774d767..aaec35b527 100644 --- a/x/distribution/keeper/msg_server.go +++ b/x/distribution/keeper/msg_server.go @@ -122,8 +122,8 @@ func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority) } - if (!req.Params.BaseProposerReward.IsNil() && !req.Params.BaseProposerReward.IsZero()) || //nolint:staticcheck - (!req.Params.BonusProposerReward.IsNil() && !req.Params.BonusProposerReward.IsZero()) { //nolint:staticcheck + if (!req.Params.BaseProposerReward.IsNil() && !req.Params.BaseProposerReward.IsZero()) || //nolint:staticcheck // deprecated but kept for backwards compatibility + (!req.Params.BonusProposerReward.IsNil() && !req.Params.BonusProposerReward.IsZero()) { //nolint:staticcheck // deprecated but kept for backwards compatibility return nil, errorsmod.Wrapf(errors.ErrInvalidRequest, "cannot update base or bonus proposer reward because these are deprecated fields") } diff --git a/x/genutil/module.go b/x/genutil/module.go index 735d4390bc..85d70d39eb 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -132,10 +132,8 @@ func init() { ) } -// GenutilInputs defines the inputs needed for the genutil module. -// -//nolint:revive -type GenutilInputs struct { +// ModuleInputs defines the inputs needed for the genutil module. +type ModuleInputs struct { depinject.In AccountKeeper types.AccountKeeper @@ -144,7 +142,7 @@ type GenutilInputs struct { Config client.TxConfig } -func ProvideModule(in GenutilInputs) appmodule.AppModule { +func ProvideModule(in ModuleInputs) appmodule.AppModule { m := NewAppModule(in.AccountKeeper, in.StakingKeeper, in.DeliverTx, in.Config) return m } diff --git a/x/gov/keeper/msg_server_test.go b/x/gov/keeper/msg_server_test.go index eef8dd1124..4f6cd477c7 100644 --- a/x/gov/keeper/msg_server_test.go +++ b/x/gov/keeper/msg_server_test.go @@ -14,6 +14,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) +const ( + abc = "abc" + o1 = "-0.1" +) + var ( longAddress = "cosmos1v9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpv9skzctpg0s5ed" longAddressError = "address max length is 255" @@ -977,7 +982,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() { name: "invalid quorum", input: func() *v1.MsgUpdateParams { params1 := params - params1.Quorum = "abc" //nolint:goconst + params1.Quorum = abc return &v1.MsgUpdateParams{ Authority: authority, @@ -991,7 +996,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() { name: "negative quorum", input: func() *v1.MsgUpdateParams { params1 := params - params1.Quorum = "-0.1" + params1.Quorum = o1 return &v1.MsgUpdateParams{ Authority: authority, @@ -1019,7 +1024,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() { name: "invalid threshold", input: func() *v1.MsgUpdateParams { params1 := params - params1.Threshold = "abc" + params1.Threshold = abc return &v1.MsgUpdateParams{ Authority: authority, @@ -1033,7 +1038,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() { name: "negative threshold", input: func() *v1.MsgUpdateParams { params1 := params - params1.Threshold = "-0.1" + params1.Threshold = o1 return &v1.MsgUpdateParams{ Authority: authority, @@ -1061,7 +1066,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() { name: "invalid veto threshold", input: func() *v1.MsgUpdateParams { params1 := params - params1.VetoThreshold = "abc" + params1.VetoThreshold = abc return &v1.MsgUpdateParams{ Authority: authority, @@ -1075,7 +1080,7 @@ func (suite *KeeperTestSuite) TestMsgUpdateParams() { name: "negative veto threshold", input: func() *v1.MsgUpdateParams { params1 := params - params1.VetoThreshold = "-0.1" + params1.VetoThreshold = o1 return &v1.MsgUpdateParams{ Authority: authority, diff --git a/x/gov/types/v1/msgs_test.go b/x/gov/types/v1/msgs_test.go index 2c721ad640..d0dfe7d170 100644 --- a/x/gov/types/v1/msgs_test.go +++ b/x/gov/types/v1/msgs_test.go @@ -21,6 +21,8 @@ var ( sdk.AccAddress("test1"), sdk.AccAddress("test2"), } + + metadata = "metadata" ) func init() { @@ -62,7 +64,6 @@ func TestMsgDeposit(t *testing.T) { // test ValidateBasic for MsgVote func TestMsgVote(t *testing.T) { - metadata := "metadata" //nolint:goconst tests := []struct { proposalID uint64 voterAddr sdk.AccAddress @@ -90,7 +91,6 @@ func TestMsgVote(t *testing.T) { // test ValidateBasic for MsgVoteWeighted func TestMsgVoteWeighted(t *testing.T) { - metadata := "metadata" tests := []struct { proposalID uint64 voterAddr sdk.AccAddress @@ -135,7 +135,6 @@ func TestMsgVoteWeighted(t *testing.T) { } func TestMsgSubmitProposal_ValidateBasic(t *testing.T) { - metadata := "metadata" // Valid msg msg1, err := v1.NewLegacyContent(v1beta1.NewTextProposal("Title", "description"), addrs[0].String()) require.NoError(t, err) diff --git a/x/group/internal/math/dec_test.go b/x/group/internal/math/dec_test.go index 27757b01e9..c52f2219f8 100644 --- a/x/group/internal/math/dec_test.go +++ b/x/group/internal/math/dec_test.go @@ -2,8 +2,6 @@ package math import ( "fmt" - "regexp" - "strconv" "testing" "github.com/stretchr/testify/require" @@ -257,41 +255,3 @@ func testIsNegative(t *rapid.T) { require.Equal(t, f < 0, dec.IsNegative()) } - -func floatDecimalPlaces(t *rapid.T, f float64) uint32 { //nolint:unused - reScientific := regexp.MustCompile(`^\-?(?:[[:digit:]]+(?:\.([[:digit:]]+))?|\.([[:digit:]]+))(?:e?(?:\+?([[:digit:]]+)|(-[[:digit:]]+)))?$`) - fStr := fmt.Sprintf("%g", f) - matches := reScientific.FindAllStringSubmatch(fStr, 1) - if len(matches) != 1 { - t.Fatalf("Didn't match float: %g", f) - } - - // basePlaces is the number of decimal places in the decimal part of the - // string - basePlaces := 0 - if matches[0][1] != "" { - basePlaces = len(matches[0][1]) - } else if matches[0][2] != "" { - basePlaces = len(matches[0][2]) - } - t.Logf("Base places: %d", basePlaces) - - // exp is the exponent - exp := 0 - if matches[0][3] != "" { - var err error - exp, err = strconv.Atoi(matches[0][3]) - require.NoError(t, err) - } else if matches[0][4] != "" { - var err error - exp, err = strconv.Atoi(matches[0][4]) - require.NoError(t, err) - } - - // Subtract exponent from base and check if negative - if res := basePlaces - exp; res <= 0 { - return 0 - } else { //nolint:revive - return uint32(res) - } -} diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 50dced5068..de71e3153e 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -180,7 +180,7 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { suite.Require().NoError(err) var msg types.MsgUnjail - types.Amino.UnmarshalJSON(operationMsg.Msg, &msg) + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddr) diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 7a171ac481..ce9fb7e489 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -29,12 +29,15 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } -var Amino = codec.NewLegacyAmino() +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) func init() { - RegisterLegacyAminoCodec(Amino) - cryptocodec.RegisterCrypto(Amino) - sdk.RegisterLegacyAminoCodec(Amino) + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index fe58c224a6..db8dc4c489 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -32,7 +32,7 @@ func (msg MsgUnjail) GetSigners() []sdk.AccAddress { // GetSignBytes gets the bytes for the message signer to sign on func (msg MsgUnjail) GetSignBytes() []byte { - bz := Amino.MustMarshalJSON(&msg) + bz := ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } @@ -46,7 +46,7 @@ func (msg MsgUnjail) ValidateBasic() error { // GetSignBytes implements the LegacyMsg interface. func (msg MsgUpdateParams) GetSignBytes() []byte { - return sdk.MustSortJSON(Amino.MustMarshalJSON(&msg)) + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } // GetSigners returns the expected signers for a MsgUpdateParams message. diff --git a/x/staking/module.go b/x/staking/module.go index e58654f0df..b58a7ee191 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -62,7 +62,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { } // RegisterInterfaces registers the module's interface types -func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { +func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { types.RegisterInterfaces(registry) } diff --git a/x/tx/signing/aminojson/aminojson_test.go b/x/tx/signing/aminojson/aminojson_test.go index 723657d9e4..511ac8a654 100644 --- a/x/tx/signing/aminojson/aminojson_test.go +++ b/x/tx/signing/aminojson/aminojson_test.go @@ -101,7 +101,6 @@ func TestAminoJsonSignMode(t *testing.T) { require.NoError(t, err) }) } - } func TestNewSignModeHandler(t *testing.T) {