From 6040d1b88b648375eb5c93de27c897ce71d3f231 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Thu, 3 Dec 2020 09:39:11 +0100 Subject: [PATCH] fix: Metadata is not initialized in x/bank InitGenesis #7951 (#8065) * fix: Metadata is not initialized in x/bank InitGenesis #7951 * remove commented code Co-authored-by: Aleksandr Bezobchuk --- x/bank/keeper/genesis.go | 6 +++++- x/bank/keeper/genesis_test.go | 16 ++++++++++++++-- x/bank/keeper/keeper.go | 3 +-- x/bank/module.go | 6 +++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/x/bank/keeper/genesis.go b/x/bank/keeper/genesis.go index 7397d8d5b6e..d30415c6a28 100644 --- a/x/bank/keeper/genesis.go +++ b/x/bank/keeper/genesis.go @@ -8,7 +8,7 @@ import ( ) // InitGenesis initializes the bank module's state from a given genesis state. -func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { +func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { k.SetParams(ctx, genState.Params) var totalSupply sdk.Coins @@ -32,6 +32,10 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { } k.SetSupply(ctx, types.NewSupply(genState.Supply)) + + for _, meta := range genState.DenomMetadata { + k.SetDenomMetaData(ctx, meta) + } } // ExportGenesis returns the bank module's genesis state. diff --git a/x/bank/keeper/genesis_test.go b/x/bank/keeper/genesis_test.go index 8bd46d68171..bdb8cdc304e 100644 --- a/x/bank/keeper/genesis_test.go +++ b/x/bank/keeper/genesis_test.go @@ -37,8 +37,20 @@ func (suite *IntegrationTestSuite) getTestBalances() []types.Balance { addr2, _ := sdk.AccAddressFromBech32("cosmos1f9xjhxm0plzrh9cskf4qee4pc2xwp0n0556gh0") addr1, _ := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh") return []types.Balance{ - {addr2.String(), sdk.Coins{sdk.NewInt64Coin("testcoin1", 32), sdk.NewInt64Coin("testcoin2", 34)}}, - {addr1.String(), sdk.Coins{sdk.NewInt64Coin("testcoin3", 10)}}, + {Address: addr2.String(), Coins: sdk.Coins{sdk.NewInt64Coin("testcoin1", 32), sdk.NewInt64Coin("testcoin2", 34)}}, + {Address: addr1.String(), Coins: sdk.Coins{sdk.NewInt64Coin("testcoin3", 10)}}, } } + +func (suite *IntegrationTestSuite) TestInitGenesis() { + require := suite.Require() + m := types.Metadata{Description: sdk.DefaultBondDenom, Base: sdk.DefaultBondDenom, Display: sdk.DefaultBondDenom} + g := types.DefaultGenesisState() + g.DenomMetadata = []types.Metadata{m} + bk := suite.app.BankKeeper + bk.InitGenesis(suite.ctx, g) + + m2 := bk.GetDenomMetaData(suite.ctx, m.Base) + require.Equal(m, m2) +} diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 6594398aa51..2fd76ea58c3 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -22,7 +22,7 @@ var _ Keeper = (*BaseKeeper)(nil) type Keeper interface { SendKeeper - InitGenesis(sdk.Context, types.GenesisState) + InitGenesis(sdk.Context, *types.GenesisState) ExportGenesis(sdk.Context) *types.GenesisState GetSupply(ctx sdk.Context) exported.SupplyI @@ -186,7 +186,6 @@ func (k BaseKeeper) GetDenomMetaData(ctx sdk.Context, denom string) types.Metada store = prefix.NewStore(store, types.DenomMetadataKey(denom)) bz := store.Get([]byte(denom)) - var metadata types.Metadata k.cdc.MustUnmarshalBinaryBare(bz, &metadata) diff --git a/x/bank/module.go b/x/bank/module.go index 32f7431f26f..bc998634c12 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -52,7 +52,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONMarshaler) json.RawMessage { } // ValidateGenesis performs genesis state validation for the bank module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxEncodingConfig, bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, _ client.TxEncodingConfig, bz json.RawMessage) error { var data types.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) @@ -140,7 +140,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j cdc.MustUnmarshalJSON(data, &genesisState) telemetry.MeasureSince(start, "InitGenesis", "crisis", "unmarshal") - am.keeper.InitGenesis(ctx, genesisState) + am.keeper.InitGenesis(ctx, &genesisState) return []abci.ValidatorUpdate{} } @@ -170,7 +170,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { } // ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { return nil }