Skip to content

Commit

Permalink
fix: bank store migration (cosmos#13821)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwme authored Nov 10, 2022
1 parent a5e8e2d commit d314a12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion x/bank/migrations/v3/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func migrateDenomMetadata(store sdk.KVStore, logger log.Logger) error {

for ; oldDenomMetaDataIter.Valid(); oldDenomMetaDataIter.Next() {
oldKey := oldDenomMetaDataIter.Key()
l := len(oldKey)/2 + 1
l := len(oldKey) / 2

newKey := make([]byte, len(types.DenomMetadataPrefix)+l)
// old key: prefix_bytes | denom_bytes | denom_bytes
Expand Down
6 changes: 3 additions & 3 deletions x/bank/migrations/v3/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func TestMigrateDenomMetaData(t *testing.T) {
denomMetadataStore := prefix.NewStore(store, v2.DenomMetadataPrefix)

for i := range []int{0, 1} {
key := append(v2.DenomMetadataPrefix, []byte(metaData[i].Base)...)
// keys before 0.45 had denom two times in the key
key := append([]byte{}, []byte(metaData[i].Base)...)
key = append(key, []byte(metaData[i].Base)...)
bz, err := encCfg.Codec.Marshal(&metaData[i])
require.NoError(t, err)
Expand All @@ -107,11 +107,11 @@ func TestMigrateDenomMetaData(t *testing.T) {
newKey := denomMetadataIter.Key()

// make sure old entry is deleted
oldKey := append(newKey, newKey[1:]...)
oldKey := append(newKey, newKey[0:]...)
bz := denomMetadataStore.Get(oldKey)
require.Nil(t, bz)

require.Equal(t, string(newKey)[1:], metaData[i].Base, "idx: %d", i)
require.Equal(t, string(newKey), metaData[i].Base, "idx: %d", i)
bz = denomMetadataStore.Get(denomMetadataIter.Key())
require.NotNil(t, bz)
err := encCfg.Codec.Unmarshal(bz, &result)
Expand Down

0 comments on commit d314a12

Please sign in to comment.