refactor(x/accounts)!: accounts and auth module use the same account number tracking (#20405)
This commit is contained in:
parent
dbc0e659c0
commit
74d89bf506
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -84,6 +85,12 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(t)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@ -95,6 +96,12 @@ func initFixture(t *testing.T) *fixture {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(t)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
|
||||
@ -107,6 +107,12 @@ func initFixture(tb testing.TB) *fixture {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(tb)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
maccPerms := map[string][]string{
|
||||
pooltypes.ModuleName: {},
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package integration_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
@ -49,6 +50,12 @@ func Example() {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(&testing.T{})
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
@ -147,6 +154,12 @@ func Example_oneModule() {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(&testing.T{})
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -77,6 +78,12 @@ func initFixture(tb testing.TB) *fixture {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(tb)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -81,8 +82,14 @@ func initFixture(tb testing.TB) *fixture {
|
||||
queryRouter := baseapp.NewGRPCQueryRouter()
|
||||
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(&testing.T{})
|
||||
ctrl := gomock.NewController(tb)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
@ -134,7 +135,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
}
|
||||
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(&testing.T{})
|
||||
ctrl := gomock.NewController(tb)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
@ -187,6 +188,12 @@ func initFixture(tb testing.TB) *fixture {
|
||||
|
||||
// set default staking params
|
||||
assert.NilError(tb, stakingKeeper.Params.Set(sdkCtx, types.DefaultParams()))
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
f := fixture{
|
||||
app: integrationApp,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -92,6 +93,12 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(t)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currentNum := accNum
|
||||
accNum++
|
||||
return currentNum, nil
|
||||
})
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
|
||||
@ -107,6 +107,30 @@ func (k Keeper) IsAccountsModuleAccount(
|
||||
return hasAcc
|
||||
}
|
||||
|
||||
func (k Keeper) NextAccountNumber(
|
||||
ctx context.Context,
|
||||
) (accNum uint64, err error) {
|
||||
accNum, err = k.AccountNumber.Next(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return accNum, nil
|
||||
}
|
||||
|
||||
// InitAccountNumberSeqUnsafe use to set accounts account number tracking.
|
||||
// Only use for account number migration.
|
||||
func (k Keeper) InitAccountNumberSeqUnsafe(ctx context.Context, accNum uint64) error {
|
||||
currentNum, err := k.AccountNumber.Peek(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if currentNum > accNum {
|
||||
return fmt.Errorf("cannot set number lower than current account number got %v while current account number is %v", accNum, currentNum)
|
||||
}
|
||||
return k.AccountNumber.Set(ctx, accNum)
|
||||
}
|
||||
|
||||
// Init creates a new account of the given type.
|
||||
func (k Keeper) Init(
|
||||
ctx context.Context,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ante_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@ -79,6 +80,12 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
|
||||
suite.ctx = testCtx.Ctx.WithIsCheckTx(isCheckTx).WithBlockHeight(1)
|
||||
suite.encCfg = moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{})
|
||||
|
||||
accNum := uint64(0)
|
||||
suite.acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currNum := accNum
|
||||
accNum++
|
||||
return currNum, nil
|
||||
})
|
||||
maccPerms := map[string][]string{
|
||||
"fee_collector": nil,
|
||||
"mint": {"minter"},
|
||||
|
||||
@ -22,7 +22,12 @@ func (ak AccountKeeper) NewAccountWithAddress(ctx context.Context, addr sdk.AccA
|
||||
|
||||
// NewAccount sets the next account number to a given account interface
|
||||
func (ak AccountKeeper) NewAccount(ctx context.Context, acc sdk.AccountI) sdk.AccountI {
|
||||
if err := acc.SetAccountNumber(ak.NextAccountNumber(ctx)); err != nil {
|
||||
accNum, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := acc.SetAccountNumber(accNum); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"sort"
|
||||
"sync/atomic"
|
||||
@ -69,6 +70,12 @@ func (suite *DeterministicTestSuite) SetupTest() {
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
suite.acctsModKeeper = acctsModKeeper
|
||||
accNum := uint64(0)
|
||||
suite.acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currNum := accNum
|
||||
accNum++
|
||||
return currNum, nil
|
||||
})
|
||||
|
||||
maccPerms := map[string][]string{
|
||||
"fee_collector": nil,
|
||||
|
||||
@ -29,7 +29,10 @@ func (ak AccountKeeper) InitGenesis(ctx context.Context, data types.GenesisState
|
||||
for _, acc := range accounts {
|
||||
accNum := acc.GetAccountNumber()
|
||||
for lastAccNum == nil || *lastAccNum < accNum {
|
||||
n := ak.NextAccountNumber(ctx)
|
||||
n, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lastAccNum = &n
|
||||
}
|
||||
ak.SetAccount(ctx, acc)
|
||||
|
||||
@ -46,6 +46,8 @@ type AccountKeeperI interface {
|
||||
GetSequence(context.Context, sdk.AccAddress) (uint64, error)
|
||||
|
||||
// Fetch the next account number, and increment the internal counter.
|
||||
//
|
||||
// Deprecated: keep this to avoid breaking api
|
||||
NextAccountNumber(context.Context) uint64
|
||||
|
||||
// GetModulePermissions fetches per-module account permissions
|
||||
@ -97,9 +99,9 @@ type AccountKeeper struct {
|
||||
authority string
|
||||
|
||||
// State
|
||||
Schema collections.Schema
|
||||
Params collections.Item[types.Params]
|
||||
AccountNumber collections.Sequence
|
||||
Schema collections.Schema
|
||||
Params collections.Item[types.Params]
|
||||
|
||||
// Accounts key: AccAddr | value: AccountI | index: AccountsIndex
|
||||
Accounts *collections.IndexedMap[sdk.AccAddress, sdk.AccountI, AccountsIndexes]
|
||||
}
|
||||
@ -133,7 +135,6 @@ 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()
|
||||
@ -181,8 +182,10 @@ func (ak AccountKeeper) GetSequence(ctx context.Context, addr sdk.AccAddress) (u
|
||||
|
||||
// NextAccountNumber returns and increments the global account number counter.
|
||||
// If the global account number is not set, it initializes it with value 0.
|
||||
//
|
||||
// Deprecated: NextAccountNumber is deprecated
|
||||
func (ak AccountKeeper) NextAccountNumber(ctx context.Context) uint64 {
|
||||
n, err := ak.AccountNumber.Next(ctx)
|
||||
n, err := ak.AccountsModKeeper.NextAccountNumber(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -62,6 +63,12 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
suite.acctsModKeeper = acctsModKeeper
|
||||
accNum := uint64(0)
|
||||
suite.acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currNum := accNum
|
||||
accNum++
|
||||
return currNum, nil
|
||||
})
|
||||
|
||||
maccPerms := map[string][]string{
|
||||
"fee_collector": nil,
|
||||
@ -202,7 +209,8 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
|
||||
suite.Require().Equal(6, int(feeCollector.GetAccountNumber()))
|
||||
|
||||
// The 3rd account has account number 5, but because the FeeCollector account gets initialized last, the next should be 7.
|
||||
nextNum := suite.accountKeeper.NextAccountNumber(ctx)
|
||||
nextNum, err := suite.accountKeeper.AccountsModKeeper.NextAccountNumber(ctx)
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(7, int(nextNum))
|
||||
|
||||
suite.SetupTest() // reset
|
||||
@ -237,7 +245,8 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
|
||||
feeCollector = suite.accountKeeper.GetModuleAccount(ctx, "fee_collector")
|
||||
suite.Require().Equal(1, int(feeCollector.GetAccountNumber()))
|
||||
|
||||
nextNum = suite.accountKeeper.NextAccountNumber(ctx)
|
||||
nextNum, err = suite.accountKeeper.AccountsModKeeper.NextAccountNumber(ctx)
|
||||
suite.Require().NoError(err)
|
||||
// we expect nextNum to be 2 because we initialize fee_collector as account number 1
|
||||
suite.Require().Equal(2, int(nextNum))
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package keeper
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
v5 "cosmossdk.io/x/auth/migrations/v5"
|
||||
"cosmossdk.io/x/auth/types"
|
||||
|
||||
@ -12,11 +13,16 @@ 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 {
|
||||
return Migrator{keeper: keeper}
|
||||
sb := collections.NewSchemaBuilder(keeper.Environment.KVStoreService)
|
||||
accNumSeq := collections.NewSequence(sb, types.GlobalAccountNumberKey, "account_number")
|
||||
|
||||
return Migrator{keeper: keeper, accNum: accNumSeq}
|
||||
}
|
||||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
@ -42,7 +48,18 @@ 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.keeper.AccountNumber)
|
||||
return v5.Migrate(ctx, m.keeper.KVStoreService, m.accNum)
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.keeper.AccountsModKeeper.InitAccountNumberSeqUnsafe(ctx, currentAccNum)
|
||||
}
|
||||
|
||||
// V45SetAccount implements V45_SetAccount
|
||||
|
||||
12
x/auth/migrations/v6/migrate.go
Normal file
12
x/auth/migrations/v6/migrate.go
Normal file
@ -0,0 +1,12 @@
|
||||
package v6
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type migrateAccNumFunc = func(ctx context.Context) error
|
||||
|
||||
// Migrate account number from x/auth account number to x/accounts account number
|
||||
func Migrate(ctx context.Context, f migrateAccNumFunc) error {
|
||||
return f(ctx)
|
||||
}
|
||||
@ -23,7 +23,7 @@ import (
|
||||
|
||||
// ConsensusVersion defines the current x/auth module consensus version.
|
||||
const (
|
||||
ConsensusVersion = 5
|
||||
ConsensusVersion = 6
|
||||
GovModuleName = "gov"
|
||||
)
|
||||
|
||||
@ -109,6 +109,9 @@ func (am AppModule) RegisterMigrations(mr appmodule.MigrationRegistrar) error {
|
||||
if err := mr.Register(types.ModuleName, 4, m.Migrate4To5); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 4 to 5: %w", types.ModuleName, err)
|
||||
}
|
||||
if err := mr.Register(types.ModuleName, 5, m.Migrate5To6); err != nil {
|
||||
return fmt.Errorf("failed to migrate x/%s from version 5 to 6: %w", types.ModuleName, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -106,6 +106,20 @@ func (m *MockAccountsModKeeper) EXPECT() *MockAccountsModKeeperMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// InitAccountNumberSeqUnsafe mocks base method.
|
||||
func (m *MockAccountsModKeeper) InitAccountNumberSeqUnsafe(ctx context.Context, currentAccNum uint64) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "InitAccountNumberSeqUnsafe", ctx, currentAccNum)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// InitAccountNumberSeqUnsafe indicates an expected call of InitAccountNumberSeqUnsafe.
|
||||
func (mr *MockAccountsModKeeperMockRecorder) InitAccountNumberSeqUnsafe(ctx, currentAccNum interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitAccountNumberSeqUnsafe", reflect.TypeOf((*MockAccountsModKeeper)(nil).InitAccountNumberSeqUnsafe), ctx, currentAccNum)
|
||||
}
|
||||
|
||||
// IsAccountsModuleAccount mocks base method.
|
||||
func (m *MockAccountsModKeeper) IsAccountsModuleAccount(ctx context.Context, accountAddr []byte) bool {
|
||||
m.ctrl.T.Helper()
|
||||
@ -120,6 +134,21 @@ func (mr *MockAccountsModKeeperMockRecorder) IsAccountsModuleAccount(ctx, accoun
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountsModKeeper)(nil).IsAccountsModuleAccount), ctx, accountAddr)
|
||||
}
|
||||
|
||||
// NextAccountNumber mocks base method.
|
||||
func (m *MockAccountsModKeeper) NextAccountNumber(ctx context.Context) (uint64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NextAccountNumber", ctx)
|
||||
ret0, _ := ret[0].(uint64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// NextAccountNumber indicates an expected call of NextAccountNumber.
|
||||
func (mr *MockAccountsModKeeperMockRecorder) NextAccountNumber(ctx interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NextAccountNumber", reflect.TypeOf((*MockAccountsModKeeper)(nil).NextAccountNumber), ctx)
|
||||
}
|
||||
|
||||
// SendModuleMessageUntyped mocks base method.
|
||||
func (m *MockAccountsModKeeper) SendModuleMessageUntyped(ctx context.Context, sender []byte, msg protoiface.MessageV1) (protoiface.MessageV1, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -19,4 +19,9 @@ type BankKeeper interface {
|
||||
type AccountsModKeeper interface {
|
||||
SendModuleMessageUntyped(ctx context.Context, sender []byte, msg protoiface.MessageV1) (protoiface.MessageV1, error)
|
||||
IsAccountsModuleAccount(ctx context.Context, accountAddr []byte) bool
|
||||
NextAccountNumber(ctx context.Context) (accNum uint64, err error)
|
||||
|
||||
// InitAccountNumberSeqUnsafe is use to set accounts module account number with value
|
||||
// of auth module current account number
|
||||
InitAccountNumberSeqUnsafe(ctx context.Context, currentAccNum uint64) error
|
||||
}
|
||||
|
||||
@ -106,6 +106,20 @@ func (m *MockAccountsModKeeper) EXPECT() *MockAccountsModKeeperMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// InitAccountNumberSeqUnsafe mocks base method.
|
||||
func (m *MockAccountsModKeeper) InitAccountNumberSeqUnsafe(ctx context.Context, currentAccNum uint64) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "InitAccountNumberSeqUnsafe", ctx, currentAccNum)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// InitAccountNumberSeqUnsafe indicates an expected call of InitAccountNumberSeqUnsafe.
|
||||
func (mr *MockAccountsModKeeperMockRecorder) InitAccountNumberSeqUnsafe(ctx, currentAccNum interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitAccountNumberSeqUnsafe", reflect.TypeOf((*MockAccountsModKeeper)(nil).InitAccountNumberSeqUnsafe), ctx, currentAccNum)
|
||||
}
|
||||
|
||||
// IsAccountsModuleAccount mocks base method.
|
||||
func (m *MockAccountsModKeeper) IsAccountsModuleAccount(ctx context.Context, accountAddr []byte) bool {
|
||||
m.ctrl.T.Helper()
|
||||
@ -120,6 +134,21 @@ func (mr *MockAccountsModKeeperMockRecorder) IsAccountsModuleAccount(ctx, accoun
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountsModKeeper)(nil).IsAccountsModuleAccount), ctx, accountAddr)
|
||||
}
|
||||
|
||||
// NextAccountNumber mocks base method.
|
||||
func (m *MockAccountsModKeeper) NextAccountNumber(ctx context.Context) (uint64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NextAccountNumber", ctx)
|
||||
ret0, _ := ret[0].(uint64)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// NextAccountNumber indicates an expected call of NextAccountNumber.
|
||||
func (mr *MockAccountsModKeeperMockRecorder) NextAccountNumber(ctx interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NextAccountNumber", reflect.TypeOf((*MockAccountsModKeeper)(nil).NextAccountNumber), ctx)
|
||||
}
|
||||
|
||||
// SendModuleMessageUntyped mocks base method.
|
||||
func (m *MockAccountsModKeeper) SendModuleMessageUntyped(ctx context.Context, sender []byte, msg protoiface.MessageV1) (protoiface.MessageV1, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package v4_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -53,6 +54,13 @@ func TestFundsMigration(t *testing.T) {
|
||||
stakingKeeper := distrtestutil.NewMockStakingKeeper(ctrl)
|
||||
poolKeeper := distrtestutil.NewMockPoolKeeper(ctrl)
|
||||
|
||||
accNum := uint64(0)
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(gomock.Any()).AnyTimes().DoAndReturn(func(ctx context.Context) (uint64, error) {
|
||||
currNum := accNum
|
||||
accNum++
|
||||
return currNum, nil
|
||||
})
|
||||
|
||||
// create account keeper
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()),
|
||||
|
||||
@ -52,7 +52,7 @@ func TestMigrate(t *testing.T) {
|
||||
tKey := storetypes.NewTransientStoreKey("transient_test")
|
||||
ctx := testutil.DefaultContext(storeKey, tKey)
|
||||
|
||||
oldAccs, accountKeeper, err := createOldPolicyAccount(ctx, storeKey, cdc, policies)
|
||||
oldAccs, accountKeeper, err := createOldPolicyAccount(t, ctx, storeKey, cdc, policies)
|
||||
require.NoError(t, err)
|
||||
groupPolicyTable, groupPolicySeq, err := createGroupPolicies(ctx, storeService, cdc, policies, codectestutil.CodecOptions{}.GetAddressCodec())
|
||||
require.NoError(t, err)
|
||||
@ -105,15 +105,18 @@ func createGroupPolicies(ctx sdk.Context, storeService corestore.KVStoreService,
|
||||
}
|
||||
|
||||
// createOldPolicyAccount re-creates the group policy account using a module account
|
||||
func createOldPolicyAccount(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Codec, policies []sdk.AccAddress) ([]*authtypes.ModuleAccount, group.AccountKeeper, error) {
|
||||
func createOldPolicyAccount(t *testing.T, ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Codec, policies []sdk.AccAddress) ([]*authtypes.ModuleAccount, group.AccountKeeper, error) {
|
||||
t.Helper()
|
||||
addressCodec := addresscodec.NewBech32Codec(sdk.Bech32MainPrefix)
|
||||
authorityStrAddr, err := addressCodec.BytesToString(authorityAddr)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(&testing.T{})
|
||||
ctrl := gomock.NewController(t)
|
||||
acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl)
|
||||
// mock account number
|
||||
accNum := uint64(0)
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), log.NewNopLogger()), cdc, authtypes.ProtoBaseAccount, acctsModKeeper, nil, addressCodec, sdk.Bech32MainPrefix, authorityStrAddr)
|
||||
|
||||
@ -123,6 +126,9 @@ func createOldPolicyAccount(ctx sdk.Context, storeKey storetypes.StoreKey, cdc c
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
acctsModKeeper.EXPECT().NextAccountNumber(ctx).Return(accNum, nil)
|
||||
accNum++
|
||||
|
||||
acc := accountKeeper.NewAccount(ctx, &authtypes.ModuleAccount{
|
||||
BaseAccount: &authtypes.BaseAccount{
|
||||
Address: policyStrAddr,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user