From e2bd820c3c010202552209f5fec4bf16fde3b862 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Fri, 31 Mar 2023 11:24:40 +0700 Subject: [PATCH 1/5] linter fixes for feegrant and upgrade --- x/feegrant/grant.go | 2 +- x/feegrant/msgs.go | 4 ++-- x/feegrant/simulation/operations.go | 2 +- x/upgrade/internal/conv/string_test.go | 2 +- x/upgrade/keeper/grpc_query.go | 8 +++----- x/upgrade/keeper/keeper_test.go | 2 +- x/upgrade/module.go | 6 ++---- x/upgrade/plan/downloader_test.go | 4 +--- x/upgrade/types/storeloader_test.go | 2 +- 9 files changed, 13 insertions(+), 19 deletions(-) diff --git a/x/feegrant/grant.go b/x/feegrant/grant.go index 8ea74bbce6b2..73e9a025bdb8 100644 --- a/x/feegrant/grant.go +++ b/x/feegrant/grant.go @@ -14,7 +14,7 @@ var _ types.UnpackInterfacesMessage = &Grant{} // NewGrant creates a new FeeAllowanceGrant. // -//nolint:interfacer + func NewGrant(granter, grantee sdk.AccAddress, feeAllowance FeeAllowanceI) (Grant, error) { msg, ok := feeAllowance.(proto.Message) if !ok { diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 50bbc293bc7b..5f86f91e0784 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -21,7 +21,7 @@ var ( // NewMsgGrantAllowance creates a new MsgGrantAllowance. // -//nolint:interfacer + func NewMsgGrantAllowance(feeAllowance FeeAllowanceI, granter, grantee sdk.AccAddress) (*MsgGrantAllowance, error) { msg, ok := feeAllowance.(proto.Message) if !ok { @@ -74,7 +74,7 @@ func (msg MsgGrantAllowance) UnpackInterfaces(unpacker types.AnyUnpacker) error // NewMsgRevokeAllowance returns a message to revoke a fee allowance for a given // granter and grantee // -//nolint:interfacer + func NewMsgRevokeAllowance(granter, grantee sdk.AccAddress) MsgRevokeAllowance { return MsgRevokeAllowance{Granter: granter.String(), Grantee: grantee.String()} } diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 173a6478f9e7..cb97eee6b9c5 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -17,7 +17,7 @@ import ( // Simulation operation weights constants // -//nolint:gosec // These aren't harcoded credentials. + const ( OpWeightMsgGrantAllowance = "op_weight_msg_grant_fee_allowance" OpWeightMsgRevokeAllowance = "op_weight_msg_grant_revoke_allowance" diff --git a/x/upgrade/internal/conv/string_test.go b/x/upgrade/internal/conv/string_test.go index 484d0a31ea62..dfaaa038cbd8 100644 --- a/x/upgrade/internal/conv/string_test.go +++ b/x/upgrade/internal/conv/string_test.go @@ -26,7 +26,7 @@ func (s *StringSuite) TestUnsafeStrToBytes() { b := unsafeConvertStr() runtime.GC() <-time.NewTimer(2 * time.Millisecond).C - b2 := append(b, 'd') //nolint:gocritic // append is fine here + b2 := append(b, 'd') s.Equal("abc", string(b)) s.Equal("abcd", string(b2)) } diff --git a/x/upgrade/keeper/grpc_query.go b/x/upgrade/keeper/grpc_query.go index ba042693d96e..6c4fe10b36b4 100644 --- a/x/upgrade/keeper/grpc_query.go +++ b/x/upgrade/keeper/grpc_query.go @@ -37,17 +37,15 @@ func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanReques } // UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method -// -//nolint:staticcheck -func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { +func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { //nolint:staticcheck // SA1019: types.QueryUpgradedConsensusStateRequest is deprecated: Use QueryUpgradedConsensusStateRequestV1 instead - this is a test, however ctx := sdk.UnwrapSDKContext(c) consState, found := k.GetUpgradedConsensusState(ctx, req.LastHeight) if !found { - return &types.QueryUpgradedConsensusStateResponse{}, nil + return &types.QueryUpgradedConsensusStateResponse{}, nil //nolint:staticcheck // SA1019: types.QueryUpgradedConsensusStateResponse is deprecated: Use QueryUpgradedConsensusStateResponseV1 instead - this is a test, however } - return &types.QueryUpgradedConsensusStateResponse{ + return &types.QueryUpgradedConsensusStateResponse{ //nolint:staticcheck // SA1019: types.QueryUpgradedConsensusStateResponse is deprecated: Use QueryUpgradedConsensusStateResponseV1 instead - this is a test, however UpgradedConsensusState: consState, }, nil } diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index eed7f80ab3e7..0e699806d18b 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -280,7 +280,7 @@ func (s *KeeperTestSuite) TestMigrations() { vmBefore := s.upgradeKeeper.GetModuleVersionMap(s.ctx) s.upgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) { // simulate upgrading the bank module - vm["bank"] = vm["bank"] + 1 //nolint:gocritic + vm["bank"]++ return vm, nil }) dummyPlan := types.Plan{ diff --git a/x/upgrade/module.go b/x/upgrade/module.go index ba20b20bf6c2..e92dc0685142 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -171,8 +171,7 @@ func init() { ) } -//nolint:revive -type UpgradeInputs struct { +type UpgradeInputs struct { //nolint:revive // for readability, we ignore var-naming rules here depinject.In Config *modulev1.Module @@ -182,8 +181,7 @@ type UpgradeInputs struct { AppOpts servertypes.AppOptions `optional:"true"` } -//nolint:revive -type UpgradeOutputs struct { +type UpgradeOutputs struct { //nolint:revive // for readability, we ignore var-naming rules here depinject.Out UpgradeKeeper *keeper.Keeper diff --git a/x/upgrade/plan/downloader_test.go b/x/upgrade/plan/downloader_test.go index 7a48275ef687..ef0f727550ab 100644 --- a/x/upgrade/plan/downloader_test.go +++ b/x/upgrade/plan/downloader_test.go @@ -65,9 +65,7 @@ type TestZip []*TestFile func NewTestZip(testFiles ...*TestFile) TestZip { tz := make([]*TestFile, len(testFiles)) - for i, tf := range testFiles { //nolint:gosimple - tz[i] = tf - } + copy(tz, testFiles) return tz } diff --git a/x/upgrade/types/storeloader_test.go b/x/upgrade/types/storeloader_test.go index 26926a4e0be2..cb9b678b0b56 100644 --- a/x/upgrade/types/storeloader_test.go +++ b/x/upgrade/types/storeloader_test.go @@ -74,7 +74,7 @@ func TestSetLoader(t *testing.T) { data, err := json.Marshal(upgradeInfo) require.NoError(t, err) - err = os.WriteFile(upgradeInfoFilePath, data, 0o644) //nolint:gosec + err = os.WriteFile(upgradeInfoFilePath, data, 0o600) require.NoError(t, err) // make sure it exists before running everything From cbc5211f6cf7cbc27a49ab2d422baa913015aed0 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 3 Apr 2023 11:09:30 +0700 Subject: [PATCH 2/5] use moduleinputs and moduleoutputs --- x/upgrade/module.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index e92dc0685142..d74494374a56 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -171,7 +171,7 @@ func init() { ) } -type UpgradeInputs struct { //nolint:revive // for readability, we ignore var-naming rules here +type ModuleInputs struct { depinject.In Config *modulev1.Module @@ -181,7 +181,7 @@ type UpgradeInputs struct { //nolint:revive // for readability, we ignore var-na AppOpts servertypes.AppOptions `optional:"true"` } -type UpgradeOutputs struct { //nolint:revive // for readability, we ignore var-naming rules here +type ModuleOutputs struct { depinject.Out UpgradeKeeper *keeper.Keeper @@ -190,7 +190,7 @@ type UpgradeOutputs struct { //nolint:revive // for readability, we ignore var-n BaseAppOption runtime.BaseAppOption } -func ProvideModule(in UpgradeInputs) UpgradeOutputs { +func ProvideModule(in ModuleInputs) ModuleOutputs { var ( homePath string skipUpgradeHeights = make(map[int64]bool) From b38d0282856526831ef31392a366091a8e6748cf Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 3 Apr 2023 11:10:56 +0700 Subject: [PATCH 3/5] don't label non-tests as tests --- x/upgrade/keeper/grpc_query.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/upgrade/keeper/grpc_query.go b/x/upgrade/keeper/grpc_query.go index 6c4fe10b36b4..f46421fcc6f2 100644 --- a/x/upgrade/keeper/grpc_query.go +++ b/x/upgrade/keeper/grpc_query.go @@ -37,15 +37,15 @@ func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanReques } // UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method -func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { //nolint:staticcheck // SA1019: types.QueryUpgradedConsensusStateRequest is deprecated: Use QueryUpgradedConsensusStateRequestV1 instead - this is a test, however +func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { //nolint:staticcheck // we're using a deprecated call for compatiblity ctx := sdk.UnwrapSDKContext(c) consState, found := k.GetUpgradedConsensusState(ctx, req.LastHeight) if !found { - return &types.QueryUpgradedConsensusStateResponse{}, nil //nolint:staticcheck // SA1019: types.QueryUpgradedConsensusStateResponse is deprecated: Use QueryUpgradedConsensusStateResponseV1 instead - this is a test, however + return &types.QueryUpgradedConsensusStateResponse{}, nil //nolint:staticcheck // we're using a deprecated call for compatiblity } - return &types.QueryUpgradedConsensusStateResponse{ //nolint:staticcheck // SA1019: types.QueryUpgradedConsensusStateResponse is deprecated: Use QueryUpgradedConsensusStateResponseV1 instead - this is a test, however + return &types.QueryUpgradedConsensusStateResponse{ //nolint:staticcheck // we're using a deprecated call for compatiblity UpgradedConsensusState: consState, }, nil } From 73f6c3bbb4a078d058b265b4dccd3928a7120146 Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 3 Apr 2023 11:14:16 +0700 Subject: [PATCH 4/5] save grpc_query.go and module.go --- x/upgrade/keeper/grpc_query.go | 6 +++--- x/upgrade/module.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/upgrade/keeper/grpc_query.go b/x/upgrade/keeper/grpc_query.go index f46421fcc6f2..d0c30c36423e 100644 --- a/x/upgrade/keeper/grpc_query.go +++ b/x/upgrade/keeper/grpc_query.go @@ -37,15 +37,15 @@ func (k Keeper) AppliedPlan(c context.Context, req *types.QueryAppliedPlanReques } // UpgradedConsensusState implements the Query/UpgradedConsensusState gRPC method -func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { //nolint:staticcheck // we're using a deprecated call for compatiblity +func (k Keeper) UpgradedConsensusState(c context.Context, req *types.QueryUpgradedConsensusStateRequest) (*types.QueryUpgradedConsensusStateResponse, error) { //nolint:staticcheck // we're using a deprecated call for compatibility ctx := sdk.UnwrapSDKContext(c) consState, found := k.GetUpgradedConsensusState(ctx, req.LastHeight) if !found { - return &types.QueryUpgradedConsensusStateResponse{}, nil //nolint:staticcheck // we're using a deprecated call for compatiblity + return &types.QueryUpgradedConsensusStateResponse{}, nil //nolint:staticcheck // we're using a deprecated call for compatibility } - return &types.QueryUpgradedConsensusStateResponse{ //nolint:staticcheck // we're using a deprecated call for compatiblity + return &types.QueryUpgradedConsensusStateResponse{ //nolint:staticcheck // we're using a deprecated call for compatibility UpgradedConsensusState: consState, }, nil } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index d74494374a56..298fe6f1f0a9 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -218,7 +218,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { m := NewAppModule(k) gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} - return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt} + return ModuleOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt} } func PopulateVersionMap(upgradeKeeper *keeper.Keeper, modules map[string]appmodule.AppModule) { From 23ed0b04dc5acf2a413e3e88429e529e80f10c7d Mon Sep 17 00:00:00 2001 From: Jacob Gadikian Date: Mon, 3 Apr 2023 14:12:31 +0700 Subject: [PATCH 5/5] remove that extra // --- x/feegrant/simulation/operations.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index cb97eee6b9c5..de01159da746 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -16,8 +16,6 @@ import ( ) // Simulation operation weights constants -// - const ( OpWeightMsgGrantAllowance = "op_weight_msg_grant_fee_allowance" OpWeightMsgRevokeAllowance = "op_weight_msg_grant_revoke_allowance"