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 <alexanderbez@users.noreply.github.com>
This commit is contained in:
Robert Zaremba 2020-12-03 09:39:11 +01:00 committed by GitHub
parent bac31becb3
commit 6040d1b88b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 8 deletions

View File

@ -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.

View File

@ -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)
}

View File

@ -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)

View File

@ -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
}