Skip to content

Commit

Permalink
fix: fix x/tokenfactory genesis import denoms reset x/bank existi…
Browse files Browse the repository at this point in the history
…ng denom metadata (#5532)

* fix: fix genesis import denoms replace existing metadata

* test: add unit test

* test: add missing unit test

* chore: add changelog entry
  • Loading branch information
dadamu authored Jun 19, 2023
1 parent 70b2fff commit de18b81
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
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)
}

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

0 comments on commit de18b81

Please sign in to comment.