diff --git a/CHANGELOG.md b/CHANGELOG.md index e86d703d85b..7e5b80584fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/x/tokenfactory/keeper/createdenom.go b/x/tokenfactory/keeper/createdenom.go index 96b00eebc3b..bb456750421 100644 --- a/x/tokenfactory/keeper/createdenom.go +++ b/x/tokenfactory/keeper/createdenom.go @@ -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) + } authorityMetadata := types.DenomAuthorityMetadata{ Admin: creatorAddr, diff --git a/x/tokenfactory/keeper/createdenom_test.go b/x/tokenfactory/keeper/createdenom_test.go index 2140115fc0f..68929d334e6 100644 --- a/x/tokenfactory/keeper/createdenom_test.go +++ b/x/tokenfactory/keeper/createdenom_test.go @@ -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" @@ -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 diff --git a/x/tokenfactory/keeper/genesis_test.go b/x/tokenfactory/keeper/genesis_test.go index cffd1b5927f..209ca023082 100644 --- a/x/tokenfactory/keeper/genesis_test.go +++ b/x/tokenfactory/keeper/genesis_test.go @@ -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"}) } } @@ -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"}) + } + } }