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 all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### State Breaking

* [#5532](https://github.com/osmosis-labs/osmosis/pull/5532) fix: Fix x/tokenfactory genesis import denoms reset x/bank existing denom metadata

## v16.0.0
Osmosis Labs is excited to announce the release of v16.0.0, a major upgrade that includes a number of new features and improvements like introduction of new modules, updates existing APIs, and dependency updates. This upgrade aims to enhance capital efficiency by introducing SuperCharged Liquidity, introduce custom liquidity pools backed by CosmWasm smart contracts, and improve overall functionality.

Expand Down
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
12 changes: 12 additions & 0 deletions x/tokenfactory/keeper/createdenom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"github.com/osmosis-labs/osmosis/v16/app/apptesting"
"github.com/osmosis-labs/osmosis/v16/x/tokenfactory/types"
Expand Down Expand Up @@ -164,6 +165,17 @@ func (s *KeeperTestSuite) TestCreateDenom() {

s.Require().NoError(err)
s.Require().Equal(s.TestAccs[0].String(), queryRes.AuthorityMetadata.Admin)

// Make sure that the denom metadata is initialized correctly
metadata, found := bankKeeper.GetDenomMetaData(s.Ctx, res.GetNewTokenDenom())
s.Require().True(found)
s.Require().Equal(banktypes.Metadata{
DenomUnits: []*banktypes.DenomUnit{{
Denom: res.GetNewTokenDenom(),
Exponent: 0,
}},
Base: res.GetNewTokenDenom(),
}, metadata)
} else {
s.Require().Error(err)
// Ensure we don't charge if we expect an error
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"})
}
}
}