From b7fbe42e54506bad9b4d1b54681403a1a11c0e08 Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Tue, 4 Oct 2022 16:25:37 +0200 Subject: [PATCH 1/3] split ExportGenesis into two functions to maintain backwards compatibility (#339) --- simapp/export.go | 2 +- types/module/module.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/simapp/export.go b/simapp/export.go index 60aecc5a05b0..8d53fd1dfd35 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -28,7 +28,7 @@ func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAd app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) } - genState := app.ModuleManager.ExportGenesis(ctx, app.appCodec, modulesToExport) + genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport) appState, err := json.MarshalIndent(genState, "", " ") if err != nil { return servertypes.ExportedApp{}, err diff --git a/types/module/module.go b/types/module/module.go index f693e0824b17..45356e239915 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -320,7 +320,12 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData } // ExportGenesis performs export genesis functionality for modules -func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec, modulesToExport []string) map[string]json.RawMessage { +func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string]json.RawMessage { + return m.ExportGenesisForModules(ctx, cdc, []string{}) +} + +// ExportGenesisForModules performs export genesis functionality for modules +func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, modulesToExport []string) map[string]json.RawMessage { genesisData := make(map[string]json.RawMessage) if len(modulesToExport) == 0 { for _, moduleName := range m.OrderExportGenesis { From d1e5d5adbe93cc02f9c1d810b11957dc5df310bd Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 5 Oct 2022 00:15:11 +0200 Subject: [PATCH 2/3] fix tests --- CHANGELOG.md | 2 +- UPGRADING.md | 2 +- simapp/export.go | 2 +- types/module/module_test.go | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37d4f1654db0..31dbe3deacb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,7 +98,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* [#13437](https://github.com/cosmos/cosmos-sdk/pull/13437) Add a list of modules to export argument in `ExportAppStateAndValidators` and `ExportGenesis`. +* [#13437](https://github.com/cosmos/cosmos-sdk/pull/13437) Add a list of modules to export argument in `ExportAppStateAndValidators`. * (x/slashing) [#13427](https://github.com/cosmos/cosmos-sdk/pull/13427) Move `x/slashing/testslashing` to `x/slashing/testutil` for consistency with other modules. * (x/staking) [#13427](https://github.com/cosmos/cosmos-sdk/pull/13427) Move `x/staking/teststaking` to `x/staking/testutil` for consistency with other modules. * (simapp) [#13402](https://github.com/cosmos/cosmos-sdk/pull/13402) Move simulation flags to `x/simulation/client/cli`. diff --git a/UPGRADING.md b/UPGRADING.md index e086c4bdc30c..8821f85e1972 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -37,7 +37,7 @@ This means you can replace your usage of `simapp.MakeTestEncodingConfig` in test #### Export `ExportAppStateAndValidators` takes an extra argument, `modulesToExport`, which is a list of module names to export. -That argument should be passed to the module maanager `ExportGenesis` method. +That argument should be passed to the module maanager `ExportGenesisFromModules` method. ### Protobuf diff --git a/simapp/export.go b/simapp/export.go index 8d53fd1dfd35..96e841064a5a 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -28,7 +28,7 @@ func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAd app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) } - genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport) + genState := app.ModuleManager.ExportGenesisForModules(ctx, app.appCodec, modulesToExport) appState, err := json.MarshalIndent(genState, "", " ") if err != nil { return servertypes.ExportedApp{}, err diff --git a/types/module/module_test.go b/types/module/module_test.go index c8be39e32068..f3808dd2767d 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -198,10 +198,11 @@ func TestManager_ExportGenesis(t *testing.T) { "module1": json.RawMessage(`{"key1": "value1"}`), "module2": json.RawMessage(`{"key2": "value2"}`), } - require.Equal(t, want, mm.ExportGenesis(ctx, cdc, []string{})) + require.Equal(t, want, mm.ExportGenesis(ctx, cdc)) + require.Equal(t, want, mm.ExportGenesisForModules(ctx, cdc, []string{})) require.Panics(t, func() { - mm.ExportGenesis(ctx, cdc, []string{"module1", "modulefoo"}) + mm.ExportGenesisForModules(ctx, cdc, []string{"module1", "modulefoo"}) }) } From f144b722470a76ff4c2bf9afb98bbef98af9ddaf Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 5 Oct 2022 00:28:07 +0200 Subject: [PATCH 3/3] anytime --- types/module/module_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/module/module_test.go b/types/module/module_test.go index f3808dd2767d..dd6ad46b88e8 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -191,8 +191,8 @@ func TestManager_ExportGenesis(t *testing.T) { ctx := sdk.Context{} interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - mockAppModule1.EXPECT().ExportGenesis(gomock.Eq(ctx), gomock.Eq(cdc)).Times(1).Return(json.RawMessage(`{"key1": "value1"}`)) - mockAppModule2.EXPECT().ExportGenesis(gomock.Eq(ctx), gomock.Eq(cdc)).Times(1).Return(json.RawMessage(`{"key2": "value2"}`)) + mockAppModule1.EXPECT().ExportGenesis(gomock.Eq(ctx), gomock.Eq(cdc)).AnyTimes().Return(json.RawMessage(`{"key1": "value1"}`)) + mockAppModule2.EXPECT().ExportGenesis(gomock.Eq(ctx), gomock.Eq(cdc)).AnyTimes().Return(json.RawMessage(`{"key2": "value2"}`)) want := map[string]json.RawMessage{ "module1": json.RawMessage(`{"key1": "value1"}`),