Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix x/tokenfactory genesis import denoms reset x/bank existing denom metadata #5532

Merged
merged 4 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions x/tokenfactory/keeper/createdenom.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, subdenom string
// Runs CreateDenom logic after the charge and all denom validation has been handled.
// Made into a second function for genesis initialization.
func (k Keeper) createDenomAfterValidation(ctx sdk.Context, creatorAddr string, denom string) (err error) {
denomMetaData := banktypes.Metadata{
DenomUnits: []*banktypes.DenomUnit{{
Denom: denom,
Exponent: 0,
}},
Base: denom,
}
_, exists := k.bankKeeper.GetDenomMetaData(ctx, denom)
if !exists {
denomMetaData := banktypes.Metadata{
DenomUnits: []*banktypes.DenomUnit{{
Denom: denom,
Exponent: 0,
}},
Base: denom,
}

k.bankKeeper.SetDenomMetaData(ctx, denomMetaData)
k.bankKeeper.SetDenomMetaData(ctx, denomMetaData)
Comment on lines +31 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can unit tests for CreateDenom be added to confirm the new logic introduced as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the unit test to check CreateDenom if the metadata is set correctly, the metadata existing case is already covered by this test

}

authorityMetadata := types.DenomAuthorityMetadata{
Admin: creatorAddr,
Expand Down
13 changes: 12 additions & 1 deletion x/tokenfactory/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *KeeperTestSuite) TestGenesis() {
for i, denom := range genesisState.FactoryDenoms {
// hacky, sets bank metadata to exist if i != 0, to cover both cases.
if i != 0 {
app.BankKeeper.SetDenomMetaData(s.Ctx, banktypes.Metadata{Base: denom.GetDenom()})
app.BankKeeper.SetDenomMetaData(s.Ctx, banktypes.Metadata{Base: denom.GetDenom(), Display: "test"})
}
}

Expand All @@ -56,4 +56,15 @@ func (s *KeeperTestSuite) TestGenesis() {
exportedGenesis := app.TokenFactoryKeeper.ExportGenesis(s.Ctx)
s.Require().NotNil(exportedGenesis)
s.Require().Equal(genesisState, *exportedGenesis)

app.BankKeeper.SetParams(s.Ctx, banktypes.DefaultParams())
app.BankKeeper.InitGenesis(s.Ctx, app.BankKeeper.ExportGenesis(s.Ctx))
for i, denom := range genesisState.FactoryDenoms {
// hacky, check whether bank metadata is not replaced if i != 0, to cover both cases.
if i != 0 {
metadata, found := app.BankKeeper.GetDenomMetaData(s.Ctx, denom.GetDenom())
s.Require().True(found)
s.Require().Equal(metadata, banktypes.Metadata{Base: denom.GetDenom(), Display: "test"})
}
}
}