diff --git a/CHANGELOG.md b/CHANGELOG.md index ee24877e843c..04f2c186cd9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ A SendEnabled query has been added to both GRPC and CLI. * (appModule) Remove `Route`, `QuerierRoute` and `LegacyQuerierHandler` from AppModule Interface. * (x/modules) Remove all LegacyQueries and related code from modules +* (x/modules) [\#12700](https://github.com/cosmos/cosmos-sdk/pull/12700) Change genesis state type from `json.RawMessage` to `proto.Message` in `DefaultGenesis`, `InitGenesis` and `ExportGenesis` functions. ### CLI Breaking Changes diff --git a/UPGRADING.md b/UPGRADING.md index 2af7041ee495..78880e8ef8d6 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -8,7 +8,9 @@ This guide provides instructions for upgrading to specific versions of Cosmos SD Remove `Querier`, `Route` and `LegacyQuerier` from the app module interface. This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously known as the LCD, and the `sdk.Msg#Route` method won't be used anymore. - +* `AppModuleBasic`'s `DefaultGenesis` does not take any inputs and returns the default genesis state as `proto.Message` (instead of `json.RawMessage`). +* `AppModuleGenesis`s `InitGenesis` does not require a codec as input and takes the genesis state as `proto.Message`. +* `AppModuleGenesis`s `ExportGenesis` does not require a codec as input and returns the genesis state as `proto.Message`. ### SimApp diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 815fff51fc4b..89151f39deaf 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -109,8 +108,9 @@ func TestBaseApp_BlockGas(t *testing.T) { &testdata.TestMsg{}, ) genState := GenesisStateWithSingleValidator(t, cdc, appBuilder) - stateBytes, err := tmjson.MarshalIndent(genState, "", " ") + stateBytes, err := sdk.MarshalGenesisStateToJSON(genState, cdc, true) require.NoError(t, err) + bapp.InitChain(abci.RequestInitChain{ Validators: []abci.ValidatorUpdate{}, ConsensusParams: simtestutil.DefaultConsensusParams, diff --git a/baseapp/util_test.go b/baseapp/util_test.go index 6ffa983c6314..7a2867100cbc 100644 --- a/baseapp/util_test.go +++ b/baseapp/util_test.go @@ -2,9 +2,9 @@ package baseapp_test import ( "context" - "encoding/json" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" tmtypes "github.com/tendermint/tendermint/types" @@ -38,7 +38,7 @@ import ( // GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts // that also act as delegators. -func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]json.RawMessage { +func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *runtime.AppBuilder) map[string]proto.Message { t.Helper() privVal := mock.NewPV() diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index b0b2b0afbcfe..0b75d5ab87b2 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -73,7 +72,7 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState, err := sims.GenesisStateWithValSet(cdc, appBuilder.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance) s.NoError(err) - stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, cdc, true) s.NoError(err) // init chain will set the validator set and initialize the genesis accounts diff --git a/runtime/builder.go b/runtime/builder.go index f73805c17cac..1ad807d25b09 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -1,9 +1,9 @@ package runtime import ( - "encoding/json" "io" + "github.com/gogo/protobuf/proto" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -20,8 +20,8 @@ type AppBuilder struct { // DefaultGenesis returns a default genesis from the registered // AppModuleBasic's. -func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage { - return a.app.basicManager.DefaultGenesis(a.app.cdc) +func (a *AppBuilder) DefaultGenesis() map[string]proto.Message { + return a.app.basicManager.DefaultGenesis() } // Build builds an *App instance. diff --git a/simapp/app_legacy.go b/simapp/app_legacy.go index 0ec50e6468fd..38de9db17e4f 100644 --- a/simapp/app_legacy.go +++ b/simapp/app_legacy.go @@ -534,7 +534,7 @@ func (a *SimApp) Configurator() module.Configurator { // InitChainer application update at chain initialization func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - var genesisState GenesisState + var genesisState map[string]json.RawMessage if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) } diff --git a/simapp/app_test.go b/simapp/app_test.go index 3c6a451216bf..dce27d25197d 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -1,7 +1,6 @@ package simapp import ( - "encoding/json" "testing" "github.com/golang/mock/gomock" @@ -14,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/tests/mocks" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" @@ -210,9 +210,10 @@ func TestInitGenesisOnMigration(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) mockModule := mocks.NewMockAppModule(mockCtrl) - mockDefaultGenesis := json.RawMessage(`{"key": "value"}`) - mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis) - mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil) + mockDefaultGenesis := &testdata.AnyWithExtra{B: 111} + + mockModule.EXPECT().DefaultGenesis().Times(1).Return(mockDefaultGenesis) + mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil) mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0)) app.ModuleManager.Modules["mock"] = mockModule diff --git a/simapp/export.go b/simapp/export.go index 990a426c4dc0..cb9fbd597d56 100644 --- a/simapp/export.go +++ b/simapp/export.go @@ -1,7 +1,6 @@ package simapp import ( - "encoding/json" "fmt" "log" @@ -30,8 +29,9 @@ func (app *SimApp) ExportAppStateAndValidators( app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) } - genState := app.ModuleManager.ExportGenesis(ctx, app.appCodec) - appState, err := json.MarshalIndent(genState, "", " ") + genState := app.ModuleManager.ExportGenesis(ctx) + + appState, err := sdk.MarshalGenesisStateToJSON(genState, app.AppCodec(), true) if err != nil { return servertypes.ExportedApp{}, err } diff --git a/simapp/genesis.go b/simapp/genesis.go index a002aead9ae5..960291f5d6d1 100644 --- a/simapp/genesis.go +++ b/simapp/genesis.go @@ -1,21 +1,10 @@ package simapp import ( - "encoding/json" - - "github.com/cosmos/cosmos-sdk/codec" + "github.com/gogo/protobuf/proto" ) -// GenesisState of the blockchain is represented here as a map of raw json -// messages key'd by a identifier string. -// The identifier is used to determine which module genesis information belongs -// to so it may be appropriately routed during init chain. -// Within this application default genesis information is retrieved from -// the ModuleBasicManager which populates json from each BasicModule -// object provided to it during init. -type GenesisState map[string]json.RawMessage - // NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return ModuleBasics.DefaultGenesis(cdc) +func NewDefaultGenesisState() map[string]proto.Message { + return ModuleBasics.DefaultGenesis() } diff --git a/simapp/sim_test.go b/simapp/sim_test.go index ed96329cbace..33ee3c86af1a 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -162,7 +162,7 @@ func TestAppImportExport(t *testing.T) { newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", newApp.Name()) - var genesisState GenesisState + var genesisState map[string]json.RawMessage err = json.Unmarshal(exported.AppState, &genesisState) require.NoError(t, err) diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 1fd12e5a8727..1823fbfe272c 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -355,11 +355,10 @@ func initGenFiles( genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string, numValidators int, ) error { - appGenState := mbm.DefaultGenesis(clientCtx.Codec) + appGenState := mbm.DefaultGenesis() // set the accounts in the genesis state - var authGenState authtypes.GenesisState - clientCtx.Codec.MustUnmarshalJSON(appGenState[authtypes.ModuleName], &authGenState) + authGenState := appGenState[authtypes.ModuleName].(*authtypes.GenesisState) accounts, err := authtypes.PackAccounts(genAccounts) if err != nil { @@ -367,19 +366,18 @@ func initGenFiles( } authGenState.Accounts = accounts - appGenState[authtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&authGenState) + appGenState[authtypes.ModuleName] = authGenState // set the balances in the genesis state - var bankGenState banktypes.GenesisState - clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) + bankGenState := appGenState[banktypes.ModuleName].(*banktypes.GenesisState) bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances) for _, bal := range bankGenState.Balances { bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...) } - appGenState[banktypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&bankGenState) + appGenState[banktypes.ModuleName] = bankGenState - appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ") + appGenStateJSON, err := sdk.MarshalGenesisStateToJSON(appGenState, clientCtx.Codec, true) if err != nil { return err } diff --git a/simapp/state.go b/simapp/state.go index 14eb5aeedce5..45340a86f9bd 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -8,6 +8,7 @@ import ( "os" "time" + "github.com/gogo/protobuf/proto" tmjson "github.com/tendermint/tendermint/libs/json" tmtypes "github.com/tendermint/tendermint/types" @@ -143,7 +144,7 @@ func AppStateRandomizedFn( accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, ) (json.RawMessage, []simtypes.Account) { numAccs := int64(len(accs)) - genesisState := NewDefaultGenesisState(cdc) + genesisState := NewDefaultGenesisState() // generate a random amount of initial stake coins and a random initial // number of bonded accounts @@ -186,7 +187,7 @@ func AppStateRandomizedFn( simManager.GenerateGenesisStates(simState) - appState, err := json.Marshal(genesisState) + appState, err := sdk.MarshalGenesisStateToJSON(genesisState, cdc, false) if err != nil { panic(err) } @@ -209,15 +210,15 @@ func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile str panic(err) } - var appState GenesisState + var appState map[string]proto.Message err = json.Unmarshal(genesis.AppState, &appState) if err != nil { panic(err) } - var authGenesis authtypes.GenesisState + var authGenesis *authtypes.GenesisState if appState[authtypes.ModuleName] != nil { - cdc.MustUnmarshalJSON(appState[authtypes.ModuleName], &authGenesis) + authGenesis = appState[authtypes.ModuleName].(*authtypes.GenesisState) } newAccs := make([]simtypes.Account, len(authGenesis.Accounts)) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 3078c644c077..8cf23123c179 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -2,14 +2,13 @@ package simapp import ( "context" - "encoding/json" "math/rand" "testing" "time" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -43,7 +42,7 @@ type SetupOptions struct { AppOpts servertypes.AppOptions } -func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { +func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, map[string]proto.Message) { db := dbm.NewMemDB() appOptions := make(simtestutil.AppOptionsMap, 0) @@ -52,9 +51,9 @@ func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { app := NewSimApp(log.NewNopLogger(), db, nil, true, appOptions) if withGenesis { - return app, NewDefaultGenesisState(app.AppCodec()) + return app, NewDefaultGenesisState() } - return app, GenesisState{} + return app, map[string]proto.Message{} } // NewSimappWithCustomOptions initializes a new SimApp with custom options. @@ -77,13 +76,13 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio } app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts) - genesisState := NewDefaultGenesisState(app.appCodec) + genesisState := NewDefaultGenesisState() genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) if !isCheckTx { // init chain must be called to stop deliverState from being nil - stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, app.AppCodec(), true) require.NoError(t, err) // Initialize the chain @@ -135,7 +134,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs genesisState, err := simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, genAccs, balances...) require.NoError(t, err) - stateBytes, err := json.MarshalIndent(genesisState, "", " ") + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, app.AppCodec(), true) require.NoError(t, err) // init chain will set the validator set and initialize the genesis accounts @@ -177,7 +176,7 @@ func SetupWithGenesisAccounts(t *testing.T, genAccs []authtypes.GenesisAccount, // GenesisStateWithSingleValidator initializes GenesisState with a single validator and genesis accounts // that also act as delegators. -func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState { +func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) map[string]proto.Message { t.Helper() privVal := mock.NewPV() @@ -198,7 +197,7 @@ func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState { }, } - genesisState := NewDefaultGenesisState(app.appCodec) + genesisState := NewDefaultGenesisState() genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) require.NoError(t, err) @@ -368,7 +367,7 @@ func NewTestNetworkFixture() network.TestFixture { return network.TestFixture{ AppConstructor: appCtr, - GenesisState: ModuleBasics.DefaultGenesis(app.AppCodec()), + GenesisState: ModuleBasics.DefaultGenesis(), EncodingConfig: testutil.TestEncodingConfig{ InterfaceRegistry: app.InterfaceRegistry(), Codec: app.AppCodec(), diff --git a/tests/e2e/gov/client/testutil/cli_test.go b/tests/e2e/gov/client/testutil/cli_test.go index c472b0c68cc2..1a8d51d7fa45 100644 --- a/tests/e2e/gov/client/testutil/cli_test.go +++ b/tests/e2e/gov/client/testutil/cli_test.go @@ -12,7 +12,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/client/testutil" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -26,8 +25,7 @@ func TestIntegrationTestSuite(t *testing.T) { votingPeriod := time.Duration(5) * time.Second genesisState.Params.MaxDepositPeriod = &maxDepPeriod genesisState.Params.VotingPeriod = &votingPeriod - bz, err := cfg.Codec.MarshalJSON(genesisState) - require.NoError(t, err) - cfg.GenesisState["gov"] = bz + cfg.GenesisState["gov"] = genesisState + suite.Run(t, testutil.NewDepositTestSuite(cfg)) } diff --git a/tests/e2e/server/export_test.go b/tests/e2e/server/export_test.go index 2452bd2836a9..9423add80e21 100644 --- a/tests/e2e/server/export_test.go +++ b/tests/e2e/server/export_test.go @@ -28,6 +28,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/genutil" ) @@ -134,7 +135,8 @@ func setupApp(t *testing.T, tempDir string) (*simapp.SimApp, context.Context, *t app := simapp.NewSimApp(logger, db, nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir)) genesisState := simapp.GenesisStateWithSingleValidator(t, app) - stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") + + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, app.AppCodec(), true) require.NoError(t, err) serverCtx := server.NewDefaultContext() diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 5a07c7563d61..3e2d4a3c9152 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -13,6 +13,7 @@ import ( types "github.com/cosmos/cosmos-sdk/codec/types" types0 "github.com/cosmos/cosmos-sdk/types" module "github.com/cosmos/cosmos-sdk/types/module" + proto "github.com/gogo/protobuf/proto" gomock "github.com/golang/mock/gomock" runtime "github.com/grpc-ecosystem/grpc-gateway/runtime" cobra "github.com/spf13/cobra" @@ -43,17 +44,17 @@ func (m *MockAppModuleBasic) EXPECT() *MockAppModuleBasicMockRecorder { } // DefaultGenesis mocks base method. -func (m *MockAppModuleBasic) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { +func (m *MockAppModuleBasic) DefaultGenesis() proto.Message { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DefaultGenesis", arg0) - ret0, _ := ret[0].(json.RawMessage) + ret := m.ctrl.Call(m, "DefaultGenesis") + ret0, _ := ret[0].(proto.Message) return ret0 } // DefaultGenesis indicates an expected call of DefaultGenesis. -func (mr *MockAppModuleBasicMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { +func (mr *MockAppModuleBasicMockRecorder) DefaultGenesis() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModuleBasic)(nil).DefaultGenesis), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModuleBasic)(nil).DefaultGenesis)) } // GetQueryCmd mocks base method. @@ -172,31 +173,31 @@ func (m *MockAppModuleGenesis) EXPECT() *MockAppModuleGenesisMockRecorder { } // DefaultGenesis mocks base method. -func (m *MockAppModuleGenesis) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { +func (m *MockAppModuleGenesis) DefaultGenesis() proto.Message { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DefaultGenesis", arg0) - ret0, _ := ret[0].(json.RawMessage) + ret := m.ctrl.Call(m, "DefaultGenesis") + ret0, _ := ret[0].(proto.Message) return ret0 } // DefaultGenesis indicates an expected call of DefaultGenesis. -func (mr *MockAppModuleGenesisMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { +func (mr *MockAppModuleGenesisMockRecorder) DefaultGenesis() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).DefaultGenesis), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).DefaultGenesis)) } // ExportGenesis mocks base method. -func (m *MockAppModuleGenesis) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockAppModuleGenesis) ExportGenesis(arg0 types0.Context) proto.Message { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) - ret0, _ := ret[0].(json.RawMessage) + ret := m.ctrl.Call(m, "ExportGenesis", arg0) + ret0, _ := ret[0].(proto.Message) return ret0 } // ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockAppModuleGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockAppModuleGenesisMockRecorder) ExportGenesis(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ExportGenesis), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).ExportGenesis), arg0) } // GetQueryCmd mocks base method. @@ -228,17 +229,17 @@ func (mr *MockAppModuleGenesisMockRecorder) GetTxCmd() *gomock.Call { } // InitGenesis mocks base method. -func (m *MockAppModuleGenesis) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { +func (m *MockAppModuleGenesis) InitGenesis(arg0 types0.Context, arg1 proto.Message) []types1.ValidatorUpdate { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) ret0, _ := ret[0].([]types1.ValidatorUpdate) return ret0 } // InitGenesis indicates an expected call of InitGenesis. -func (mr *MockAppModuleGenesisMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockAppModuleGenesisMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).InitGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModuleGenesis)(nil).InitGenesis), arg0, arg1) } // Name mocks base method. @@ -328,18 +329,6 @@ func (m *MockAppModule) EXPECT() *MockAppModuleMockRecorder { return m.recorder } -// BeginBlock mocks base method. -func (m *MockAppModule) BeginBlock(arg0 types0.Context, arg1 types1.RequestBeginBlock) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "BeginBlock", arg0, arg1) -} - -// BeginBlock indicates an expected call of BeginBlock. -func (mr *MockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockAppModule)(nil).BeginBlock), arg0, arg1) -} - // ConsensusVersion mocks base method. func (m *MockAppModule) ConsensusVersion() uint64 { m.ctrl.T.Helper() @@ -355,45 +344,31 @@ func (mr *MockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { } // DefaultGenesis mocks base method. -func (m *MockAppModule) DefaultGenesis(arg0 codec.JSONCodec) json.RawMessage { +func (m *MockAppModule) DefaultGenesis() proto.Message { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DefaultGenesis", arg0) - ret0, _ := ret[0].(json.RawMessage) + ret := m.ctrl.Call(m, "DefaultGenesis") + ret0, _ := ret[0].(proto.Message) return ret0 } // DefaultGenesis indicates an expected call of DefaultGenesis. -func (mr *MockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.Call { +func (mr *MockAppModuleMockRecorder) DefaultGenesis() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis), arg0) -} - -// EndBlock mocks base method. -func (m *MockAppModule) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) - ret0, _ := ret[0].([]types1.ValidatorUpdate) - return ret0 -} - -// EndBlock indicates an expected call of EndBlock. -func (mr *MockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModule)(nil).EndBlock), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockAppModule)(nil).DefaultGenesis)) } // ExportGenesis mocks base method. -func (m *MockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockAppModule) ExportGenesis(arg0 types0.Context) proto.Message { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) - ret0, _ := ret[0].(json.RawMessage) + ret := m.ctrl.Call(m, "ExportGenesis", arg0) + ret0, _ := ret[0].(proto.Message) return ret0 } // ExportGenesis indicates an expected call of ExportGenesis. -func (mr *MockAppModuleMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockAppModuleMockRecorder) ExportGenesis(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModule)(nil).ExportGenesis), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockAppModule)(nil).ExportGenesis), arg0) } // GetQueryCmd mocks base method. @@ -425,17 +400,17 @@ func (mr *MockAppModuleMockRecorder) GetTxCmd() *gomock.Call { } // InitGenesis mocks base method. -func (m *MockAppModule) InitGenesis(arg0 types0.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types1.ValidatorUpdate { +func (m *MockAppModule) InitGenesis(arg0 types0.Context, arg1 proto.Message) []types1.ValidatorUpdate { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) ret0, _ := ret[0].([]types1.ValidatorUpdate) return ret0 } // InitGenesis indicates an expected call of InitGenesis. -func (mr *MockAppModuleMockRecorder) InitGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockAppModuleMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModule)(nil).InitGenesis), arg0, arg1, arg2) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockAppModule)(nil).InitGenesis), arg0, arg1) } // LegacyQuerierHandler mocks base method. @@ -567,3 +542,503 @@ func (mr *MockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{ mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) } + +// MockBeginBlockAppModule is a mock of BeginBlockAppModule interface. +type MockBeginBlockAppModule struct { + ctrl *gomock.Controller + recorder *MockBeginBlockAppModuleMockRecorder +} + +// MockBeginBlockAppModuleMockRecorder is the mock recorder for MockBeginBlockAppModule. +type MockBeginBlockAppModuleMockRecorder struct { + mock *MockBeginBlockAppModule +} + +// NewMockBeginBlockAppModule creates a new mock instance. +func NewMockBeginBlockAppModule(ctrl *gomock.Controller) *MockBeginBlockAppModule { + mock := &MockBeginBlockAppModule{ctrl: ctrl} + mock.recorder = &MockBeginBlockAppModuleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBeginBlockAppModule) EXPECT() *MockBeginBlockAppModuleMockRecorder { + return m.recorder +} + +// BeginBlock mocks base method. +func (m *MockBeginBlockAppModule) BeginBlock(arg0 types0.Context, arg1 types1.RequestBeginBlock) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BeginBlock", arg0, arg1) +} + +// BeginBlock indicates an expected call of BeginBlock. +func (mr *MockBeginBlockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockBeginBlockAppModule)(nil).BeginBlock), arg0, arg1) +} + +// ConsensusVersion mocks base method. +func (m *MockBeginBlockAppModule) ConsensusVersion() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockBeginBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ConsensusVersion)) +} + +// DefaultGenesis mocks base method. +func (m *MockBeginBlockAppModule) DefaultGenesis() proto.Message { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis") + ret0, _ := ret[0].(proto.Message) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) DefaultGenesis() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).DefaultGenesis)) +} + +// ExportGenesis mocks base method. +func (m *MockBeginBlockAppModule) ExportGenesis(arg0 types0.Context) proto.Message { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0) + ret0, _ := ret[0].(proto.Message) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) ExportGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ExportGenesis), arg0) +} + +// GetQueryCmd mocks base method. +func (m *MockBeginBlockAppModule) GetQueryCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetQueryCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetQueryCmd indicates an expected call of GetQueryCmd. +func (mr *MockBeginBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetQueryCmd)) +} + +// GetTxCmd mocks base method. +func (m *MockBeginBlockAppModule) GetTxCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTxCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetTxCmd indicates an expected call of GetTxCmd. +func (mr *MockBeginBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetTxCmd)) +} + +// InitGenesis mocks base method. +func (m *MockBeginBlockAppModule) InitGenesis(arg0 types0.Context, arg1 proto.Message) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).InitGenesis), arg0, arg1) +} + +// LegacyQuerierHandler mocks base method. +func (m *MockBeginBlockAppModule) LegacyQuerierHandler(arg0 *codec.LegacyAmino) types0.Querier { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyQuerierHandler", arg0) + ret0, _ := ret[0].(types0.Querier) + return ret0 +} + +// LegacyQuerierHandler indicates an expected call of LegacyQuerierHandler. +func (mr *MockBeginBlockAppModuleMockRecorder) LegacyQuerierHandler(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQuerierHandler", reflect.TypeOf((*MockBeginBlockAppModule)(nil).LegacyQuerierHandler), arg0) +} + +// Name mocks base method. +func (m *MockBeginBlockAppModule) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockBeginBlockAppModuleMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockBeginBlockAppModule)(nil).Name)) +} + +// QuerierRoute mocks base method. +func (m *MockBeginBlockAppModule) QuerierRoute() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QuerierRoute") + ret0, _ := ret[0].(string) + return ret0 +} + +// QuerierRoute indicates an expected call of QuerierRoute. +func (mr *MockBeginBlockAppModuleMockRecorder) QuerierRoute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockBeginBlockAppModule)(nil).QuerierRoute)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockBeginBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockBeginBlockAppModule) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInterfaces), arg0) +} + +// RegisterInvariants mocks base method. +func (m *MockBeginBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInvariants", arg0) +} + +// RegisterInvariants indicates an expected call of RegisterInvariants. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInvariants), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockBeginBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +} + +// RegisterServices mocks base method. +func (m *MockBeginBlockAppModule) RegisterServices(arg0 module.Configurator) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockBeginBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterServices), arg0) +} + +// Route mocks base method. +func (m *MockBeginBlockAppModule) Route() types0.Route { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Route") + ret0, _ := ret[0].(types0.Route) + return ret0 +} + +// Route indicates an expected call of Route. +func (mr *MockBeginBlockAppModuleMockRecorder) Route() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockBeginBlockAppModule)(nil).Route)) +} + +// ValidateGenesis mocks base method. +func (m *MockBeginBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockBeginBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockBeginBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) +} + +// MockEndBlockAppModule is a mock of EndBlockAppModule interface. +type MockEndBlockAppModule struct { + ctrl *gomock.Controller + recorder *MockEndBlockAppModuleMockRecorder +} + +// MockEndBlockAppModuleMockRecorder is the mock recorder for MockEndBlockAppModule. +type MockEndBlockAppModuleMockRecorder struct { + mock *MockEndBlockAppModule +} + +// NewMockEndBlockAppModule creates a new mock instance. +func NewMockEndBlockAppModule(ctrl *gomock.Controller) *MockEndBlockAppModule { + mock := &MockEndBlockAppModule{ctrl: ctrl} + mock.recorder = &MockEndBlockAppModuleMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEndBlockAppModule) EXPECT() *MockEndBlockAppModuleMockRecorder { + return m.recorder +} + +// ConsensusVersion mocks base method. +func (m *MockEndBlockAppModule) ConsensusVersion() uint64 { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ConsensusVersion") + ret0, _ := ret[0].(uint64) + return ret0 +} + +// ConsensusVersion indicates an expected call of ConsensusVersion. +func (mr *MockEndBlockAppModuleMockRecorder) ConsensusVersion() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockEndBlockAppModule)(nil).ConsensusVersion)) +} + +// DefaultGenesis mocks base method. +func (m *MockEndBlockAppModule) DefaultGenesis() proto.Message { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultGenesis") + ret0, _ := ret[0].(proto.Message) + return ret0 +} + +// DefaultGenesis indicates an expected call of DefaultGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) DefaultGenesis() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).DefaultGenesis)) +} + +// EndBlock mocks base method. +func (m *MockEndBlockAppModule) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// EndBlock indicates an expected call of EndBlock. +func (mr *MockEndBlockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockEndBlockAppModule)(nil).EndBlock), arg0, arg1) +} + +// ExportGenesis mocks base method. +func (m *MockEndBlockAppModule) ExportGenesis(arg0 types0.Context) proto.Message { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ExportGenesis", arg0) + ret0, _ := ret[0].(proto.Message) + return ret0 +} + +// ExportGenesis indicates an expected call of ExportGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) ExportGenesis(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ExportGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).ExportGenesis), arg0) +} + +// GetQueryCmd mocks base method. +func (m *MockEndBlockAppModule) GetQueryCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetQueryCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetQueryCmd indicates an expected call of GetQueryCmd. +func (mr *MockEndBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetQueryCmd)) +} + +// GetTxCmd mocks base method. +func (m *MockEndBlockAppModule) GetTxCmd() *cobra.Command { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTxCmd") + ret0, _ := ret[0].(*cobra.Command) + return ret0 +} + +// GetTxCmd indicates an expected call of GetTxCmd. +func (mr *MockEndBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetTxCmd)) +} + +// InitGenesis mocks base method. +func (m *MockEndBlockAppModule) InitGenesis(arg0 types0.Context, arg1 proto.Message) []types1.ValidatorUpdate { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1) + ret0, _ := ret[0].([]types1.ValidatorUpdate) + return ret0 +} + +// InitGenesis indicates an expected call of InitGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).InitGenesis), arg0, arg1) +} + +// LegacyQuerierHandler mocks base method. +func (m *MockEndBlockAppModule) LegacyQuerierHandler(arg0 *codec.LegacyAmino) types0.Querier { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LegacyQuerierHandler", arg0) + ret0, _ := ret[0].(types0.Querier) + return ret0 +} + +// LegacyQuerierHandler indicates an expected call of LegacyQuerierHandler. +func (mr *MockEndBlockAppModuleMockRecorder) LegacyQuerierHandler(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LegacyQuerierHandler", reflect.TypeOf((*MockEndBlockAppModule)(nil).LegacyQuerierHandler), arg0) +} + +// Name mocks base method. +func (m *MockEndBlockAppModule) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockEndBlockAppModuleMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockEndBlockAppModule)(nil).Name)) +} + +// QuerierRoute mocks base method. +func (m *MockEndBlockAppModule) QuerierRoute() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QuerierRoute") + ret0, _ := ret[0].(string) + return ret0 +} + +// QuerierRoute indicates an expected call of QuerierRoute. +func (mr *MockEndBlockAppModuleMockRecorder) QuerierRoute() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QuerierRoute", reflect.TypeOf((*MockEndBlockAppModule)(nil).QuerierRoute)) +} + +// RegisterGRPCGatewayRoutes mocks base method. +func (m *MockEndBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1) +} + +// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1) +} + +// RegisterInterfaces mocks base method. +func (m *MockEndBlockAppModule) RegisterInterfaces(arg0 types.InterfaceRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInterfaces", arg0) +} + +// RegisterInterfaces indicates an expected call of RegisterInterfaces. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInterfaces), arg0) +} + +// RegisterInvariants mocks base method. +func (m *MockEndBlockAppModule) RegisterInvariants(arg0 types0.InvariantRegistry) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterInvariants", arg0) +} + +// RegisterInvariants indicates an expected call of RegisterInvariants. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterInvariants(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInvariants", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInvariants), arg0) +} + +// RegisterLegacyAminoCodec mocks base method. +func (m *MockEndBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0) +} + +// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0) +} + +// RegisterServices mocks base method. +func (m *MockEndBlockAppModule) RegisterServices(arg0 module.Configurator) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "RegisterServices", arg0) +} + +// RegisterServices indicates an expected call of RegisterServices. +func (mr *MockEndBlockAppModuleMockRecorder) RegisterServices(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterServices", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterServices), arg0) +} + +// Route mocks base method. +func (m *MockEndBlockAppModule) Route() types0.Route { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Route") + ret0, _ := ret[0].(types0.Route) + return ret0 +} + +// Route indicates an expected call of Route. +func (mr *MockEndBlockAppModuleMockRecorder) Route() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Route", reflect.TypeOf((*MockEndBlockAppModule)(nil).Route)) +} + +// ValidateGenesis mocks base method. +func (m *MockEndBlockAppModule) ValidateGenesis(arg0 codec.JSONCodec, arg1 client.TxEncodingConfig, arg2 json.RawMessage) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGenesis", arg0, arg1, arg2) + ret0, _ := ret[0].(error) + return ret0 +} + +// ValidateGenesis indicates an expected call of ValidateGenesis. +func (mr *MockEndBlockAppModuleMockRecorder) ValidateGenesis(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).ValidateGenesis), arg0, arg1, arg2) +} diff --git a/testutil/network/network.go b/testutil/network/network.go index 4b3213c3b714..e65b27bedd9c 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -15,6 +15,7 @@ import ( "testing" "time" + "github.com/gogo/protobuf/proto" "github.com/rs/zerolog" "github.com/spf13/cobra" "github.com/tendermint/tendermint/config" @@ -67,7 +68,7 @@ type TestFixtureFactory = func() TestFixture type TestFixture struct { AppConstructor AppConstructor - GenesisState map[string]json.RawMessage + GenesisState map[string]proto.Message EncodingConfig moduletestutil.TestEncodingConfig } @@ -80,26 +81,26 @@ type Config struct { TxConfig client.TxConfig AccountRetriever client.AccountRetriever - AppConstructor AppConstructor // the ABCI application constructor - GenesisState map[string]json.RawMessage // custom genesis state to provide - TimeoutCommit time.Duration // the consensus commitment timeout - ChainID string // the network chain-id - NumValidators int // the total number of validators to create and bond - Mnemonics []string // custom user-provided validator operator mnemonics - BondDenom string // the staking bond denomination - MinGasPrices string // the minimum gas prices each validator will accept - AccountTokens math.Int // the amount of unique validator tokens (e.g. 1000node0) - StakingTokens math.Int // the amount of tokens each validator has available to stake - BondedTokens math.Int // the amount of tokens each validator stakes - PruningStrategy string // the pruning strategy each validator will have - EnableTMLogging bool // enable Tendermint logging to STDOUT - CleanupDir bool // remove base temporary directory during cleanup - SigningAlgo string // signing algorithm for keys - KeyringOptions []keyring.Option // keyring configuration options - RPCAddress string // RPC listen address (including port) - APIAddress string // REST API listen address (including port) - GRPCAddress string // GRPC server listen address (including port) - PrintMnemonic bool // print the mnemonic of first validator as log output for testing + AppConstructor AppConstructor // the ABCI application constructor + GenesisState map[string]proto.Message // custom genesis state to provide + TimeoutCommit time.Duration // the consensus commitment timeout + ChainID string // the network chain-id + NumValidators int // the total number of validators to create and bond + Mnemonics []string // custom user-provided validator operator mnemonics + BondDenom string // the staking bond denomination + MinGasPrices string // the minimum gas prices each validator will accept + AccountTokens math.Int // the amount of unique validator tokens (e.g. 1000node0) + StakingTokens math.Int // the amount of tokens each validator has available to stake + BondedTokens math.Int // the amount of tokens each validator stakes + PruningStrategy string // the pruning strategy each validator will have + EnableTMLogging bool // enable Tendermint logging to STDOUT + CleanupDir bool // remove base temporary directory during cleanup + SigningAlgo string // signing algorithm for keys + KeyringOptions []keyring.Option // keyring configuration options + RPCAddress string // RPC listen address (including port) + APIAddress string // REST API listen address (including port) + GRPCAddress string // GRPC server listen address (including port) + PrintMnemonic bool // print the mnemonic of first validator as log output for testing } // DefaultConfig returns a sane default configuration suitable for nearly all diff --git a/testutil/network/util.go b/testutil/network/util.go index e3ace5544445..7530fc21230c 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -1,7 +1,6 @@ package network import ( - "encoding/json" "fmt" "io/ioutil" "path/filepath" @@ -17,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/api" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" srvtypes "github.com/cosmos/cosmos-sdk/server/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -153,8 +153,7 @@ func collectGenFiles(cfg Config, vals []*Validator, outputDir string) error { func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance, genFiles []string) error { // set the accounts in the genesis state - var authGenState authtypes.GenesisState - cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[authtypes.ModuleName], &authGenState) + authGenState := cfg.GenesisState[authtypes.ModuleName].(*authtypes.GenesisState) accounts, err := authtypes.PackAccounts(genAccounts) if err != nil { @@ -162,16 +161,15 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance } authGenState.Accounts = append(authGenState.Accounts, accounts...) - cfg.GenesisState[authtypes.ModuleName] = cfg.Codec.MustMarshalJSON(&authGenState) + cfg.GenesisState[authtypes.ModuleName] = authGenState // set the balances in the genesis state - var bankGenState banktypes.GenesisState - cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[banktypes.ModuleName], &bankGenState) + bankGenState := cfg.GenesisState[banktypes.ModuleName].(*banktypes.GenesisState) bankGenState.Balances = append(bankGenState.Balances, genBalances...) - cfg.GenesisState[banktypes.ModuleName] = cfg.Codec.MustMarshalJSON(&bankGenState) + cfg.GenesisState[banktypes.ModuleName] = bankGenState - appGenStateJSON, err := json.MarshalIndent(cfg.GenesisState, "", " ") + appGenStateJSON, err := sdk.MarshalGenesisStateToJSON(cfg.GenesisState, cfg.Codec, true) if err != nil { return err } diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index 6be34dc1ccf9..f6c9883f3fc1 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -2,12 +2,11 @@ package sims import ( "context" - "encoding/json" "fmt" "time" + "github.com/gogo/protobuf/proto" abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -135,8 +134,7 @@ func SetupWithConfiguration(appConfig depinject.Config, validatorSet func() (*tm return nil, fmt.Errorf("failed to create genesis state: %w", err) } - // init chain must be called to stop deliverState from being nil - stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, codec, true) if err != nil { return nil, fmt.Errorf("failed to marshal default genesis state: %w", err) } @@ -165,13 +163,13 @@ func SetupWithConfiguration(appConfig depinject.Config, validatorSet func() (*tm } // GenesisStateWithValSet returns a new genesis state with the validator set -func GenesisStateWithValSet(codec codec.Codec, genesisState map[string]json.RawMessage, +func GenesisStateWithValSet(codec codec.Codec, genesisState map[string]proto.Message, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance, -) (map[string]json.RawMessage, error) { +) (map[string]proto.Message, error) { // set genesis accounts authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) - genesisState[authtypes.ModuleName] = codec.MustMarshalJSON(authGenesis) + genesisState[authtypes.ModuleName] = authGenesis validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators)) @@ -208,7 +206,7 @@ func GenesisStateWithValSet(codec codec.Codec, genesisState map[string]json.RawM } // set validators and delegations stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) - genesisState[stakingtypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis) + genesisState[stakingtypes.ModuleName] = stakingGenesis totalSupply := sdk.NewCoins() for _, b := range balances { @@ -229,7 +227,7 @@ func GenesisStateWithValSet(codec codec.Codec, genesisState map[string]json.RawM // update total supply bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{}) - genesisState[banktypes.ModuleName] = codec.MustMarshalJSON(bankGenesis) + genesisState[banktypes.ModuleName] = bankGenesis return genesisState, nil } diff --git a/types/module/module.go b/types/module/module.go index da4719fb7fad..2ab777f87412 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -31,8 +31,10 @@ package module import ( "encoding/json" "fmt" + "reflect" "sort" + "github.com/gogo/protobuf/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -50,7 +52,7 @@ type AppModuleBasic interface { RegisterLegacyAminoCodec(*codec.LegacyAmino) RegisterInterfaces(codectypes.InterfaceRegistry) - DefaultGenesis(codec.JSONCodec) json.RawMessage + DefaultGenesis() proto.Message ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error // client functionality @@ -86,10 +88,10 @@ func (bm BasicManager) RegisterInterfaces(registry codectypes.InterfaceRegistry) } // DefaultGenesis provides default genesis information for all modules -func (bm BasicManager) DefaultGenesis(cdc codec.JSONCodec) map[string]json.RawMessage { - genesis := make(map[string]json.RawMessage) +func (bm BasicManager) DefaultGenesis() map[string]proto.Message { + genesis := make(map[string]proto.Message) for _, b := range bm { - genesis[b.Name()] = b.DefaultGenesis(cdc) + genesis[b.Name()] = b.DefaultGenesis() } return genesis @@ -141,8 +143,8 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { type AppModuleGenesis interface { AppModuleBasic - InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate - ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + InitGenesis(sdk.Context, proto.Message) []abci.ValidatorUpdate + ExportGenesis(sdk.Context) proto.Message } // AppModule is the standard form for an application module @@ -298,7 +300,18 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData } ctx.Logger().Debug("running initialization for module", "module", moduleName) - moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, cdc, genesisData[moduleName]) + // Get the type of the default genesis so we can create a zeroed struct + // to which we then unmarshal the genesis' file JSON into + genType := reflect.TypeOf(m.Modules[moduleName].DefaultGenesis()) + if genType == nil { + continue + } + moduleGenesis := reflect.New(genType.Elem()).Interface().(proto.Message) + + if err := cdc.UnmarshalJSON(genesisData[moduleName], moduleGenesis); err != nil { + panic(fmt.Sprintf("failed to parse %s genesis state: %s", moduleName, err)) + } + moduleValUpdates := m.Modules[moduleName].InitGenesis(ctx, moduleGenesis) // use these validator updates if provided, the module manager assumes // only one module will update the validator set @@ -321,10 +334,10 @@ 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) map[string]json.RawMessage { - genesisData := make(map[string]json.RawMessage) +func (m *Manager) ExportGenesis(ctx sdk.Context) map[string]proto.Message { + genesisData := make(map[string]proto.Message) for _, moduleName := range m.OrderExportGenesis { - genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx, cdc) + genesisData[moduleName] = m.Modules[moduleName].ExportGenesis(ctx) } return genesisData @@ -434,7 +447,7 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version } } else { ctx.Logger().Info(fmt.Sprintf("adding a new module: %s", moduleName)) - moduleValUpdates := module.InitGenesis(ctx, c.cdc, module.DefaultGenesis(c.cdc)) + moduleValUpdates := module.InitGenesis(ctx, module.DefaultGenesis()) // The module manager assumes only one module will update the // validator set, and it can't be a new module. if len(moduleValUpdates) > 0 { diff --git a/types/module/module_test.go b/types/module/module_test.go index 2f52b0dbbc00..d49265ef92ae 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -3,8 +3,10 @@ package module_test import ( "encoding/json" "errors" + "fmt" "testing" + "github.com/gogo/protobuf/proto" "github.com/golang/mock/gomock" "github.com/spf13/cobra" "github.com/stretchr/testify/require" @@ -12,10 +14,10 @@ import ( "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/tests/mocks" + "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -29,15 +31,14 @@ func TestBasicManager(t *testing.T) { interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - clientCtx := client.Context{} - clientCtx = clientCtx.WithLegacyAmino(legacyAmino) - wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)} + wantDefaultGenesis := map[string]proto.Message{"mockAppModuleBasic1": &testdata.AnyWithExtra{B: 111}} + wantDefaultGenesisJSON := map[string]json.RawMessage{"mockAppModuleBasic1": []byte(`{"b":111}`)} mockAppModuleBasic1 := mocks.NewMockAppModuleBasic(mockCtrl) mockAppModuleBasic1.EXPECT().Name().AnyTimes().Return("mockAppModuleBasic1") - mockAppModuleBasic1.EXPECT().DefaultGenesis(gomock.Eq(cdc)).Times(1).Return(json.RawMessage(``)) - mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(nil), gomock.Eq(wantDefaultGenesis["mockAppModuleBasic1"])).Times(1).Return(errFoo) + mockAppModuleBasic1.EXPECT().DefaultGenesis().Times(1).Return(&testdata.AnyWithExtra{B: 111}) + mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(nil), gomock.Eq(wantDefaultGenesisJSON["mockAppModuleBasic1"])).Times(1).Return(errFoo) mockAppModuleBasic1.EXPECT().RegisterLegacyAminoCodec(gomock.Eq(legacyAmino)).Times(1) mockAppModuleBasic1.EXPECT().RegisterInterfaces(gomock.Eq(interfaceRegistry)).Times(1) mockAppModuleBasic1.EXPECT().GetTxCmd().Times(1).Return(nil) @@ -49,12 +50,12 @@ func TestBasicManager(t *testing.T) { mm.RegisterLegacyAminoCodec(legacyAmino) mm.RegisterInterfaces(interfaceRegistry) - require.Equal(t, wantDefaultGenesis, mm.DefaultGenesis(cdc)) + require.Equal(t, wantDefaultGenesis, mm.DefaultGenesis()) var data map[string]string require.Equal(t, map[string]string(nil), data) - require.True(t, errors.Is(errFoo, mm.ValidateGenesis(cdc, nil, wantDefaultGenesis))) + require.True(t, errors.Is(errFoo, mm.ValidateGenesis(cdc, nil, wantDefaultGenesisJSON))) mockCmd := &cobra.Command{Use: "root"} mm.AddTxCommands(mockCmd) @@ -62,7 +63,7 @@ func TestBasicManager(t *testing.T) { mm.AddQueryCommands(mockCmd) // validate genesis returns nil - require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, nil, wantDefaultGenesis)) + require.Nil(t, module.NewBasicManager().ValidateGenesis(cdc, nil, wantDefaultGenesisJSON)) } func TestGenesisOnlyAppModule(t *testing.T) { @@ -154,29 +155,50 @@ func TestManager_InitGenesis(t *testing.T) { mockAppModule1 := mocks.NewMockAppModule(mockCtrl) mockAppModule2 := mocks.NewMockAppModule(mockCtrl) + mockAppModule3 := mocks.NewMockAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") - mm := module.NewManager(mockAppModule1, mockAppModule2) + mockAppModule3.EXPECT().Name().Times(2).Return("module3") + mm := module.NewManager(mockAppModule1, mockAppModule2, mockAppModule3) require.NotNil(t, mm) - require.Equal(t, 2, len(mm.Modules)) + require.Equal(t, 3, len(mm.Modules)) ctx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger()) interfaceRegistry := types.NewInterfaceRegistry() cdc := codec.NewProtoCodec(interfaceRegistry) - genesisData := map[string]json.RawMessage{"module1": json.RawMessage(`{"key": "value"}`)} - // this should panic since the validator set is empty even after init genesis - mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return(nil) - require.Panics(t, func() { mm.InitGenesis(ctx, cdc, genesisData) }) + genModule1 := &testdata.Cat{Moniker: "module1"} + genModule2 := &testdata.Dog{Name: "module2"} - // test panic + genesisData := map[string]json.RawMessage{ + "module1": json.RawMessage(`{"moniker": "module1"}`), + "module3": json.RawMessage(`{}`), + } + + // this should panic since the validator set is empty even after init genesis + mockAppModule1.EXPECT().DefaultGenesis().Return(&testdata.Cat{}) + mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), genModule1).Times(1).Return(nil) + mockAppModule3.EXPECT().DefaultGenesis().Return(nil) + require.PanicsWithValue(t, + fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction), + func() { mm.InitGenesis(ctx, cdc, genesisData) }, + ) + + // test panic because updates were already set by a previous module (module1 and module2 return updates) genesisData = map[string]json.RawMessage{ - "module1": json.RawMessage(`{"key": "value"}`), - "module2": json.RawMessage(`{"key": "value"}`), + "module1": json.RawMessage(`{"moniker": "module1"}`), + "module2": json.RawMessage(`{"name": "module2"}`), } - mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module1"])).Times(1).Return([]abci.ValidatorUpdate{{}}) - mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(cdc), gomock.Eq(genesisData["module2"])).Times(1).Return([]abci.ValidatorUpdate{{}}) - require.Panics(t, func() { mm.InitGenesis(ctx, cdc, genesisData) }) + mockAppModule1.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genModule1)).Times(1).Return([]abci.ValidatorUpdate{{}}) + mockAppModule2.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(genModule2)).Times(1).Return([]abci.ValidatorUpdate{{}}) + + mockAppModule1.EXPECT().DefaultGenesis().Return(&testdata.Cat{}) + mockAppModule2.EXPECT().DefaultGenesis().Return(&testdata.Dog{}) + + require.PanicsWithValue(t, + "validator InitGenesis updates already set by a previous module", + func() { mm.InitGenesis(ctx, cdc, genesisData) }, + ) } func TestManager_ExportGenesis(t *testing.T) { @@ -192,24 +214,31 @@ func TestManager_ExportGenesis(t *testing.T) { require.Equal(t, 2, len(mm.Modules)) 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"}`)) - want := map[string]json.RawMessage{ - "module1": json.RawMessage(`{"key1": "value1"}`), - "module2": json.RawMessage(`{"key2": "value2"}`), + gen1 := &testdata.AnyWithExtra{B: 111} + gen2 := &testdata.AnyWithExtra{B: 222} + + mockAppModule1.EXPECT().ExportGenesis(gomock.Eq(ctx)).Times(1).Return(gen1) + mockAppModule2.EXPECT().ExportGenesis(gomock.Eq(ctx)).Times(1).Return(gen2) + + want := map[string]proto.Message{ + "module1": gen1, + "module2": gen2, } - require.Equal(t, want, mm.ExportGenesis(ctx, cdc)) + + exportedGen := mm.ExportGenesis(ctx) + require.Equal(t, want, exportedGen) + + require.Equal(t, int64(111), (exportedGen["module1"]).(*testdata.AnyWithExtra).B) + require.Equal(t, int64(222), (exportedGen["module2"]).(*testdata.AnyWithExtra).B) } func TestManager_BeginBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mocks.NewMockAppModule(mockCtrl) - mockAppModule2 := mocks.NewMockAppModule(mockCtrl) + mockAppModule1 := mocks.NewMockBeginBlockAppModule(mockCtrl) + mockAppModule2 := mocks.NewMockBeginBlockAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") mm := module.NewManager(mockAppModule1, mockAppModule2) @@ -227,8 +256,8 @@ func TestManager_EndBlock(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) - mockAppModule1 := mocks.NewMockAppModule(mockCtrl) - mockAppModule2 := mocks.NewMockAppModule(mockCtrl) + mockAppModule1 := mocks.NewMockEndBlockAppModule(mockCtrl) + mockAppModule2 := mocks.NewMockEndBlockAppModule(mockCtrl) mockAppModule1.EXPECT().Name().Times(2).Return("module1") mockAppModule2.EXPECT().Name().Times(2).Return("module2") mm := module.NewManager(mockAppModule1, mockAppModule2) diff --git a/types/module/simulation.go b/types/module/simulation.go index 8cba9093452e..eaa29d9c9750 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -1,7 +1,6 @@ package module import ( - "encoding/json" "math/rand" "sort" "time" @@ -10,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/gogo/protobuf/proto" ) // AppModuleSimulation defines the standard functions that every module should expose @@ -134,7 +134,7 @@ type SimulationState struct { AppParams simulation.AppParams Cdc codec.JSONCodec // application codec Rand *rand.Rand // random number - GenState map[string]json.RawMessage // genesis state + GenState map[string]proto.Message // genesis state Accounts []simulation.Account // simulation accounts InitialStake sdkmath.Int // initial coins per account NumBonded int64 // number of initially bonded accounts diff --git a/types/utils.go b/types/utils.go index efd9a9c71a81..92127eab527d 100644 --- a/types/utils.go +++ b/types/utils.go @@ -6,7 +6,9 @@ import ( "fmt" "time" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" + proto "github.com/gogo/protobuf/proto" dbm "github.com/tendermint/tm-db" ) @@ -125,3 +127,24 @@ func ParseLengthPrefixedBytes(key []byte, startIndex int, sliceLength int) ([]by return byteSlice, endIndex } + +func MarshalGenesisStateToJSON(gs map[string]proto.Message, cdc codec.JSONCodec, indent bool) ([]byte, error) { + genStateJson := map[string]json.RawMessage{} + var err error + for k, v := range gs { + if v != nil { + genStateJson[k], err = cdc.MarshalJSON(v) + if err != nil { + return nil, err + } + } else { + genStateJson[k] = []byte("{}") + } + } + + if indent { + return json.MarshalIndent(genStateJson, "", " ") + } + + return json.Marshal(genStateJson) +} diff --git a/x/auth/module.go b/x/auth/module.go index 2505e44bbc6a..3cfe02f7d045 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -9,6 +9,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/auth/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -53,8 +54,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the auth // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the auth module. @@ -139,18 +140,16 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - am.accountKeeper.InitGenesis(ctx, genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*types.GenesisState) + am.accountKeeper.InitGenesis(ctx, *genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the auth // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.accountKeeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.accountKeeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 4b31bf7d49e0..1ae50ba502d8 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -130,5 +130,5 @@ func RandomizedGenState(simState *module.SimulationState, randGenAccountsFn type panic(err) } fmt.Printf("Selected randomly generated auth parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(authGenesis) + simState.GenState[types.ModuleName] = authGenesis } diff --git a/x/auth/simulation/genesis_test.go b/x/auth/simulation/genesis_test.go index 4b8f48ef76b0..18912767d48b 100644 --- a/x/auth/simulation/genesis_test.go +++ b/x/auth/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -33,13 +33,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState, simulation.RandomGenesisAccounts) - var authGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &authGenesis) + authGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) require.Equal(t, uint64(0x8c), authGenesis.Params.GetMaxMemoCharacters()) require.Equal(t, uint64(0x2b6), authGenesis.Params.GetSigVerifyCostED25519()) diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 0fb256467c7a..79d14815e9dd 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -3,10 +3,6 @@ package vesting import ( "encoding/json" - gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" - "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -14,6 +10,10 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/gogo/protobuf/proto" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" modulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/core/appmodule" @@ -49,8 +49,8 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) } // DefaultGenesis returns the module's default genesis state as raw bytes. -func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage { - return []byte("{}") +func (AppModuleBasic) DefaultGenesis() proto.Message { + return nil } // ValidateGenesis performs genesis state validation. Currently, this is a no-op. @@ -98,13 +98,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis performs a no-op. -func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(_ sdk.Context, _ proto.Message) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } // ExportGenesis is always empty, as InitGenesis does nothing either. -func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return am.DefaultGenesis(cdc) +func (am AppModule) ExportGenesis(_ sdk.Context) proto.Message { + return am.DefaultGenesis() } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/authz/module/module.go b/x/authz/module/module.go index bced6e7a891d..d41ef3b2d575 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -5,6 +5,7 @@ import ( "encoding/json" "math/rand" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -69,8 +70,8 @@ func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // DefaultGenesis returns default genesis state as raw bytes for the authz // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(authz.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return authz.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the authz module. @@ -134,18 +135,16 @@ func (am AppModule) NewHandler() sdk.Handler { // InitGenesis performs genesis initialization for the authz module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState authz.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - am.keeper.InitGenesis(ctx, &genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*authz.GenesisState) + am.keeper.InitGenesis(ctx, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the authz // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/authz/simulation/genesis.go b/x/authz/simulation/genesis.go index e1443683bb18..99042c9eefff 100644 --- a/x/authz/simulation/genesis.go +++ b/x/authz/simulation/genesis.go @@ -65,5 +65,5 @@ func RandomizedGenState(simState *module.SimulationState) { authzGrantsGenesis := authz.NewGenesisState(grants) - simState.GenState[authz.ModuleName] = simState.Cdc.MustMarshalJSON(authzGrantsGenesis) + simState.GenState[authz.ModuleName] = authzGrantsGenesis } diff --git a/x/authz/simulation/genesis_test.go b/x/authz/simulation/genesis_test.go index a6ad0e399530..72f3556a2c1d 100644 --- a/x/authz/simulation/genesis_test.go +++ b/x/authz/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" "cosmossdk.io/depinject" @@ -31,12 +31,12 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var authzGenesis authz.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[authz.ModuleName], &authzGenesis) + authzGenesis, ok := simState.GenState[authz.ModuleName].(*authz.GenesisState) + require.True(t, ok) require.Len(t, authzGenesis.Authorization, len(simState.Accounts)-1) } diff --git a/x/bank/client/testutil/suite.go b/x/bank/client/testutil/suite.go index 77efc07de9f1..de6b88b68dfc 100644 --- a/x/bank/client/testutil/suite.go +++ b/x/bank/client/testutil/suite.go @@ -35,8 +35,8 @@ func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up integration test suite") genesisState := s.cfg.GenesisState - var bankGenesis types.GenesisState - s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[types.ModuleName], &bankGenesis)) + bankGenesis, ok := genesisState[types.ModuleName].(*types.GenesisState) + s.Require().True(ok) bankGenesis.DenomMetadata = []types.Metadata{ { @@ -78,11 +78,10 @@ func (s *IntegrationTestSuite) SetupSuite() { }, } - bankGenesisBz, err := s.cfg.Codec.MarshalJSON(&bankGenesis) - s.Require().NoError(err) - genesisState[types.ModuleName] = bankGenesisBz + genesisState[types.ModuleName] = bankGenesis s.cfg.GenesisState = genesisState + var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) diff --git a/x/bank/module.go b/x/bank/module.go index 0ca4e015ebb7..e7490a6881a2 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -10,6 +10,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/bank/module/v1" "cosmossdk.io/depinject" store "github.com/cosmos/cosmos-sdk/store/types" + "github.com/gogo/protobuf/proto" "github.com/tendermint/tendermint/crypto" "cosmossdk.io/core/appmodule" @@ -59,8 +60,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the bank // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the bank module. @@ -151,21 +152,19 @@ func (AppModule) QuerierRoute() string { return types.RouterKey } // InitGenesis performs genesis initialization for the bank module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { start := time.Now() - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) + genesisState := data.(*types.GenesisState) telemetry.MeasureSince(start, "InitGenesis", "crisis", "unmarshal") - am.keeper.InitGenesis(ctx, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the bank // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/bank/simulation/genesis.go b/x/bank/simulation/genesis.go index 8592b08a318d..b9dfbdb7265c 100644 --- a/x/bank/simulation/genesis.go +++ b/x/bank/simulation/genesis.go @@ -95,5 +95,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated bank parameters:\n%s\n", paramsBytes) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&bankGenesis) + simState.GenState[types.ModuleName] = &bankGenesis } diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index 7782b6cd794f..612fb0061cab 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -32,13 +32,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var bankGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &bankGenesis) + bankGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled") assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") diff --git a/x/capability/module.go b/x/capability/module.go index 23ecad8e7cd3..5ca8d5a92991 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -7,6 +7,7 @@ import ( "time" "cosmossdk.io/core/appmodule" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -59,8 +60,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} func (a AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} // DefaultGenesis returns the capability module's default genesis state. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesis()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesis() } // ValidateGenesis performs genesis state validation for the capability module. @@ -117,20 +118,17 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // InitGenesis performs the capability module's genesis initialization It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { - var genState types.GenesisState - // Initialize global index to index in genesis state - cdc.MustUnmarshalJSON(gs, &genState) +func (am AppModule) InitGenesis(ctx sdk.Context, gs proto.Message) []abci.ValidatorUpdate { + genState := gs.(*types.GenesisState) - InitGenesis(ctx, am.keeper, genState) + InitGenesis(ctx, am.keeper, *genState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the capability module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - genState := ExportGenesis(ctx, am.keeper) - return cdc.MustMarshalJSON(genState) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return ExportGenesis(ctx, am.keeper) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/capability/simulation/genesis.go b/x/capability/simulation/genesis.go index ab1d11fb3d46..4400bf213574 100644 --- a/x/capability/simulation/genesis.go +++ b/x/capability/simulation/genesis.go @@ -35,5 +35,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&capabilityGenesis) + simState.GenState[types.ModuleName] = &capabilityGenesis } diff --git a/x/capability/simulation/genesis_test.go b/x/capability/simulation/genesis_test.go index 14eb344cc093..b6d9227a72d3 100644 --- a/x/capability/simulation/genesis_test.go +++ b/x/capability/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -31,13 +31,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var capGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &capGenesis) + capGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) require.Equal(t, uint64(149), capGenesis.Index) require.Len(t, capGenesis.Owners, 0) diff --git a/x/crisis/module.go b/x/crisis/module.go index 0a0c2fe55824..04b9f0ce3d20 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -8,6 +8,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/crisis/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cast" "github.com/spf13/cobra" @@ -59,8 +60,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the crisis // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the crisis module. @@ -144,13 +145,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { start := time.Now() - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) + genesisState := data.(*types.GenesisState) telemetry.MeasureSince(start, "InitGenesis", "crisis", "unmarshal") - am.keeper.InitGenesis(ctx, &genesisState) + am.keeper.InitGenesis(ctx, genesisState) if !am.skipGenesisInvariants { am.keeper.AssertInvariants(ctx) } @@ -159,9 +159,8 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the crisis // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/distribution/client/testutil/suite.go b/x/distribution/client/testutil/suite.go index dac9c3a6dc73..68dd47066ec2 100644 --- a/x/distribution/client/testutil/suite.go +++ b/x/distribution/client/testutil/suite.go @@ -46,17 +46,16 @@ func (s *IntegrationTestSuite) SetupSuite() { s.cfg = cfg genesisState := s.cfg.GenesisState - var mintData minttypes.GenesisState - s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) + + mintData, ok := genesisState[minttypes.ModuleName].(*minttypes.GenesisState) + s.Require().True(ok) inflation := sdk.MustNewDecFromStr("1.0") mintData.Minter.Inflation = inflation mintData.Params.InflationMin = inflation mintData.Params.InflationMax = inflation - mintDataBz, err := s.cfg.Codec.MarshalJSON(&mintData) - s.Require().NoError(err) - genesisState[minttypes.ModuleName] = mintDataBz + genesisState[minttypes.ModuleName] = mintData s.cfg.GenesisState = genesisState s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) diff --git a/x/distribution/module.go b/x/distribution/module.go index 26372bd876c2..fbf2f125a884 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -9,6 +9,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -58,8 +59,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the distribution // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the distribution module. @@ -149,18 +150,16 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the distribution module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - am.keeper.InitGenesis(ctx, genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*types.GenesisState) + am.keeper.InitGenesis(ctx, *genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the distribution // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/distribution/simulation/genesis.go b/x/distribution/simulation/genesis.go index 036efa28adff..027291095321 100644 --- a/x/distribution/simulation/genesis.go +++ b/x/distribution/simulation/genesis.go @@ -82,5 +82,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated distribution parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&distrGenesis) + simState.GenState[types.ModuleName] = &distrGenesis } diff --git a/x/distribution/simulation/genesis_test.go b/x/distribution/simulation/genesis_test.go index 259f0512d7a0..98f892a2d045 100644 --- a/x/distribution/simulation/genesis_test.go +++ b/x/distribution/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -32,13 +32,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var distrGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &distrGenesis) + distrGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) dec1, _ := sdk.NewDecFromStr("0.170000000000000000") dec2, _ := sdk.NewDecFromStr("0.010000000000000000") diff --git a/x/evidence/module.go b/x/evidence/module.go index 03c9135a5000..5e95e28b8ba0 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -7,6 +7,7 @@ import ( "math/rand" "cosmossdk.io/core/appmodule" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -62,8 +63,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { } // DefaultGenesis returns the evidence module's default genesis state. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the evidence module. @@ -137,20 +138,19 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // InitGenesis performs the evidence module's genesis initialization It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { - var gs types.GenesisState - err := cdc.UnmarshalJSON(bz, &gs) - if err != nil { - panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", types.ModuleName, err)) +func (am AppModule) InitGenesis(ctx sdk.Context, bz proto.Message) []abci.ValidatorUpdate { + gs, ok := bz.(*types.GenesisState) + if !ok { + panic(fmt.Sprintf("failed to unmarshal %s genesis state.", types.ModuleName)) } - InitGenesis(ctx, am.keeper, &gs) + InitGenesis(ctx, am.keeper, gs) return []abci.ValidatorUpdate{} } // ExportGenesis returns the evidence module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return ExportGenesis(ctx, am.keeper) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/evidence/simulation/genesis.go b/x/evidence/simulation/genesis.go index 640670ebe9a9..c3ea739cad55 100644 --- a/x/evidence/simulation/genesis.go +++ b/x/evidence/simulation/genesis.go @@ -37,5 +37,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(evidenceGenesis) + simState.GenState[types.ModuleName] = evidenceGenesis } diff --git a/x/evidence/simulation/genesis_test.go b/x/evidence/simulation/genesis_test.go index 4999015bfd67..6fb372e257e5 100644 --- a/x/evidence/simulation/genesis_test.go +++ b/x/evidence/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -32,13 +32,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var evidenceGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &evidenceGenesis) + evidenceGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) require.Len(t, evidenceGenesis.Evidence, 0) } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 402dc449e520..6e117c1fc7c9 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -6,6 +6,8 @@ import ( "math/rand" "cosmossdk.io/core/appmodule" + + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -77,8 +79,8 @@ func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sd // DefaultGenesis returns default genesis state as raw bytes for the feegrant // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(feegrant.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return feegrant.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the feegrant module. @@ -142,11 +144,9 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {} // InitGenesis performs genesis initialization for the feegrant module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { - var gs feegrant.GenesisState - cdc.MustUnmarshalJSON(bz, &gs) - - err := am.keeper.InitGenesis(ctx, &gs) +func (am AppModule) InitGenesis(ctx sdk.Context, bz proto.Message) []abci.ValidatorUpdate { + gs := bz.(*feegrant.GenesisState) + err := am.keeper.InitGenesis(ctx, gs) if err != nil { panic(err) } @@ -155,13 +155,13 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.Ra // ExportGenesis returns the exported genesis state as raw bytes for the feegrant // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { gs, err := am.keeper.ExportGenesis(ctx) if err != nil { panic(err) } - return cdc.MustMarshalJSON(gs) + return gs } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/feegrant/simulation/genesis.go b/x/feegrant/simulation/genesis.go index 7fbc8107c5bb..2b95ba036ac5 100644 --- a/x/feegrant/simulation/genesis.go +++ b/x/feegrant/simulation/genesis.go @@ -67,11 +67,5 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { feegrants = genFeeGrants(r, simState.Accounts) }, ) - feegrantGenesis := feegrant.NewGenesisState(feegrants) - bz, err := simState.Cdc.MarshalJSON(feegrantGenesis) - if err != nil { - panic(err) - } - - simState.GenState[feegrant.ModuleName] = bz + simState.GenState[feegrant.ModuleName] = feegrant.NewGenesisState(feegrants) } diff --git a/x/feegrant/simulation/genesis_test.go b/x/feegrant/simulation/genesis_test.go index f15d1dd4b91f..92ebf7b25868 100644 --- a/x/feegrant/simulation/genesis_test.go +++ b/x/feegrant/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -30,12 +30,12 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: accounts, InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var feegrantGenesis feegrant.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[feegrant.ModuleName], &feegrantGenesis) + feegrantGenesis, ok := simState.GenState[feegrant.ModuleName].(*feegrant.GenesisState) + require.True(t, ok) require.Len(t, feegrantGenesis.Allowances, len(accounts)-1) } diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 3107061c465a..9442978e6011 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -75,7 +75,6 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - cdc := clientCtx.Codec serverCtx := server.GetServerContextFromCmd(cmd) config := serverCtx.Config @@ -121,24 +120,14 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { return fmt.Errorf("genesis.json file already exists: %v", genFile) } - appGenState := mbm.DefaultGenesis(cdc) + appGenState := mbm.DefaultGenesis() if stakingBondDenom != "" { - var stakingGenesis stakingtypes.GenesisState - - stakingRaw := appGenState[stakingtypes.ModuleName] - err := clientCtx.Codec.UnmarshalJSON(stakingRaw, &stakingGenesis) - if err != nil { - return err - } + stakingGenesis := appGenState[stakingtypes.ModuleName].(*stakingtypes.GenesisState) stakingGenesis.Params.BondDenom = stakingBondDenom - modifiedStakingStr, err := clientCtx.Codec.MarshalJSON(&stakingGenesis) - if err != nil { - return err - } - appGenState[stakingtypes.ModuleName] = modifiedStakingStr + appGenState[stakingtypes.ModuleName] = stakingGenesis } appState, err := json.MarshalIndent(appGenState, "", " ") diff --git a/x/genutil/module.go b/x/genutil/module.go index 0bf86f85d439..08257a6b2b78 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -6,6 +6,7 @@ import ( modulev1 "cosmossdk.io/api/cosmos/genutil/module/v1" "cosmossdk.io/core/appmodule" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -41,8 +42,8 @@ func (b AppModuleBasic) RegisterInterfaces(_ cdctypes.InterfaceRegistry) {} // DefaultGenesis returns default genesis state as raw bytes for the genutil // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the genutil module. @@ -91,10 +92,9 @@ func NewAppModule(accountKeeper types.AccountKeeper, // InitGenesis performs genesis initialization for the genutil module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - validators, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := (data).(*types.GenesisState) + validators, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, *genesisState, am.txEncodingConfig) if err != nil { panic(err) } @@ -103,8 +103,8 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the genutil // module. -func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return am.DefaultGenesis(cdc) +func (am AppModule) ExportGenesis(_ sdk.Context) proto.Message { + return am.DefaultGenesis() } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/gov/genesis_test.go b/x/gov/genesis_test.go index d7c0c6b677ec..213fcde0c003 100644 --- a/x/gov/genesis_test.go +++ b/x/gov/genesis_test.go @@ -1,7 +1,6 @@ package gov_test import ( - "encoding/json" "testing" "github.com/stretchr/testify/require" @@ -60,15 +59,15 @@ func TestImportExportQueues(t *testing.T) { // export the state and import it into a new app govGenState := gov.ExportGenesis(ctx, app.GovKeeper) - genesisState := simapp.NewDefaultGenesisState(app.AppCodec()) + genesisState := simapp.NewDefaultGenesisState() - genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenState) - genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState) - genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) - genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenState) - genesisState[distributiontypes.ModuleName] = app.AppCodec().MustMarshalJSON(distributionGenState) + genesisState[authtypes.ModuleName] = authGenState + genesisState[banktypes.ModuleName] = bankGenState + genesisState[types.ModuleName] = govGenState + genesisState[stakingtypes.ModuleName] = stakingGenState + genesisState[distributiontypes.ModuleName] = distributionGenState - stateBytes, err := json.MarshalIndent(genesisState, "", " ") + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, app.AppCodec(), true) if err != nil { panic(err) } diff --git a/x/gov/module.go b/x/gov/module.go index 2b799b493713..3dd010469274 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -9,6 +9,7 @@ import ( "math/rand" "sort" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -73,8 +74,8 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the gov // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(v1.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return v1.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the gov module. @@ -298,18 +299,16 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the gov module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState v1.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*v1.GenesisState) + InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the gov // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := ExportGenesis(ctx, am.keeper) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return ExportGenesis(ctx, am.keeper) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/gov/module_test.go b/x/gov/module_test.go index b0d277162b40..954ece22f828 100644 --- a/x/gov/module_test.go +++ b/x/gov/module_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -14,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -28,7 +28,8 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, appOptions) genesisState := simapp.GenesisStateWithSingleValidator(t, app) - stateBytes, err := tmjson.Marshal(genesisState) + + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, app.AppCodec(), false) require.NoError(t, err) app.InitChain( diff --git a/x/gov/simulation/genesis.go b/x/gov/simulation/genesis.go index a7a5f36ca1bb..56c640f33541 100644 --- a/x/gov/simulation/genesis.go +++ b/x/gov/simulation/genesis.go @@ -106,5 +106,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated governance parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(govGenesis) + simState.GenState[types.ModuleName] = govGenesis } diff --git a/x/gov/simulation/genesis_test.go b/x/gov/simulation/genesis_test.go index 37868dd942f6..83c840d5a561 100644 --- a/x/gov/simulation/genesis_test.go +++ b/x/gov/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -34,13 +34,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var govGenesis v1.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &govGenesis) + govGenesis, ok := simState.GenState[types.ModuleName].(*v1.GenesisState) + require.True(t, ok) dec1, _ := sdk.NewDecFromStr("0.361000000000000000") dec2, _ := sdk.NewDecFromStr("0.512000000000000000") @@ -53,9 +53,9 @@ func TestRandomizedGenState(t *testing.T) { require.Equal(t, dec2.String(), govGenesis.Params.Threshold) require.Equal(t, dec3.String(), govGenesis.Params.VetoThreshold) require.Equal(t, uint64(0x28), govGenesis.StartingProposalId) - require.Equal(t, []*v1.Deposit{}, govGenesis.Deposits) - require.Equal(t, []*v1.Vote{}, govGenesis.Votes) - require.Equal(t, []*v1.Proposal{}, govGenesis.Proposals) + require.Equal(t, []*v1.Deposit(nil), govGenesis.Deposits) + require.Equal(t, []*v1.Vote(nil), govGenesis.Votes) + require.Equal(t, []*v1.Proposal(nil), govGenesis.Proposals) } // TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState. diff --git a/x/group/keeper/genesis.go b/x/group/keeper/genesis.go index 2e0766ed716e..255efe561fae 100644 --- a/x/group/keeper/genesis.go +++ b/x/group/keeper/genesis.go @@ -1,19 +1,16 @@ package keeper import ( - "encoding/json" - + "github.com/gogo/protobuf/proto" abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/group" ) -func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState group.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) +func (k Keeper) InitGenesis(ctx types.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*group.GenesisState) if err := k.groupTable.Import(ctx.KVStore(k.key), genesisState.Groups, genesisState.GroupSeq); err != nil { panic(errors.Wrap(err, "groups")) @@ -42,7 +39,7 @@ func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.Ra return []abci.ValidatorUpdate{} } -func (k Keeper) ExportGenesis(ctx types.Context, cdc codec.JSONCodec) *group.GenesisState { +func (k Keeper) ExportGenesis(ctx types.Context) *group.GenesisState { genesisState := group.NewGenesisState() var groups []*group.GroupInfo diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index 25c1323f7b44..64e945f3e8cd 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "context" - "encoding/json" "testing" "time" @@ -118,14 +117,8 @@ func (s *GenesisTestSuite) TestInitExportGenesis() { Proposals: []*group.Proposal{proposal}, Votes: []*group.Vote{{ProposalId: proposal.Id, Voter: memberAddr.String(), SubmitTime: submittedAt, Option: group.VOTE_OPTION_YES}}, } - genesisBytes, err := cdc.MarshalJSON(genesisState) - s.Require().NoError(err) - - genesisData := map[string]json.RawMessage{ - group.ModuleName: genesisBytes, - } - s.keeper.InitGenesis(sdkCtx, cdc, genesisData[group.ModuleName]) + s.keeper.InitGenesis(sdkCtx, genesisState) for i, g := range genesisState.Groups { res, err := s.keeper.GroupInfo(ctx, &group.QueryGroupInfoRequest{ @@ -165,7 +158,7 @@ func (s *GenesisTestSuite) TestInitExportGenesis() { s.Require().Equal(votesRes.Votes[0], genesisState.Votes[0]) } - exported := s.keeper.ExportGenesis(sdkCtx, cdc) + exported := s.keeper.ExportGenesis(sdkCtx) bz, err := cdc.MarshalJSON(exported) s.Require().NoError(err) diff --git a/x/group/module/module.go b/x/group/module/module.go index c0ad9a540cf4..9a512c9c004a 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -7,6 +7,8 @@ import ( "math/rand" "cosmossdk.io/core/appmodule" + + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -64,8 +66,8 @@ func (AppModuleBasic) Name() string { // DefaultGenesis returns default genesis state as raw bytes for the group // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(group.NewGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return group.NewGenesisState() } // ValidateGenesis performs genesis state validation for the group module. @@ -118,16 +120,15 @@ func (am AppModule) NewHandler() sdk.Handler { // InitGenesis performs genesis initialization for the group module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - am.keeper.InitGenesis(ctx, cdc, data) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + am.keeper.InitGenesis(ctx, data) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the group // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx, cdc) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // RegisterServices registers a gRPC query service to respond to the diff --git a/x/group/simulation/genesis.go b/x/group/simulation/genesis.go index 7f30a4fc7303..bde7a38ffebf 100644 --- a/x/group/simulation/genesis.go +++ b/x/group/simulation/genesis.go @@ -193,5 +193,5 @@ func RandomizedGenState(simState *module.SimulationState) { Votes: votes, } - simState.GenState[group.ModuleName] = simState.Cdc.MustMarshalJSON(&groupGenesis) + simState.GenState[group.ModuleName] = &groupGenesis } diff --git a/x/group/simulation/genesis_test.go b/x/group/simulation/genesis_test.go index db09434920ac..2e50fc8e9c66 100644 --- a/x/group/simulation/genesis_test.go +++ b/x/group/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" "cosmossdk.io/depinject" @@ -32,12 +32,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var groupGenesis group.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[group.ModuleName], &groupGenesis) + + groupGenesis, ok := simState.GenState[group.ModuleName].(*group.GenesisState) + require.True(t, ok) require.Equal(t, int(groupGenesis.GroupSeq), len(simState.Accounts)) require.Len(t, groupGenesis.Groups, len(simState.Accounts)) diff --git a/x/mint/client/testutil/suite.go b/x/mint/client/testutil/suite.go index dd90d2d54333..c91edcea0803 100644 --- a/x/mint/client/testutil/suite.go +++ b/x/mint/client/testutil/suite.go @@ -31,19 +31,18 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := s.cfg.GenesisState - var mintData minttypes.GenesisState - s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[minttypes.ModuleName], &mintData)) + mintData, ok := genesisState[minttypes.ModuleName].(*minttypes.GenesisState) + s.Require().True(ok) inflation := sdk.MustNewDecFromStr("1.0") mintData.Minter.Inflation = inflation mintData.Params.InflationMin = inflation mintData.Params.InflationMax = inflation - mintDataBz, err := s.cfg.Codec.MarshalJSON(&mintData) - s.Require().NoError(err) - genesisState[minttypes.ModuleName] = mintDataBz + genesisState[minttypes.ModuleName] = mintData s.cfg.GenesisState = genesisState + var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) diff --git a/x/mint/module.go b/x/mint/module.go index 6ee35876e854..15673da7ed02 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -8,6 +8,8 @@ import ( modulev1 "cosmossdk.io/api/cosmos/mint/module/v1" "cosmossdk.io/core/appmodule" + + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -63,8 +65,8 @@ func (b AppModuleBasic) RegisterInterfaces(r cdctypes.InterfaceRegistry) { // DefaultGenesis returns default genesis state as raw bytes for the mint // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the mint module. @@ -152,19 +154,16 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the mint module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - - am.keeper.InitGenesis(ctx, am.authKeeper, &genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*types.GenesisState) + am.keeper.InitGenesis(ctx, am.authKeeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the mint // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/mint/simulation/genesis.go b/x/mint/simulation/genesis.go index be363a429809..7727b554e1c2 100644 --- a/x/mint/simulation/genesis.go +++ b/x/mint/simulation/genesis.go @@ -92,5 +92,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated minting parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(mintGenesis) + simState.GenState[types.ModuleName] = mintGenesis } diff --git a/x/mint/simulation/genesis_test.go b/x/mint/simulation/genesis_test.go index 6c590d6c8ea8..9de2596524d3 100644 --- a/x/mint/simulation/genesis_test.go +++ b/x/mint/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" "cosmossdk.io/math" @@ -33,13 +33,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var mintGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &mintGenesis) + mintGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) dec1, _ := sdk.NewDecFromStr("0.670000000000000000") dec2, _ := sdk.NewDecFromStr("0.200000000000000000") diff --git a/x/nft/client/testutil/tx.go b/x/nft/client/testutil/tx.go index e95bbf6b13d1..0043cd0deead 100644 --- a/x/nft/client/testutil/tx.go +++ b/x/nft/client/testutil/tx.go @@ -75,10 +75,10 @@ func (s *IntegrationTestSuite) SetupSuite() { }}, } - nftDataBz, err := s.cfg.Codec.MarshalJSON(&nftGenesis) - s.Require().NoError(err) - genesisState[nft.ModuleName] = nftDataBz + genesisState[nft.ModuleName] = &nftGenesis s.cfg.GenesisState = genesisState + + var err error s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg) s.Require().NoError(err) diff --git a/x/nft/module/module.go b/x/nft/module/module.go index b8054addf0d8..955415ce4c23 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -5,6 +5,7 @@ import ( "encoding/json" "math/rand" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -61,8 +62,8 @@ func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // DefaultGenesis returns default genesis state as raw bytes for the nft // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(nft.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return nft.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the nft module. @@ -127,18 +128,16 @@ func (am AppModule) NewHandler() sdk.Handler { // InitGenesis performs genesis initialization for the nft module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState nft.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - am.keeper.InitGenesis(ctx, &genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*nft.GenesisState) + am.keeper.InitGenesis(ctx, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the nft // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/nft/simulation/genesis.go b/x/nft/simulation/genesis.go index b11b358746d8..5578dcf1f1a5 100644 --- a/x/nft/simulation/genesis.go +++ b/x/nft/simulation/genesis.go @@ -63,5 +63,5 @@ func RandomizedGenState(simState *module.SimulationState) { Classes: classes, Entries: entries, } - simState.GenState[nft.ModuleName] = simState.Cdc.MustMarshalJSON(nftGenesis) + simState.GenState[nft.ModuleName] = nftGenesis } diff --git a/x/nft/simulation/genesis_test.go b/x/nft/simulation/genesis_test.go index ae47c9a9602d..2dbb84f526b5 100644 --- a/x/nft/simulation/genesis_test.go +++ b/x/nft/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -29,12 +29,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var nftGenesis nft.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[nft.ModuleName], &nftGenesis) + + nftGenesis, ok := simState.GenState[nft.ModuleName].(*nft.GenesisState) + require.True(t, ok) require.Len(t, nftGenesis.Classes, len(simState.Accounts)-1) require.Len(t, nftGenesis.Entries, len(simState.Accounts)-1) diff --git a/x/params/module.go b/x/params/module.go index 82ccd75c48a1..9676a1d3d065 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -6,6 +6,7 @@ import ( "math/rand" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -51,7 +52,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { // DefaultGenesis returns default genesis state as raw bytes for the params // module. -func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage { return nil } +func (AppModuleBasic) DefaultGenesis() proto.Message { return nil } // ValidateGenesis performs genesis state validation for the params module. func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, config client.TxEncodingConfig, _ json.RawMessage) error { @@ -95,7 +96,7 @@ func NewAppModule(k keeper.Keeper) AppModule { func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // InitGenesis performs a no-op. -func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(_ sdk.Context, _ proto.Message) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } @@ -128,7 +129,7 @@ func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.Weig } // ExportGenesis performs a no-op. -func (am AppModule) ExportGenesis(_ sdk.Context, _ codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(_ sdk.Context) proto.Message { return nil } diff --git a/x/slashing/module.go b/x/slashing/module.go index e0e5de62e324..df279c332c25 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -9,6 +9,8 @@ import ( modulev1 "cosmossdk.io/api/cosmos/slashing/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -64,8 +66,8 @@ func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) // DefaultGenesis returns default genesis state as raw bytes for the slashing // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the slashing module. @@ -145,18 +147,16 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the slashing module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - am.keeper.InitGenesis(ctx, am.stakingKeeper, &genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*types.GenesisState) + am.keeper.InitGenesis(ctx, am.stakingKeeper, genesisState) return []abci.ValidatorUpdate{} } // ExportGenesis returns the exported genesis state as raw bytes for the slashing // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - gs := am.keeper.ExportGenesis(ctx) - return cdc.MustMarshalJSON(gs) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/slashing/simulation/genesis.go b/x/slashing/simulation/genesis.go index bb46fce2228c..200d4c1c8973 100644 --- a/x/slashing/simulation/genesis.go +++ b/x/slashing/simulation/genesis.go @@ -93,5 +93,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated slashing parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(slashingGenesis) + simState.GenState[types.ModuleName] = slashingGenesis } diff --git a/x/slashing/simulation/genesis_test.go b/x/slashing/simulation/genesis_test.go index 6cf18bb751b8..c5b240adea6f 100644 --- a/x/slashing/simulation/genesis_test.go +++ b/x/slashing/simulation/genesis_test.go @@ -1,11 +1,11 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" "time" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" "cosmossdk.io/depinject" @@ -37,13 +37,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var slashingGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &slashingGenesis) + slashingGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) dec1, _ := sdk.NewDecFromStr("0.600000000000000000") dec2, _ := sdk.NewDecFromStr("0.022222222222222222") diff --git a/x/staking/module.go b/x/staking/module.go index 6a2f74072478..2662799ab94d 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -10,6 +10,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/staking/exported" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -67,8 +68,8 @@ func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry) // DefaultGenesis returns default genesis state as raw bytes for the staking // module. -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) +func (AppModuleBasic) DefaultGenesis() proto.Message { + return types.DefaultGenesisState() } // ValidateGenesis performs genesis state validation for the staking module. @@ -157,18 +158,15 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the staking module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - - cdc.MustUnmarshalJSON(data, &genesisState) - - return am.keeper.InitGenesis(ctx, &genesisState) +func (am AppModule) InitGenesis(ctx sdk.Context, data proto.Message) []abci.ValidatorUpdate { + genesisState := data.(*types.GenesisState) + return am.keeper.InitGenesis(ctx, genesisState) } // ExportGenesis returns the exported genesis state as raw bytes for the staking // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(am.keeper.ExportGenesis(ctx)) +func (am AppModule) ExportGenesis(ctx sdk.Context) proto.Message { + return am.keeper.ExportGenesis(ctx) } // ConsensusVersion implements AppModule/ConsensusVersion. diff --git a/x/staking/module_test.go b/x/staking/module_test.go index 9c18bf3629e2..73fd30997d61 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" @@ -14,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/simapp" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -28,7 +28,8 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, appOptions) genesisState := simapp.GenesisStateWithSingleValidator(t, app) - stateBytes, err := tmjson.Marshal(genesisState) + + stateBytes, err := sdk.MarshalGenesisStateToJSON(genesisState, app.AppCodec(), true) require.NoError(t, err) app.InitChain( diff --git a/x/staking/simulation/genesis.go b/x/staking/simulation/genesis.go index afd393c1c778..d5b0004797e8 100644 --- a/x/staking/simulation/genesis.go +++ b/x/staking/simulation/genesis.go @@ -106,5 +106,5 @@ func RandomizedGenState(simState *module.SimulationState) { panic(err) } fmt.Printf("Selected randomly generated staking parameters:\n%s\n", bz) - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(stakingGenesis) + simState.GenState[types.ModuleName] = stakingGenesis } diff --git a/x/staking/simulation/genesis_test.go b/x/staking/simulation/genesis_test.go index dd60652a87bb..ffc4efb479db 100644 --- a/x/staking/simulation/genesis_test.go +++ b/x/staking/simulation/genesis_test.go @@ -1,10 +1,10 @@ package simulation_test import ( - "encoding/json" "math/rand" "testing" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" sdkmath "cosmossdk.io/math" @@ -34,13 +34,13 @@ func TestRandomizedGenState(t *testing.T) { NumBonded: 3, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), } simulation.RandomizedGenState(&simState) - var stakingGenesis types.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &stakingGenesis) + stakingGenesis, ok := simState.GenState[types.ModuleName].(*types.GenesisState) + require.True(t, ok) require.Equal(t, uint32(207), stakingGenesis.Params.MaxValidators) require.Equal(t, uint32(7), stakingGenesis.Params.MaxEntries) @@ -96,7 +96,7 @@ func TestRandomizedGenState1(t *testing.T) { NumBonded: 4, Accounts: simtypes.RandomAccounts(r, 3), InitialStake: sdkmath.NewInt(1000), - GenState: make(map[string]json.RawMessage), + GenState: make(map[string]proto.Message), }, "invalid memory address or nil pointer dereference", }, } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 24de870db39c..e43e0d36adc5 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -5,6 +5,7 @@ import ( "encoding/json" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/gogo/protobuf/proto" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cast" @@ -109,13 +110,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(_ sdk.Context, _ proto.Message) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } // DefaultGenesis is an empty object -func (AppModuleBasic) DefaultGenesis(_ codec.JSONCodec) json.RawMessage { - return []byte("{}") +func (AppModuleBasic) DefaultGenesis() proto.Message { + return nil } // ValidateGenesis is always successful, as we ignore the value @@ -124,8 +125,8 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, config client.TxEncodin } // ExportGenesis is always empty, as InitGenesis does nothing either -func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { - return am.DefaultGenesis(cdc) +func (am AppModule) ExportGenesis(_ sdk.Context) proto.Message { + return am.DefaultGenesis() } // ConsensusVersion implements AppModule/ConsensusVersion.