|
|
|
|
@ -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,15 +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)
|
|
|
|
|
@ -63,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)
|
|
|
|
|
}
|
|
|
|
|
@ -85,56 +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.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.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) {
|
|
|
|
|
@ -153,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)
|
|
|
|
|
@ -167,35 +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.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)
|
|
|
|
|
}
|
|
|
|
|
@ -212,33 +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.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.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.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))
|
|
|
|
|
|
|
|
|
|
@ -255,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})
|
|
|
|
|
@ -275,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) {
|
|
|
|
|
@ -289,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})
|
|
|
|
|
@ -301,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) {
|
|
|
|
|
@ -322,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})
|
|
|
|
|
@ -334,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})
|
|
|
|
|
@ -342,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) {
|
|
|
|
|
@ -422,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})
|
|
|
|
|
@ -438,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})
|
|
|
|
|
@ -465,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})
|
|
|
|
|
|
|
|
|
|
@ -502,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,
|
|
|
|
|
@ -517,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
|
|
|
|
|
|