Skip to content

Commit

Permalink
fix: unit for upgrade module
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jan 5, 2023
1 parent 87a6529 commit 4bc8b48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions x/upgrade/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestHaltIfTooNew(t *testing.T) {
called++
return vm, nil
})
s.keeper.SetUpgradeInitializer("future", func() error { return nil })

newCtx := s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1).WithBlockTime(time.Now())
req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()}
Expand Down Expand Up @@ -201,6 +202,7 @@ func TestUpgrade(t *testing.T) {
s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
s.keeper.SetUpgradeInitializer("test", func() error { return nil })
require.NoError(t, err)
t.Log("Verify if upgrade happens without skip upgrade")
require.NotPanics(t, func() {
Expand Down
3 changes: 3 additions & 0 deletions x/upgrade/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() {
suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
suite.app.UpgradeKeeper.SetUpgradeInitializer(planName, func() error {
return nil
})
suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan)

req = &types.QueryAppliedPlanRequest{Name: planName}
Expand Down
6 changes: 6 additions & 0 deletions x/upgrade/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() {
s.app.UpgradeKeeper.SetUpgradeHandler("all-good", func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
s.app.UpgradeKeeper.SetUpgradeInitializer("all-good", func() error { return nil })
s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{
Name: "all-good",
Info: "some text here",
Expand Down Expand Up @@ -210,6 +211,7 @@ func (s *KeeperTestSuite) TestMigrations() {
vm["bank"] = vm["bank"] + 1
return vm, nil
})
s.app.UpgradeKeeper.SetUpgradeInitializer("dummy", func() error { return nil })
dummyPlan := types.Plan{
Name: "dummy",
Info: "some text here",
Expand All @@ -233,6 +235,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() {
keeper.SetUpgradeHandler("test0", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
keeper.SetUpgradeInitializer("test0", func() error { return nil })

keeper.ApplyUpgrade(s.ctx, types.Plan{
Name: "test0",
Expand All @@ -247,6 +250,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgrade() {
keeper.SetUpgradeHandler("test1", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
keeper.SetUpgradeInitializer("test1", func() error { return nil })

newCtx := s.ctx.WithBlockHeight(15)
keeper.ApplyUpgrade(newCtx, types.Plan{
Expand All @@ -270,6 +274,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() {
keeper.SetUpgradeHandler("test-v0.9", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
keeper.SetUpgradeInitializer("test-v0.9", func() error { return nil })

keeper.ApplyUpgrade(s.ctx, types.Plan{
Name: "test-v0.9",
Expand All @@ -284,6 +289,7 @@ func (s *KeeperTestSuite) TestLastCompletedUpgradeOrdering() {
keeper.SetUpgradeHandler("test-v0.10", func(_ sdk.Context, _ types.Plan, vm module.VersionMap) (module.VersionMap, error) {
return vm, nil
})
keeper.SetUpgradeInitializer("test-v0.10", func() error { return nil })

newCtx := s.ctx.WithBlockHeight(15)
keeper.ApplyUpgrade(newCtx, types.Plan{
Expand Down

0 comments on commit 4bc8b48

Please sign in to comment.