From 1f9776e3817eee4d8c91905d7d62447591d839ba Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Thu, 23 Jun 2022 19:27:02 +0530 Subject: [PATCH 1/3] feat: add regen denom metadata migration --- app/denom_metadata_migration_test.go | 101 +++++++++++++++++++++++++++ app/stable_appconfig.go | 18 +++++ 2 files changed, 119 insertions(+) create mode 100644 app/denom_metadata_migration_test.go diff --git a/app/denom_metadata_migration_test.go b/app/denom_metadata_migration_test.go new file mode 100644 index 0000000000..9914b34b79 --- /dev/null +++ b/app/denom_metadata_migration_test.go @@ -0,0 +1,101 @@ +//go:build !experimental +// +build !experimental + +package app + +import ( + "encoding/json" + "os" + "testing" + + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + dbm "github.com/tendermint/tm-db" +) + +func TestMigrateDenomMetadata(t *testing.T) { + encCfg := MakeEncodingConfig() + db := dbm.NewMemDB() + + regenApp := NewRegenApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, + DefaultNodeHome, 0, encCfg, simapp.EmptyAppOptions{}, nil) + bz := NewDefaultGenesisState(encCfg.Marshaler) + stateBytes, err := json.MarshalIndent(bz, "", " ") + require.NoError(t, err) + + regenApp.InitChain( + abci.RequestInitChain{ + Validators: []abci.ValidatorUpdate{}, + AppStateBytes: stateBytes, + }, + ) + + ctx := regenApp.BaseApp.NewContext(false, tmproto.Header{}) + regenApp.BankKeeper.SetDenomMetaData(ctx, types.Metadata{ + Description: "The native staking token of Regen Network", + Base: "uregen", + Display: "regen", + DenomUnits: []*types.DenomUnit{ + { + Denom: "uregen", + Exponent: 0, + Aliases: []string{"microregen"}, + }, + { + Denom: "mregen", + Exponent: 3, + Aliases: []string{"milliregen"}, + }, + { + Denom: "regen", + Exponent: 6, + }, + }, + }) + + regenApp.BankKeeper.SetDenomMetaData(ctx, types.Metadata{ + Description: "The native staking token of Cosmos Hub", + Base: "uatom", + Display: "atom", + DenomUnits: []*types.DenomUnit{ + { + Denom: "uatom", + Exponent: 0, + Aliases: []string{"microatom"}, + }, + { + Denom: "matom", + Exponent: 3, + Aliases: []string{"milliatom"}, + }, + { + Denom: "atom", + Exponent: 6, + }, + }, + Name: "Cosmos Atom", + Symbol: "ATOM", + }) + + metadata, found := regenApp.BankKeeper.GetDenomMetaData(ctx, "uregen") + require.True(t, found) + require.Equal(t, metadata.Name, "") + require.Equal(t, metadata.Symbol, "") + + err = migrateDenomMetadata(ctx, regenApp.BankKeeper) + require.NoError(t, err) + + metadata, found = regenApp.BankKeeper.GetDenomMetaData(ctx, "uregen") + require.True(t, found) + require.Equal(t, metadata.Name, "Regen") + require.Equal(t, metadata.Symbol, "REGEN") + + metadata, found = regenApp.BankKeeper.GetDenomMetaData(ctx, "uatom") + require.True(t, found) + require.Equal(t, metadata.Name, "Cosmos Atom") + require.Equal(t, metadata.Symbol, "ATOM") +} diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index e899f9f0e6..4fb5a360ee 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -98,9 +98,27 @@ func (app *RegenApp) registerUpgradeHandlers() { } } + // add name and symbol to regen denom metadata + if err := migrateDenomMetadata(ctx, app.BankKeeper); err != nil { + return nil, err + } + return toVersion, nil }) +} +func migrateDenomMetadata(ctx sdk.Context, bk bankkeeper.Keeper) error { + denom := "uregen" + metadata, found := bk.GetDenomMetaData(ctx, denom) + if !found { + return fmt.Errorf("metadata is present for %s denom", denom) + } + + metadata.Name = "Regen" + metadata.Symbol = "REGEN" + bk.SetDenomMetaData(ctx, metadata) + + return nil } func recoverFunds(ctx sdk.Context, ak authkeeper.AccountKeeper, bk bankkeeper.Keeper) error { From 63f83a788fed13ac7c178141c05d46f23498b6a8 Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Thu, 23 Jun 2022 21:53:52 +0530 Subject: [PATCH 2/3] Update app/stable_appconfig.go Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com> --- app/stable_appconfig.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index 4fb5a360ee..23c717d975 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -111,7 +111,7 @@ func migrateDenomMetadata(ctx sdk.Context, bk bankkeeper.Keeper) error { denom := "uregen" metadata, found := bk.GetDenomMetaData(ctx, denom) if !found { - return fmt.Errorf("metadata is present for %s denom", denom) + return fmt.Errorf("no metadata found for %s denom", denom) } metadata.Name = "Regen" From 7c2212452f3ac0c3e694b30ad7538c9b44676eb3 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Thu, 23 Jun 2022 18:49:43 -0700 Subject: [PATCH 3/3] fix merge --- app/stable_appconfig.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/stable_appconfig.go b/app/stable_appconfig.go index df19445f23..7815adcb09 100644 --- a/app/stable_appconfig.go +++ b/app/stable_appconfig.go @@ -103,6 +103,7 @@ func (app *RegenApp) registerUpgradeHandlers() { // add name and symbol to regen denom metadata if err := migrateDenomMetadata(ctx, app.BankKeeper); err != nil { return nil, err + } // update denom unit order for basket tokens if ctx.ChainID() == "regen-redwood-1" {