refactor: split ExportGenesis into two functions to maintain backwards compatibility (#13448)
* split ExportGenesis into two functions to maintain backwards compatibility (#339) * fix tests Co-authored-by: Nicolas Lara <nicolaslara@gmail.com>
This commit is contained in:
co-authored by
Nicolas Lara
parent
c3887986ff
commit
facac1c5f8
@@ -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 {
|
||||
|
||||
@@ -191,17 +191,18 @@ 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"}`),
|
||||
"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"})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user