fix: handle RunMigrationBeginBlock error (#17372)
This commit is contained in:
@@ -701,16 +701,17 @@ func (m Manager) RunMigrations(ctx context.Context, cfg Configurator, fromVM Ver
|
||||
|
||||
// RunMigrationBeginBlock performs begin block functionality for upgrade module.
|
||||
// It takes the current context as a parameter and returns a boolean value
|
||||
// indicating whether the migration was successfully executed or not.
|
||||
func (m *Manager) RunMigrationBeginBlock(ctx sdk.Context) bool {
|
||||
// indicating whether the migration was executed or not and an error if fails.
|
||||
func (m *Manager) RunMigrationBeginBlock(ctx sdk.Context) (bool, error) {
|
||||
for _, moduleName := range m.OrderBeginBlockers {
|
||||
if mod, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok {
|
||||
if _, ok := mod.(UpgradeModule); ok {
|
||||
return mod.BeginBlock(ctx) == nil
|
||||
err := mod.BeginBlock(ctx)
|
||||
return err == nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// BeginBlock performs begin block functionality for non-upgrade modules. It creates a
|
||||
|
||||
@@ -482,16 +482,20 @@ func TestCoreAPIManager_RunMigrationBeginBlock(t *testing.T) {
|
||||
|
||||
mockAppModule1.EXPECT().BeginBlock(gomock.Any()).Times(0)
|
||||
mockAppModule2.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(nil)
|
||||
success := mm.RunMigrationBeginBlock(sdk.Context{})
|
||||
success, err := mm.RunMigrationBeginBlock(sdk.Context{})
|
||||
require.Equal(t, true, success)
|
||||
require.NoError(t, err)
|
||||
|
||||
// test false
|
||||
require.Equal(t, false, module.NewManager().RunMigrationBeginBlock(sdk.Context{}))
|
||||
success, err = module.NewManager().RunMigrationBeginBlock(sdk.Context{})
|
||||
require.Equal(t, false, success)
|
||||
require.NoError(t, err)
|
||||
|
||||
// test panic
|
||||
mockAppModule2.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(errors.New("some error"))
|
||||
success = mm.RunMigrationBeginBlock(sdk.Context{})
|
||||
success, err = mm.RunMigrationBeginBlock(sdk.Context{})
|
||||
require.Equal(t, false, success)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestCoreAPIManager_BeginBlock(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user