diff --git a/simapp/app.go b/simapp/app.go index 2b739dcd43..1afa29f01d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -398,7 +398,7 @@ func NewSimApp( slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), - upgrade.NewAppModule(app.UpgradeKeeper), + upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.GetAddressCodec()), evidence.NewAppModule(app.EvidenceKeeper), params.NewAppModule(app.ParamsKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 0bb85a2f77..c3ccf4a087 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -6,18 +6,12 @@ import ( "testing" "time" - cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - "cosmossdk.io/core/appmodule" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" - "cosmossdk.io/x/upgrade" - "cosmossdk.io/x/upgrade/keeper" - "cosmossdk.io/x/upgrade/types" - + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -26,6 +20,12 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "cosmossdk.io/x/upgrade" + "cosmossdk.io/x/upgrade/keeper" + "cosmossdk.io/x/upgrade/types" ) type TestSuite struct { @@ -58,7 +58,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { s.ctx = testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: time.Now(), Height: height}) - s.module = upgrade.NewAppModule(s.keeper) + s.module = upgrade.NewAppModule(s.keeper, addresscodec.NewBech32Codec("cosmos")) s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper) return &s } @@ -476,7 +476,7 @@ func TestDowngradeVerification(t *testing.T) { skip := map[int64]bool{} tempDir := t.TempDir() k := keeper.NewKeeper(skip, key, encCfg.Codec, tempDir, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - m := upgrade.NewAppModule(k) + m := upgrade.NewAppModule(k, addresscodec.NewBech32Codec("cosmos")) handler := upgrade.NewSoftwareUpgradeProposalHandler(k) // submit a plan. @@ -525,7 +525,7 @@ func TestDowngradeVerification(t *testing.T) { // downgrade. now keeper does not have the handler. k := keeper.NewKeeper(skip, key, encCfg.Codec, tempDir, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - m := upgrade.NewAppModule(k) + m := upgrade.NewAppModule(k, addresscodec.NewBech32Codec("cosmos")) // assertions lastAppliedPlan, _ := k.GetLastCompletedUpgrade(ctx) diff --git a/x/upgrade/client/cli/parse_test.go b/x/upgrade/client/cli/parse_test.go index c9ef3946b5..3a3b38eb41 100644 --- a/x/upgrade/client/cli/parse_test.go +++ b/x/upgrade/client/cli/parse_test.go @@ -4,12 +4,14 @@ import ( "strconv" "testing" - "cosmossdk.io/x/upgrade/types" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/stretchr/testify/require" + + "cosmossdk.io/x/upgrade/types" ) func TestParsePlan(t *testing.T) { - fs := NewCmdSubmitUpgradeProposal().Flags() + fs := NewCmdSubmitUpgradeProposal(addresscodec.NewBech32Codec("cosmos")).Flags() proposal := types.MsgSoftwareUpgrade{ Plan: types.Plan{ diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index d00a59047c..893b74680e 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -5,17 +5,17 @@ import ( "os" "path/filepath" - "github.com/spf13/cobra" - - "cosmossdk.io/x/upgrade/plan" - "cosmossdk.io/x/upgrade/types" - + addresscodec "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + "github.com/spf13/cobra" + + "cosmossdk.io/x/upgrade/plan" + "cosmossdk.io/x/upgrade/types" ) const ( @@ -27,22 +27,22 @@ const ( ) // GetTxCmd returns the transaction commands for this module -func GetTxCmd() *cobra.Command { +func GetTxCmd(ac addresscodec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, Short: "Upgrade transaction subcommands", } cmd.AddCommand( - NewCmdSubmitUpgradeProposal(), - NewCmdSubmitCancelUpgradeProposal(), + NewCmdSubmitUpgradeProposal(ac), + NewCmdSubmitCancelUpgradeProposal(ac), ) return cmd } // NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. -func NewCmdSubmitUpgradeProposal() *cobra.Command { +func NewCmdSubmitUpgradeProposal(ac addresscodec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "software-upgrade [name] (--upgrade-height [height]) (--upgrade-info [info]) [flags]", Args: cobra.ExactArgs(1), @@ -89,7 +89,7 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command { authority, _ := cmd.Flags().GetString(FlagAuthority) if authority != "" { - if _, err = sdk.AccAddressFromBech32(authority); err != nil { + if _, err = ac.StringToBytes(authority); err != nil { return fmt.Errorf("invalid authority address: %w", err) } } else { @@ -124,7 +124,7 @@ func NewCmdSubmitUpgradeProposal() *cobra.Command { } // NewCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. -func NewCmdSubmitCancelUpgradeProposal() *cobra.Command { +func NewCmdSubmitCancelUpgradeProposal(ac addresscodec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "cancel-software-upgrade [flags]", Args: cobra.ExactArgs(0), @@ -143,7 +143,7 @@ func NewCmdSubmitCancelUpgradeProposal() *cobra.Command { authority, _ := cmd.Flags().GetString(FlagAuthority) if authority != "" { - if _, err = sdk.AccAddressFromBech32(authority); err != nil { + if _, err = ac.StringToBytes(authority); err != nil { return fmt.Errorf("invalid authority address: %w", err) } } else { diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 298fe6f1f0..4a2fbf353f 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -44,7 +45,9 @@ const ConsensusVersion uint64 = 2 var _ module.AppModuleBasic = AppModuleBasic{} // AppModuleBasic implements the sdk.AppModuleBasic interface -type AppModuleBasic struct{} +type AppModuleBasic struct { + ac address.Codec +} // Name returns the ModuleName func (AppModuleBasic) Name() string { @@ -69,8 +72,8 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { } // GetTxCmd returns the CLI transaction commands for this module -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.GetTxCmd() +func (ab AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd(ab.ac) } // RegisterInterfaces registers interfaces and implementations of the upgrade module. @@ -82,12 +85,13 @@ func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry type AppModule struct { AppModuleBasic keeper *keeper.Keeper + ac address.Codec } // NewAppModule creates a new AppModule object -func NewAppModule(keeper *keeper.Keeper) AppModule { +func NewAppModule(keeper *keeper.Keeper, ac address.Codec) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{}, + AppModuleBasic: AppModuleBasic{ac: ac}, keeper: keeper, } } @@ -174,9 +178,10 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - Key *store.KVStoreKey - Cdc codec.Codec + Config *modulev1.Module + Key *store.KVStoreKey + Cdc codec.Codec + AddressCodec address.Codec AppOpts servertypes.AppOptions `optional:"true"` } @@ -215,7 +220,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { baseappOpt := func(app *baseapp.BaseApp) { k.SetVersionSetter(app) } - m := NewAppModule(k) + m := NewAppModule(k, in.AddressCodec) gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} return ModuleOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt}