Skip to content

Commit

Permalink
fix(x/migrate): IterateMigrateRecords key value prefix (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir-code authored Sep 3, 2024
1 parent ca1c073 commit b97c663
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions x/migrate/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func (k Keeper) IterateMigrateRecords(ctx sdk.Context, cb func(types.MigrateReco
defer iter.Close()

for ; iter.Valid(); iter.Next() {
if bytes.Equal(iter.Value()[1+addressLen+1:], types.ValuePrefixMigrateToFlag) {
if bytes.Equal(iter.Value()[:1], types.ValuePrefixMigrateToFlag) {
continue
}
if cb(types.MigrateRecord{
From: sdk.AccAddress(iter.Key()).String(),
From: sdk.AccAddress(iter.Key()[1:]).String(),
To: common.BytesToAddress(iter.Value()[1 : addressLen+1]).String(),
Height: int64(sdk.BigEndianToUint64(iter.Value()[1+addressLen:])),
}) {
Expand Down
10 changes: 10 additions & 0 deletions x/migrate/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ func (suite *KeeperTestSuite) TestMigrateAccount() {
suite.Require().True(bb1.Empty())
bb2 := suite.app.BankKeeper.GetAllBalances(suite.ctx, ethAcc.Bytes())
suite.Require().Equal(b1, bb2.Sub(b2...))

// expect 1 record
recordCount := 0
suite.app.MigrateKeeper.IterateMigrateRecords(suite.ctx, func(record types.MigrateRecord) bool {
suite.Require().Equal(record.From, acc.String())
suite.Require().Equal(record.To, ethAcc.String())
recordCount++
return false
})
suite.Require().Equal(recordCount, 1)
}

0 comments on commit b97c663

Please sign in to comment.