From 18fa86b09823444d18fd83f222a3b7756282e13e Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Tue, 26 Dec 2023 14:31:18 -0800 Subject: [PATCH] lint++ --- .../packetforward/ibc_middleware.go | 2 +- .../packetforward/keeper/keeper.go | 7 ++-- .../packetforward/keeper/params.go | 3 +- .../packetforward/migrations/v2/migrate.go | 1 + .../migrations/v2/migrator_test.go | 1 + .../packetforward/module_test.go | 1 + .../packetforward/types/expected_keepers.go | 2 +- .../packet-forward-middleware/test/setup.go | 7 ++-- .../testing/simapp/app.go | 32 +++++++++++-------- .../testing/simapp/export.go | 30 +++++++++++++---- .../testing/simapp/simd/commands.go | 7 ++-- .../testing/simapp/simd/root.go | 6 ++-- .../testing/simapp/upgrades/upgrades.go | 5 ++- .../simapp/x/dummyware/ibc_middleware.go | 2 +- 14 files changed, 71 insertions(+), 35 deletions(-) diff --git a/middleware/packet-forward-middleware/packetforward/ibc_middleware.go b/middleware/packet-forward-middleware/packetforward/ibc_middleware.go index eda49313..f7d5848f 100644 --- a/middleware/packet-forward-middleware/packetforward/ibc_middleware.go +++ b/middleware/packet-forward-middleware/packetforward/ibc_middleware.go @@ -16,8 +16,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" diff --git a/middleware/packet-forward-middleware/packetforward/keeper/keeper.go b/middleware/packet-forward-middleware/packetforward/keeper/keeper.go index a7722750..3dad3e44 100644 --- a/middleware/packet-forward-middleware/packetforward/keeper/keeper.go +++ b/middleware/packet-forward-middleware/packetforward/keeper/keeper.go @@ -7,16 +7,20 @@ import ( "strings" "time" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" + "github.com/hashicorp/go-metrics" + errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" @@ -24,7 +28,6 @@ import ( porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" coretypes "github.com/cosmos/ibc-go/v8/modules/core/types" - "github.com/hashicorp/go-metrics" ) var ( diff --git a/middleware/packet-forward-middleware/packetforward/keeper/params.go b/middleware/packet-forward-middleware/packetforward/keeper/params.go index d4ee4802..8ee04dd9 100644 --- a/middleware/packet-forward-middleware/packetforward/keeper/params.go +++ b/middleware/packet-forward-middleware/packetforward/keeper/params.go @@ -1,9 +1,10 @@ package keeper import ( - sdkmath "cosmossdk.io/math" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/middleware/packet-forward-middleware/packetforward/migrations/v2/migrate.go b/middleware/packet-forward-middleware/packetforward/migrations/v2/migrate.go index 57be7723..72fd797f 100644 --- a/middleware/packet-forward-middleware/packetforward/migrations/v2/migrate.go +++ b/middleware/packet-forward-middleware/packetforward/migrations/v2/migrate.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/middleware/packet-forward-middleware/packetforward/migrations/v2/migrator_test.go b/middleware/packet-forward-middleware/packetforward/migrations/v2/migrator_test.go index b3118a62..6070962a 100644 --- a/middleware/packet-forward-middleware/packetforward/migrations/v2/migrator_test.go +++ b/middleware/packet-forward-middleware/packetforward/migrations/v2/migrator_test.go @@ -11,6 +11,7 @@ import ( sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" diff --git a/middleware/packet-forward-middleware/packetforward/module_test.go b/middleware/packet-forward-middleware/packetforward/module_test.go index b59607fc..13b59421 100644 --- a/middleware/packet-forward-middleware/packetforward/module_test.go +++ b/middleware/packet-forward-middleware/packetforward/module_test.go @@ -13,6 +13,7 @@ import ( "go.uber.org/mock/gomock" sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" diff --git a/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go b/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go index edc99ace..a35b97e3 100644 --- a/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go +++ b/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ) diff --git a/middleware/packet-forward-middleware/test/setup.go b/middleware/packet-forward-middleware/test/setup.go index 4b5318f7..9534c4cb 100644 --- a/middleware/packet-forward-middleware/test/setup.go +++ b/middleware/packet-forward-middleware/test/setup.go @@ -4,6 +4,7 @@ import ( "testing" "time" + dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" @@ -11,17 +12,17 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" + "cosmossdk.io/log" "cosmossdk.io/store" "cosmossdk.io/store/metrics" storetypes "cosmossdk.io/store/types" - dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - "cosmossdk.io/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" @@ -97,6 +98,8 @@ type initializer struct { // Create an initializer with in memory database and default codecs func newInitializer(t *testing.T) initializer { + t.Helper() + logger := log.NewTestLogger(t) logger.Debug("initializing test setup") diff --git a/middleware/packet-forward-middleware/testing/simapp/app.go b/middleware/packet-forward-middleware/testing/simapp/app.go index 34bd800f..169a5794 100644 --- a/middleware/packet-forward-middleware/testing/simapp/app.go +++ b/middleware/packet-forward-middleware/testing/simapp/app.go @@ -7,6 +7,8 @@ import ( "os" "path/filepath" + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/gogoproto/proto" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward" packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" @@ -21,7 +23,7 @@ import ( reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/client/v2/autocli" "cosmossdk.io/core/appmodule" - + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/evidence" evidencekeeper "cosmossdk.io/x/evidence/keeper" @@ -33,6 +35,7 @@ import ( "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -57,7 +60,6 @@ import ( authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/tx" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" @@ -101,20 +103,16 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/gogoproto/proto" + + abci "github.com/cometbft/cometbft/abci/types" + tmos "github.com/cometbft/cometbft/libs/os" + "github.com/cosmos/ibc-go/modules/capability" capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper" ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" - - "cosmossdk.io/log" - abci "github.com/cometbft/cometbft/abci/types" - tmos "github.com/cometbft/cometbft/libs/os" - dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/ibc-go/v8/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" @@ -125,6 +123,7 @@ import ( solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v8/testing" + ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types" ) @@ -277,7 +276,7 @@ func NewSimApp( }) appCodec := codec.NewProtoCodec(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() - txConfig := tx.NewTxConfig(appCodec, tx.DefaultSignModes) + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) @@ -695,7 +694,10 @@ func NewSimApp( app.mm.RegisterInvariants(app.CrisisKeeper) app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) - app.mm.RegisterServices(app.configurator) + + if err := app.mm.RegisterServices(app.configurator); err != nil { + panic(err) + } // add test gRPC service for testing gRPC queries in isolation autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules)) @@ -780,7 +782,11 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*ab if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) } - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()) + + if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()); err != nil { + panic(err) + } + return app.mm.InitGenesis(ctx, app.appCodec, genesisState) } diff --git a/middleware/packet-forward-middleware/testing/simapp/export.go b/middleware/packet-forward-middleware/testing/simapp/export.go index 018ccf13..166b0ab5 100644 --- a/middleware/packet-forward-middleware/testing/simapp/export.go +++ b/middleware/packet-forward-middleware/testing/simapp/export.go @@ -5,8 +5,6 @@ import ( "fmt" "log" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - storetypes "cosmossdk.io/store/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -14,6 +12,8 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" ) // ExportAppStateAndValidators exports the state of the application for a genesis @@ -166,7 +166,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] /* Handle staking state. */ // iterate through redelegations, reset creation height - app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { + err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { for i := range red.Entries { red.Entries[i].CreationHeight = 0 } @@ -174,11 +174,15 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] if err != nil { panic(err) } + return false }) + if err != nil { + panic(err) + } // iterate through unbonding delegations, reset creation height - app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { + err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { for i := range ubd.Entries { ubd.Entries[i].CreationHeight = 0 } @@ -188,6 +192,9 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] } return false }) + if err != nil { + panic(err) + } // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. @@ -207,7 +214,10 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] validator.Jailed = true } - app.StakingKeeper.SetValidator(ctx, validator) + if err := app.StakingKeeper.SetValidator(ctx, validator); err != nil { + panic(err) + } + counter++ } @@ -224,12 +234,18 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs [] /* Handle slashing state. */ // reset start height on signing infos - app.SlashingKeeper.IterateValidatorSigningInfos( + err = app.SlashingKeeper.IterateValidatorSigningInfos( ctx, func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { info.StartHeight = 0 - app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) + if err := app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info); err != nil { + panic(err) + } + return false }, ) + if err != nil { + panic(err) + } } diff --git a/middleware/packet-forward-middleware/testing/simapp/simd/commands.go b/middleware/packet-forward-middleware/testing/simapp/simd/commands.go index 3a36cace..47fedc5d 100644 --- a/middleware/packet-forward-middleware/testing/simapp/simd/commands.go +++ b/middleware/packet-forward-middleware/testing/simapp/simd/commands.go @@ -5,15 +5,14 @@ import ( "io" "os" - cmtcfg "github.com/cometbft/cometbft/config" dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/testing/simapp" app "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/testing/simapp" "github.com/spf13/cobra" "github.com/spf13/viper" "cosmossdk.io/log" confixcmd "cosmossdk.io/tools/confix/cmd" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/debug" "github.com/cosmos/cosmos-sdk/client/flags" @@ -31,6 +30,8 @@ import ( authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + + cmtcfg "github.com/cometbft/cometbft/config" ) // initCometBFTConfig helps to override default CometBFT Config values. @@ -251,7 +252,7 @@ func appExport( var tempDir = func() string { dir, err := os.MkdirTemp("", "simapp") if err != nil { - dir = simapp.DefaultNodeHome + dir = app.DefaultNodeHome } defer os.RemoveAll(dir) diff --git a/middleware/packet-forward-middleware/testing/simapp/simd/root.go b/middleware/packet-forward-middleware/testing/simapp/simd/root.go index 2ce5956a..7a67be39 100644 --- a/middleware/packet-forward-middleware/testing/simapp/simd/root.go +++ b/middleware/packet-forward-middleware/testing/simapp/simd/root.go @@ -3,12 +3,13 @@ package main import ( "os" - "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" app "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/testing/simapp" appparams "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/testing/simapp/params" "github.com/spf13/cobra" + "cosmossdk.io/log" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -68,9 +69,8 @@ func NewRootCmd() *cobra.Command { // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode // is only available if the client is online. if !initClientCtx.Offline { - enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) txConfigOpts := tx.ConfigOptions{ - EnabledSignModes: enabledSignModes, + EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL), TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), } txConfig, err := tx.NewTxConfigWithOptions( diff --git a/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go b/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go index 4cce77ee..6b156e20 100644 --- a/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go +++ b/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go @@ -7,6 +7,7 @@ import ( packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -54,7 +55,9 @@ func CreateV2UpgradeHandler( // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. // The old params module is required to still be imported in your app.go in order to handle this migration. baseAppLegacySS := paramskeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) - baseapp.MigrateParams(sdk.UnwrapSDKContext(ctx), baseAppLegacySS, &consensusparamskeeper.ParamsStore) + if err := baseapp.MigrateParams(sdk.UnwrapSDKContext(ctx), baseAppLegacySS, &consensusparamskeeper.ParamsStore); err != nil { + return nil, err + } versionMap, err := mm.RunMigrations(ctx, cfg, fromVM) if err != nil { diff --git a/middleware/packet-forward-middleware/testing/simapp/x/dummyware/ibc_middleware.go b/middleware/packet-forward-middleware/testing/simapp/x/dummyware/ibc_middleware.go index f36a3b4c..96202d99 100644 --- a/middleware/packet-forward-middleware/testing/simapp/x/dummyware/ibc_middleware.go +++ b/middleware/packet-forward-middleware/testing/simapp/x/dummyware/ibc_middleware.go @@ -6,8 +6,8 @@ import ( forwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" sdk "github.com/cosmos/cosmos-sdk/types" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"