chore(upgrade): clean up handler and typo (#16845)

This commit is contained in:
Julien Robert 2023-07-06 18:35:04 +02:00 committed by GitHub
parent 57ee5a23d9
commit d9800d9c75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 178 deletions

View File

@ -370,8 +370,7 @@ func NewSimApp(
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:

View File

@ -32,6 +32,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* [#16845](https://github.com/cosmos/cosmos-sdk/pull/16845) Remove gov v1beta1 handler. Use gov v1 proposals directly, or replicate the handler in your app.
* [#16511](https://github.com/cosmos/cosmos-sdk/pull/16511) `BinaryDownloadURLMap.ValidateBasic()` and `BinaryDownloadURLMap.CheckURLs` now both take a checksum parameter when willing to ensure a checksum is provided for each URL.
* [#16511](https://github.com/cosmos/cosmos-sdk/pull/16511) `plan.DownloadURLWithChecksum` has been renamed to `plan.DownloadURL` and does not validate the URL anymore. Call `plan.ValidateURL` before calling `plan.DownloadURL` to validate the URL.
* [#16511](https://github.com/cosmos/cosmos-sdk/pull/16511) `plan.DownloadUpgrade` does not validate URL anymore. Call `plan.ValidateURL` before calling `plan.DownloadUpgrade` to validate the URL.

View File

@ -28,7 +28,6 @@ import (
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
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"
)
type TestSuite struct {
@ -36,16 +35,83 @@ type TestSuite struct {
module appmodule.HasBeginBlocker
keeper *keeper.Keeper
handler govtypesv1beta1.Handler
ctx sdk.Context
baseApp *baseapp.BaseApp
encCfg moduletestutil.TestEncodingConfig
}
var s TestSuite
func (s *TestSuite) VerifyDoUpgrade(t *testing.T) {
t.Helper()
t.Log("Verify that a panic happens at the upgrade height")
newCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1, Time: time.Now()})
err := s.module.BeginBlock(newCtx)
require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height: 11: ")
t.Log("Verify that the upgrade can be successfully applied with a handler")
s.keeper.SetUpgradeHandler("test", func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
err = s.module.BeginBlock(newCtx)
require.NoError(t, err)
s.VerifyCleared(t, newCtx)
}
func (s *TestSuite) VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName string) {
t.Helper()
t.Log("Verify that a panic happens at the upgrade height")
err := s.module.BeginBlock(newCtx)
require.ErrorContains(t, err, "UPGRADE \""+proposalName+"\" NEEDED at height: ")
t.Log("Verify that the upgrade can be successfully applied with a handler")
s.keeper.SetUpgradeHandler(proposalName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
err = s.module.BeginBlock(newCtx)
require.NoError(t, err)
s.VerifyCleared(t, newCtx)
}
func (s *TestSuite) VerifyCleared(t *testing.T, newCtx sdk.Context) {
t.Helper()
t.Log("Verify that the upgrade plan has been cleared")
_, err := s.keeper.GetUpgradePlan(newCtx)
require.ErrorIs(t, err, types.ErrNoUpgradePlanFound)
}
func (s *TestSuite) VerifyNotDone(t *testing.T, newCtx sdk.Context, name string) {
t.Helper()
t.Log("Verify that upgrade was not done")
height, err := s.keeper.GetDoneHeight(newCtx, name)
require.Zero(t, height)
require.NoError(t, err)
}
func (s *TestSuite) VerifyDone(t *testing.T, newCtx sdk.Context, name string) {
t.Helper()
t.Log("Verify that the upgrade plan has been executed")
height, err := s.keeper.GetDoneHeight(newCtx, name)
require.NotZero(t, height)
require.NoError(t, err)
}
func (s *TestSuite) VerifySet(t *testing.T, skipUpgradeHeights map[int64]bool) {
t.Helper()
t.Log("Verify if the skip upgrade has been set")
for k := range skipUpgradeHeights {
require.True(t, s.keeper.IsSkipHeight(k))
}
}
func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite {
t.Helper()
s := TestSuite{}
s.encCfg = moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
@ -64,21 +130,12 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite {
s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now(), Height: height})
s.module = upgrade.NewAppModule(s.keeper, addresscodec.NewBech32Codec("cosmos"))
s.handler = upgrade.NewSoftwareUpgradeProposalHandler(s.keeper)
return &s
}
func TestRequireName(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{}}) //nolint:staticcheck // we're testing deprecated code
require.Error(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}
func TestRequireFutureBlock(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height - 1}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height - 1})
require.Error(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}
@ -86,58 +143,21 @@ func TestRequireFutureBlock(t *testing.T) {
func TestDoHeightUpgrade(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
t.Log("Verify can schedule an upgrade")
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1})
require.NoError(t, err)
VerifyDoUpgrade(t)
s.VerifyDoUpgrade(t)
}
func TestCanOverwriteScheduleUpgrade(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
t.Log("Can overwrite plan")
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "bad_test", Height: s.ctx.HeaderInfo().Height + 10}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "bad_test", Height: s.ctx.HeaderInfo().Height + 10})
require.NoError(t, err)
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1})
require.NoError(t, err)
VerifyDoUpgrade(t)
}
func VerifyDoUpgrade(t *testing.T) {
t.Helper()
t.Log("Verify that a panic happens at the upgrade height")
newCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1, Time: time.Now()})
err := s.module.BeginBlock(newCtx)
require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height: 11: ")
t.Log("Verify that the upgrade can be successfully applied with a handler")
s.keeper.SetUpgradeHandler("test", func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
err = s.module.BeginBlock(newCtx)
require.NoError(t, err)
VerifyCleared(t, newCtx)
}
func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName string) {
t.Helper()
t.Log("Verify that a panic happens at the upgrade height")
err := s.module.BeginBlock(newCtx)
require.ErrorContains(t, err, "UPGRADE \""+proposalName+"\" NEEDED at height: ")
t.Log("Verify that the upgrade can be successfully applied with a handler")
s.keeper.SetUpgradeHandler(proposalName, func(ctx context.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
err = s.module.BeginBlock(newCtx)
require.NoError(t, err)
VerifyCleared(t, newCtx)
s.VerifyDoUpgrade(t)
}
func TestHaltIfTooNew(t *testing.T) {
@ -156,7 +176,7 @@ func TestHaltIfTooNew(t *testing.T) {
require.Equal(t, 0, called)
t.Log("Verify we error if we have a registered handler ahead of time")
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "future", Height: s.ctx.HeaderInfo().Height + 3}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "future", Height: s.ctx.HeaderInfo().Height + 3})
require.NoError(t, err)
err = s.module.BeginBlock(newCtx)
@ -170,36 +190,29 @@ func TestHaltIfTooNew(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, called)
VerifyCleared(t, futCtx)
}
func VerifyCleared(t *testing.T, newCtx sdk.Context) {
t.Helper()
t.Log("Verify that the upgrade plan has been cleared")
_, err := s.keeper.GetUpgradePlan(newCtx)
require.ErrorIs(t, err, types.ErrNoUpgradePlanFound)
s.VerifyCleared(t, futCtx)
}
func TestCanClear(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
t.Log("Verify upgrade is scheduled")
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 100}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 100})
require.NoError(t, err)
err = s.handler(s.ctx, &types.CancelSoftwareUpgradeProposal{Title: "cancel"}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ClearUpgradePlan(s.ctx)
require.NoError(t, err)
VerifyCleared(t, s.ctx)
s.VerifyCleared(t, s.ctx)
}
func TestCantApplySameUpgradeTwice(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
height := s.ctx.HeaderInfo().Height + 1
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: height}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: height})
require.NoError(t, err)
VerifyDoUpgrade(t)
s.VerifyDoUpgrade(t)
t.Log("Verify an executed upgrade \"test\" can't be rescheduled")
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: height}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: height})
require.Error(t, err)
require.True(t, errors.Is(sdkerrors.ErrInvalidRequest, err), err)
}
@ -216,36 +229,11 @@ func TestPlanStringer(t *testing.T) {
require.Equal(t, `name:"test" time:<seconds:-62135596800 > height:100 `, (&types.Plan{Name: "test", Height: 100, Info: ""}).String())
}
func VerifyNotDone(t *testing.T, newCtx sdk.Context, name string) {
t.Helper()
t.Log("Verify that upgrade was not done")
height, err := s.keeper.GetDoneHeight(newCtx, name)
require.Zero(t, height)
require.NoError(t, err)
}
func VerifyDone(t *testing.T, newCtx sdk.Context, name string) {
t.Helper()
t.Log("Verify that the upgrade plan has been executed")
height, err := s.keeper.GetDoneHeight(newCtx, name)
require.NotZero(t, height)
require.NoError(t, err)
}
func VerifySet(t *testing.T, skipUpgradeHeights map[int64]bool) {
t.Helper()
t.Log("Verify if the skip upgrade has been set")
for k := range skipUpgradeHeights {
require.True(t, s.keeper.IsSkipHeight(k))
}
}
func TestContains(t *testing.T) {
var skipOne int64 = 11
s := setupTest(t, 10, map[int64]bool{skipOne: true})
VerifySet(t, map[int64]bool{skipOne: true})
s.VerifySet(t, map[int64]bool{skipOne: true})
t.Log("case where array contains the element")
require.True(t, s.keeper.IsSkipHeight(11))
@ -262,18 +250,18 @@ func TestSkipUpgradeSkippingAll(t *testing.T) {
newCtx := s.ctx
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: skipOne}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: skipOne})
require.NoError(t, err)
t.Log("Verify if skip upgrade flag clears upgrade plan in both cases")
VerifySet(t, map[int64]bool{skipOne: true, skipTwo: true})
s.VerifySet(t, map[int64]bool{skipOne: true, skipTwo: true})
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipOne})
err = s.module.BeginBlock(newCtx)
require.NoError(t, err)
t.Log("Verify a second proposal also is being cleared")
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop2", Plan: types.Plan{Name: "test2", Height: skipTwo}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test2", Height: skipTwo})
require.NoError(t, err)
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipTwo})
@ -282,9 +270,9 @@ func TestSkipUpgradeSkippingAll(t *testing.T) {
// To ensure verification is being done only after both upgrades are cleared
t.Log("Verify if both proposals are cleared")
VerifyCleared(t, s.ctx)
VerifyNotDone(t, s.ctx, "test")
VerifyNotDone(t, s.ctx, "test2")
s.VerifyCleared(t, s.ctx)
s.VerifyNotDone(t, s.ctx, "test")
s.VerifyNotDone(t, s.ctx, "test2")
}
func TestUpgradeSkippingOne(t *testing.T) {
@ -296,11 +284,11 @@ func TestUpgradeSkippingOne(t *testing.T) {
newCtx := s.ctx
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: skipOne}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: skipOne})
require.NoError(t, err)
t.Log("Verify if skip upgrade flag clears upgrade plan in one case and does upgrade on another")
VerifySet(t, map[int64]bool{skipOne: true})
s.VerifySet(t, map[int64]bool{skipOne: true})
// Setting block height of proposal test
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipOne})
@ -308,15 +296,15 @@ func TestUpgradeSkippingOne(t *testing.T) {
require.NoError(t, err)
t.Log("Verify the second proposal is not skipped")
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop2", Plan: types.Plan{Name: "test2", Height: skipTwo}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test2", Height: skipTwo})
require.NoError(t, err)
// Setting block height of proposal test2
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipTwo})
VerifyDoUpgradeWithCtx(t, newCtx, "test2")
s.VerifyDoUpgradeWithCtx(t, newCtx, "test2")
t.Log("Verify first proposal is cleared and second is done")
VerifyNotDone(t, s.ctx, "test")
VerifyDone(t, s.ctx, "test2")
s.VerifyNotDone(t, s.ctx, "test")
s.VerifyDone(t, s.ctx, "test2")
}
func TestUpgradeSkippingOnlyTwo(t *testing.T) {
@ -329,11 +317,11 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) {
newCtx := s.ctx
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: skipOne}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: skipOne})
require.NoError(t, err)
t.Log("Verify if skip upgrade flag clears upgrade plan in both cases and does third upgrade")
VerifySet(t, map[int64]bool{skipOne: true, skipTwo: true})
s.VerifySet(t, map[int64]bool{skipOne: true, skipTwo: true})
// Setting block height of proposal test
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipOne})
@ -341,7 +329,7 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) {
require.NoError(t, err)
// A new proposal with height in skipUpgradeHeights
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop2", Plan: types.Plan{Name: "test2", Height: skipTwo}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test2", Height: skipTwo})
require.NoError(t, err)
// Setting block height of proposal test2
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipTwo})
@ -349,29 +337,29 @@ func TestUpgradeSkippingOnlyTwo(t *testing.T) {
require.NoError(t, err)
t.Log("Verify a new proposal is not skipped")
err = s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop3", Plan: types.Plan{Name: "test3", Height: skipThree}}) //nolint:staticcheck // we're testing deprecated code
err = s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test3", Height: skipThree})
require.NoError(t, err)
newCtx = newCtx.WithHeaderInfo(header.Info{Height: skipThree})
VerifyDoUpgradeWithCtx(t, newCtx, "test3")
s.VerifyDoUpgradeWithCtx(t, newCtx, "test3")
t.Log("Verify two proposals are cleared and third is done")
VerifyNotDone(t, s.ctx, "test")
VerifyNotDone(t, s.ctx, "test2")
VerifyDone(t, s.ctx, "test3")
s.VerifyNotDone(t, s.ctx, "test")
s.VerifyNotDone(t, s.ctx, "test2")
s.VerifyDone(t, s.ctx, "test3")
}
func TestUpgradeWithoutSkip(t *testing.T) {
s := setupTest(t, 10, map[int64]bool{})
newCtx := s.ctx.WithHeaderInfo(header.Info{Height: s.ctx.HeaderInfo().Height + 1, Time: time.Now()})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "prop", Plan: types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test", Height: s.ctx.HeaderInfo().Height + 1})
require.NoError(t, err)
t.Log("Verify if upgrade happens without skip upgrade")
err = s.module.BeginBlock(newCtx)
require.ErrorContains(t, err, "UPGRADE \"test\" NEEDED at height:")
VerifyDoUpgrade(t)
VerifyDone(t, s.ctx, "test")
s.VerifyDoUpgrade(t)
s.VerifyDone(t, s.ctx, "test")
}
func TestDumpUpgradeInfoToFile(t *testing.T) {
@ -429,7 +417,7 @@ func TestBinaryVersion(t *testing.T) {
return vm, nil
})
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "Upgrade test", Plan: types.Plan{Name: "test0", Height: s.ctx.HeaderInfo().Height + 2}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test0", Height: s.ctx.HeaderInfo().Height + 2})
require.NoError(t, err)
newCtx := s.ctx.WithHeaderInfo(header.Info{Height: 12})
@ -445,7 +433,7 @@ func TestBinaryVersion(t *testing.T) {
{
"test panic: upgrade needed",
func() sdk.Context {
err := s.handler(s.ctx, &types.SoftwareUpgradeProposal{Title: "Upgrade test", Plan: types.Plan{Name: "test2", Height: 13}}) //nolint:staticcheck // we're testing deprecated code
err := s.keeper.ScheduleUpgrade(s.ctx, types.Plan{Name: "test2", Height: 13})
require.NoError(t, err)
newCtx := s.ctx.WithHeaderInfo(header.Info{Height: 13})
@ -472,18 +460,16 @@ func TestDowngradeVerification(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig(upgrade.AppModuleBasic{})
key := storetypes.NewKVStoreKey(types.StoreKey)
storeService := runtime.NewKVStoreService(key)
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now(), Height: 10})
skip := map[int64]bool{}
tempDir := t.TempDir()
k := keeper.NewKeeper(skip, storeService, encCfg.Codec, tempDir, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
k := keeper.NewKeeper(skip, storeService, encCfg.Codec, t.TempDir(), nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
m := upgrade.NewAppModule(k, addresscodec.NewBech32Codec("cosmos"))
handler := upgrade.NewSoftwareUpgradeProposalHandler(k)
// submit a plan.
planName := "downgrade"
err := handler(ctx, &types.SoftwareUpgradeProposal{Title: "test", Plan: types.Plan{Name: planName, Height: ctx.HeaderInfo().Height + 1}}) //nolint:staticcheck // we're testing deprecated code
err := k.ScheduleUpgrade(ctx, types.Plan{Name: planName, Height: ctx.HeaderInfo().Height + 1})
require.NoError(t, err)
ctx = ctx.WithHeaderInfo(header.Info{Height: ctx.HeaderInfo().Height + 1})
@ -509,8 +495,7 @@ func TestDowngradeVerification(t *testing.T) {
},
"downgrade with an active plan": {
preRun: func(k *keeper.Keeper, ctx sdk.Context, name string) {
handler := upgrade.NewSoftwareUpgradeProposalHandler(k)
err := handler(ctx, &types.SoftwareUpgradeProposal{Title: "test", Plan: types.Plan{Name: "another" + planName, Height: ctx.HeaderInfo().Height + 1}}) //nolint:staticcheck // we're testing deprecated code
err := k.ScheduleUpgrade(ctx, types.Plan{Name: "another" + planName, Height: ctx.HeaderInfo().Height + 1})
require.NoError(t, err, name)
},
expectError: true,
@ -524,7 +509,7 @@ func TestDowngradeVerification(t *testing.T) {
ctx, _ := ctx.CacheContext()
// downgrade. now keeper does not have the handler.
k := keeper.NewKeeper(skip, storeService, encCfg.Codec, tempDir, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
k := keeper.NewKeeper(skip, storeService, encCfg.Codec, t.TempDir(), nil, authtypes.NewModuleAddress(govtypes.ModuleName).String())
m := upgrade.NewAppModule(k, addresscodec.NewBech32Codec("cosmos"))
// assertions

View File

@ -110,7 +110,7 @@ func NewCmdSubmitUpgradeProposal(ac addresscodec.Codec) *cobra.Command {
Plan: p,
},
}); err != nil {
return fmt.Errorf("failed to create cancel upgrade message: %w", err)
return fmt.Errorf("failed to create submit upgrade proposal message: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal)
@ -164,7 +164,7 @@ func NewCmdSubmitCancelUpgradeProposal(ac addresscodec.Codec) *cobra.Command {
Authority: authority,
},
}); err != nil {
return fmt.Errorf("failed to create cancel upgrade message: %w", err)
return fmt.Errorf("failed to create cancel upgrade proposal message: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal)

View File

@ -1,41 +0,0 @@
package upgrade
import (
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/x/upgrade/keeper"
"cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
// NewSoftwareUpgradeProposalHandler creates a governance handler to manage new proposal types.
// It enables SoftwareUpgradeProposal to propose an Upgrade, and CancelSoftwareUpgradeProposal
// to abort a previously voted upgrade.
//
//nolint:staticcheck // we are intentionally using a deprecated proposal here.
func NewSoftwareUpgradeProposalHandler(k *keeper.Keeper) govtypes.Handler {
return func(ctx sdk.Context, content govtypes.Content) error {
switch c := content.(type) {
case *types.SoftwareUpgradeProposal:
return handleSoftwareUpgradeProposal(ctx, k, c)
case *types.CancelSoftwareUpgradeProposal:
return handleCancelSoftwareUpgradeProposal(ctx, k, c)
default:
return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized software upgrade proposal content type: %T", c)
}
}
}
//nolint:staticcheck // we are intentionally using a deprecated proposal here.
func handleSoftwareUpgradeProposal(ctx sdk.Context, k *keeper.Keeper, p *types.SoftwareUpgradeProposal) error {
return k.ScheduleUpgrade(ctx, p.Plan)
}
//nolint:staticcheck // we are intentionally using a deprecated proposal here.
func handleCancelSoftwareUpgradeProposal(ctx sdk.Context, k *keeper.Keeper, _ *types.CancelSoftwareUpgradeProposal) error {
return k.ClearUpgradePlan(ctx)
}

View File

@ -31,7 +31,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
func init() {
@ -195,7 +194,6 @@ type ModuleOutputs struct {
UpgradeKeeper *keeper.Keeper
Module appmodule.AppModule
GovHandler govv1beta1.HandlerRoute
BaseAppOption runtime.BaseAppOption
}
@ -225,9 +223,8 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
k.SetVersionSetter(app)
}
m := NewAppModule(k, in.AddressCodec)
gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)}
return ModuleOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt}
return ModuleOutputs{UpgradeKeeper: k, Module: m, BaseAppOption: baseappOpt}
}
func PopulateVersionMap(upgradeKeeper *keeper.Keeper, modules map[string]appmodule.AppModule) {