Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate bank description #770

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
if err = transAddrPrefixForFeegrant(ctx, app); err != nil {
return err
}
if err = transDescriptionForBank(ctx, app); err != nil {
return err
}

Check warning on line 72 in app/upgrade_handler.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade_handler.go#L71-L72

Added lines #L71 - L72 were not covered by tests
if err = transAddrPrefixForGov(ctx, app); err != nil {
return err
}
Expand Down Expand Up @@ -414,3 +417,14 @@
}
return newAddrs, err
}

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

for _, meta := range metaData {
meta.Description = "The native staking token of the Shentu Chain."
baseKeeper.SetDenomMetaData(ctx, meta)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this line in the if statement?

Copy link
Contributor Author

@skyargos skyargos Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also remove the if directly and assign the value directly.
Because although it is an array at present, the length is only 1 and will not affect other

}
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("bank migration error")
}
} else {
if meta.Description != newDescription {
return errors.New("bank migration error")
}
}
}
return nil

}

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