Skip to content

Commit

Permalink
migrate bank description
Browse files Browse the repository at this point in the history
  • Loading branch information
skyargos committed Sep 11, 2023
1 parent 56e2a20 commit 9cc59f3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func transAddrPrefix(ctx sdk.Context, app ShentuApp) (err error) {
if err = transAddrPrefixForFeegrant(ctx, app); err != nil {
return err
}
if err = transDescriptionForBank(ctx, app); err != nil {
return err
}
if err = transAddrPrefixForGov(ctx, app); err != nil {
return err
}
Expand Down Expand Up @@ -414,3 +417,16 @@ func prefixToShentuAddrs(addrs []string) (newAddrs []string, err error) {
}
return newAddrs, err
}

func transDescriptionForBank(ctx sdk.Context, app ShentuApp) (err error) {
baseKeeper := app.BankKeeper.BaseKeeper
metaData := baseKeeper.GetAllDenomMetaData(ctx)

for _, meta := range metaData {
if meta.Description == "The native staking token of the CertiK Chain." {
meta.Description = "The native staking token of the Shentu Chain."
}
baseKeeper.SetDenomMetaData(ctx, meta)
}
return nil
}
23 changes: 23 additions & 0 deletions app/upgrade_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"encoding/json"
"errors"
"io/ioutil"
"reflect"
"regexp"
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestMigrateStore(t *testing.T) {
checkSlashing(t, ctx, app, true)
checkAuth(t, ctx, app, true)
checkAuthz(t, ctx, app, true)
require.NoError(t, checkBank(ctx, app, true))

setConfig("shentu")
err := transAddrPrefix(ctx, *app)
Expand All @@ -72,6 +74,7 @@ func TestMigrateStore(t *testing.T) {
checkSlashing(t, ctx, app, false)
checkAuth(t, ctx, app, false)
checkAuthz(t, ctx, app, false)
require.NoError(t, checkBank(ctx, app, false))

//check for error cases
require.Error(t, transAddrPrefix(ctx, *app))
Expand Down Expand Up @@ -181,6 +184,26 @@ func checkAuthz(t *testing.T, ctx sdk.Context, app *ShentuApp, old bool) {
ck.checkForAuthz(authzkeeper.GrantKey)
}

func checkBank(ctx sdk.Context, app *ShentuApp, old bool) error {
baseKeeper := app.BankKeeper.BaseKeeper
metaData := baseKeeper.GetAllDenomMetaData(ctx)
oldDescription := "The native staking token of the CertiK Chain."
newDescription := "The native staking token of the Shentu Chain."
for _, meta := range metaData {
if old {
if meta.Description != oldDescription {
return errors.New("asd")
}
} else {
if meta.Description != newDescription {
return errors.New("asd")
}
}
}
return nil

}

func (c Checker) checkForAuth(keyPrefix []byte) {
ak := c.app.AccountKeeper
iter := sdk.KVStorePrefixIterator(c.store, keyPrefix)
Expand Down

0 comments on commit 9cc59f3

Please sign in to comment.