Skip to content

Commit

Permalink
fix: Metadata is not initialized in x/bank InitGenesis #7951 (#8065)
Browse files Browse the repository at this point in the history
* fix: Metadata is not initialized in x/bank InitGenesis #7951

* remove commented code

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
  • Loading branch information
robert-zaremba and alexanderbez authored Dec 3, 2020
1 parent bac31be commit 6040d1b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 5 additions & 1 deletion x/bank/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{}
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 6040d1b

Please sign in to comment.