Skip to content

Commit

Permalink
fix system test
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 committed Jun 3, 2024
1 parent 13cd0df commit 9c3170a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 4 additions & 3 deletions x/auth/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ type AccountKeeper struct {
authority string

// State
Schema collections.Schema
Params collections.Item[types.Params]

Schema collections.Schema
Params collections.Item[types.Params]
AccountNumber collections.Sequence
// Accounts key: AccAddr | value: AccountI | index: AccountsIndex
Accounts *collections.IndexedMap[sdk.AccAddress, sdk.AccountI, AccountsIndexes]
}
Expand Down Expand Up @@ -135,6 +135,7 @@ func NewAccountKeeper(
permAddrs: permAddrs,
authority: authority,
Params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)),
AccountNumber: collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number"),
Accounts: collections.NewIndexedMap(sb, types.AddressStoreKeyPrefix, "accounts", sdk.AccAddressKey, codec.CollInterfaceValue[sdk.AccountI](cdc), NewAccountIndexes(sb)),
}
schema, err := sb.Build()
Expand Down
12 changes: 3 additions & 9 deletions x/auth/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"context"

"cosmossdk.io/collections"
v5 "cosmossdk.io/x/auth/migrations/v5"
"cosmossdk.io/x/auth/types"

Expand All @@ -13,16 +12,11 @@ import (
// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper AccountKeeper
// accNum is use in v4 to v5 and v5 to v6 migration
accNum collections.Sequence
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper AccountKeeper) Migrator {
sb := collections.NewSchemaBuilder(keeper.Environment.KVStoreService)
accNumSeq := collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number")

return Migrator{keeper: keeper, accNum: accNumSeq}
return Migrator{keeper: keeper}
}

// Migrate1to2 migrates from version 1 to 2.
Expand All @@ -48,13 +42,13 @@ func (m Migrator) Migrate3to4(ctx context.Context) error {
// It migrates the GlobalAccountNumber from being a protobuf defined value to a
// big-endian encoded uint64, it also migrates it to use a more canonical prefix.
func (m Migrator) Migrate4To5(ctx context.Context) error {
return v5.Migrate(ctx, m.keeper.KVStoreService, m.accNum)
return v5.Migrate(ctx, m.keeper.KVStoreService, m.keeper.AccountNumber)
}

// Migrate5To6 migrates the x/auth module state from the consensus version 5 to 6.
// It migrates the GlobalAccountNumber from x/auth to x/accounts .
func (m Migrator) Migrate5To6(ctx context.Context) error {
currentAccNum, err := m.accNum.Peek(ctx)
currentAccNum, err := m.keeper.AccountNumber.Peek(ctx)
if err != nil {
return err
}
Expand Down

0 comments on commit 9c3170a

Please sign in to comment.