From 144b5e842b789f9b8482593130a2ea895ba4eb21 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Mon, 12 Jun 2023 19:16:57 +0800 Subject: [PATCH 1/4] fix: fix genesis import denoms replace existing metadata --- x/tokenfactory/keeper/createdenom.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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, From 46f01feddb6d291acca781b2928aa1a4c64b1c0c Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 15 Jun 2023 16:15:10 +0800 Subject: [PATCH 2/4] test: add unit test --- x/tokenfactory/keeper/genesis_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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"}) + } + } } From 1bafa84eb57726f1537d25526bf89b7d93936435 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 15 Jun 2023 17:49:40 +0800 Subject: [PATCH 3/4] test: add missing unit test --- x/tokenfactory/keeper/createdenom_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 From 49a938bdeca49a5bb7ccfdc1d1f8b184b86ccae2 Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Thu, 15 Jun 2023 18:03:57 +0800 Subject: [PATCH 4/4] chore: add changelog entry --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a08d9918b2c..550ae431d6a 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.