From def0712c4aa2fc38c387cc47d1787bb63bc74353 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Mon, 8 Apr 2024 20:43:35 +0700 Subject: [PATCH 1/8] add check if account is x/accounts account --- x/accounts/keeper.go | 13 ++++++++++ x/auth/ante/testutil_test.go | 2 +- x/auth/depinject.go | 3 ++- x/auth/keeper/account.go | 6 +++++ x/auth/keeper/deterministic_test.go | 3 +++ x/auth/keeper/keeper.go | 26 +++++++++++--------- x/auth/keeper/keeper_test.go | 1 + x/auth/types/expected_keepers.go | 5 ++++ x/auth/vesting/types/vesting_account_test.go | 2 +- x/bank/keeper/keeper.go | 6 +++++ x/bank/testutil/expected_keepers_mocks.go | 14 +++++++++++ x/bank/types/expected_keepers.go | 2 ++ 12 files changed, 68 insertions(+), 15 deletions(-) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 6a4779499819..b22c08ac02ec 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -126,6 +126,19 @@ type Keeper struct { AccountsState collections.Map[collections.Pair[uint64, []byte], []byte] } +// GetAccountNumber return a account number by address. +func (k Keeper) GetAccountNumber( + ctx context.Context, + accountAddr []byte, +) (uint64, error) { + accNum, err := k.AccountByNumber.Get(ctx, accountAddr) + if err != nil { + return 0, err + } + + return accNum, nil +} + // Init creates a new account of the given type. func (k Keeper) Init( ctx context.Context, diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 1814e94f2b29..85ff7257dbcb 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -81,7 +81,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { suite.accountKeeper = keeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), - sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), + sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), nil, ) suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName) err := suite.accountKeeper.Params.Set(suite.ctx, types.DefaultParams()) diff --git a/x/auth/depinject.go b/x/auth/depinject.go index 67d75e7c902a..866e4ae2f512 100644 --- a/x/auth/depinject.go +++ b/x/auth/depinject.go @@ -27,6 +27,7 @@ func init() { type ModuleInputs struct { depinject.In + AccountsKeeper types.AccountsKeeper Config *modulev1.Module Environment appmodule.Environment @@ -69,7 +70,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { panic(err) } - k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth) + k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth, in.AccountsKeeper) m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn) return ModuleOutputs{AccountKeeper: k, Module: m} diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index bdd36d12450f..4f984380eec1 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -60,3 +60,9 @@ func (ak AccountKeeper) RemoveAccount(ctx context.Context, acc sdk.AccountI) { panic(err) } } + +// IsAccountsModuleAccount check an address belong to an x/accounts account +func (ak AccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr sdk.AccAddress) bool { + _, err := ak.AccountsKeeper.GetAccountNumber(ctx, addr) + return err != nil +} diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 61baa01c2835..f6f7657f50b7 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -79,6 +79,7 @@ func (suite *DeterministicTestSuite) SetupTest() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) @@ -299,6 +300,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) suite.setModuleAccounts(suite.ctx, ak, maccs) @@ -346,6 +348,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) suite.setModuleAccounts(suite.ctx, ak, []string{mName}) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 9f03b175fcb4..e68e7fe4b5c0 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -80,7 +80,8 @@ func (a AccountsIndexes) IndexesList() []collections.Index[sdk.AccAddress, sdk.A // AccountKeeper encodes/decodes accounts using the go-amino (binary) // encoding/decoding library. type AccountKeeper struct { - addressCodec address.Codec + addressCodec address.Codec + AccountsKeeper types.AccountsKeeper environment appmodule.Environment cdc codec.BinaryCodec @@ -112,7 +113,7 @@ var _ AccountKeeperI = &AccountKeeper{} // may use auth.Keeper to access the accounts permissions map. func NewAccountKeeper( env appmodule.Environment, cdc codec.BinaryCodec, proto func() sdk.AccountI, - maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, + maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, AccountsKeeper types.AccountsKeeper, ) AccountKeeper { permAddrs := make(map[string]types.PermissionsForAddress) for name, perms := range maccPerms { @@ -122,16 +123,17 @@ func NewAccountKeeper( sb := collections.NewSchemaBuilder(env.KVStoreService) ak := AccountKeeper{ - addressCodec: ac, - bech32Prefix: bech32Prefix, - environment: env, - proto: proto, - cdc: cdc, - 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)), + addressCodec: ac, + bech32Prefix: bech32Prefix, + environment: env, + proto: proto, + cdc: cdc, + 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)), + AccountsKeeper: AccountsKeeper, } schema, err := sb.Build() if err != nil { diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 02a25bb6ec83..78267c01d3ca 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -72,6 +72,7 @@ func (suite *KeeperTestSuite) SetupTest() { authcodec.NewBech32Codec("cosmos"), "cosmos", types.NewModuleAddress("gov").String(), + nil, ) suite.msgServer = keeper.NewMsgServerImpl(suite.accountKeeper) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) diff --git a/x/auth/types/expected_keepers.go b/x/auth/types/expected_keepers.go index ffcfe49aa10d..c7be01d5edf6 100644 --- a/x/auth/types/expected_keepers.go +++ b/x/auth/types/expected_keepers.go @@ -12,3 +12,8 @@ type BankKeeper interface { SendCoins(ctx context.Context, from, to sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } + +// AccountsKeeper defines the contract for x/accounts APIs (noalias) +type AccountsKeeper interface { + GetAccountNumber(ctx context.Context, accountAddr []byte) (uint64, error) +} diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 83273f32bbad..350bba50bec2 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -62,7 +62,7 @@ func (s *VestingAccountTestSuite) SetupTest() { maccPerms, authcodec.NewBech32Codec("cosmos"), "cosmos", - authtypes.NewModuleAddress("gov").String(), + authtypes.NewModuleAddress("gov").String(), nil, ) } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index c643eb01489b..41c463eef83c 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -437,6 +437,9 @@ func (k BaseKeeper) setSupply(ctx context.Context, coin sdk.Coin) { // trackDelegation tracks the delegation of the given account if it is a vesting account func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, balance, amt sdk.Coins) error { + if k.ak.IsAccountsModuleAccount(ctx, addr) { + return nil + } acc := k.ak.GetAccount(ctx, addr) if acc == nil { return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) @@ -454,6 +457,9 @@ func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, ba // trackUndelegation tracks undelegation of the given account if it is a vesting account func (k BaseKeeper) trackUndelegation(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error { + if k.ak.IsAccountsModuleAccount(ctx, addr) { + return nil + } acc := k.ak.GetAccount(ctx, addr) if acc == nil { return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) diff --git a/x/bank/testutil/expected_keepers_mocks.go b/x/bank/testutil/expected_keepers_mocks.go index 058c4e2d7e36..55e66c0d6c09 100644 --- a/x/bank/testutil/expected_keepers_mocks.go +++ b/x/bank/testutil/expected_keepers_mocks.go @@ -216,3 +216,17 @@ func (mr *MockAccountKeeperMockRecorder) ValidatePermissions(macc interface{}) * mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatePermissions", reflect.TypeOf((*MockAccountKeeper)(nil).ValidatePermissions), macc) } + +// ValidatePermissions mocks base method. +func (m *MockAccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr types0.AccAddress) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsAccountsModuleAccount", ctx, addr) + ret0, _ := ret[0].(bool) + return ret0 +} + +// ValidatePermissions indicates an expected call of ValidatePermissions. +func (mr *MockAccountKeeperMockRecorder) IsAccountsModuleAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).IsAccountsModuleAccount), ctx, addr) +} diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index 0cebc65d3952..08fc1fcb9b36 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -28,4 +28,6 @@ type AccountKeeper interface { GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI) GetModulePermissions() map[string]types.PermissionsForAddress + + IsAccountsModuleAccount(ctx context.Context, addr sdk.AccAddress) bool } From 025f78f5cdabc4fb4da1083e5dd9ab6b521794e4 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Wed, 10 Apr 2024 15:26:31 +0700 Subject: [PATCH 2/8] minor --- x/auth/types/expected_keepers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/types/expected_keepers.go b/x/auth/types/expected_keepers.go index c7be01d5edf6..6572419d3294 100644 --- a/x/auth/types/expected_keepers.go +++ b/x/auth/types/expected_keepers.go @@ -13,7 +13,7 @@ type BankKeeper interface { SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } -// AccountsKeeper defines the contract for x/accounts APIs (noalias) +// AccountsKeeper defines the contract for x/accounts APIs type AccountsKeeper interface { GetAccountNumber(ctx context.Context, accountAddr []byte) (uint64, error) } From 911c12e54d03727265b818e32259762beaae8dfa Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Wed, 10 Apr 2024 21:16:28 +0700 Subject: [PATCH 3/8] minor --- x/accounts/keeper.go | 14 +++++--------- x/auth/keeper/account.go | 3 +-- x/auth/types/expected_keepers.go | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index b22c08ac02ec..5fb3ec9e2fa6 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -126,17 +126,13 @@ type Keeper struct { AccountsState collections.Map[collections.Pair[uint64, []byte], []byte] } -// GetAccountNumber return a account number by address. -func (k Keeper) GetAccountNumber( +// IsAccountsModuleAccount check if an address belong to a smart account. +func (k Keeper) IsAccountsModuleAccount( ctx context.Context, accountAddr []byte, -) (uint64, error) { - accNum, err := k.AccountByNumber.Get(ctx, accountAddr) - if err != nil { - return 0, err - } - - return accNum, nil +) bool { + _, err := k.AccountByNumber.Get(ctx, accountAddr) + return err == nil } // Init creates a new account of the given type. diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index 4f984380eec1..37e940ce9404 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -63,6 +63,5 @@ func (ak AccountKeeper) RemoveAccount(ctx context.Context, acc sdk.AccountI) { // IsAccountsModuleAccount check an address belong to an x/accounts account func (ak AccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr sdk.AccAddress) bool { - _, err := ak.AccountsKeeper.GetAccountNumber(ctx, addr) - return err != nil + return ak.AccountsKeeper.IsAccountsModuleAccount(ctx, addr) } diff --git a/x/auth/types/expected_keepers.go b/x/auth/types/expected_keepers.go index 6572419d3294..31c3bf0c7626 100644 --- a/x/auth/types/expected_keepers.go +++ b/x/auth/types/expected_keepers.go @@ -15,5 +15,5 @@ type BankKeeper interface { // AccountsKeeper defines the contract for x/accounts APIs type AccountsKeeper interface { - GetAccountNumber(ctx context.Context, accountAddr []byte) (uint64, error) + IsAccountsModuleAccount(ctx context.Context, accountAddr []byte) bool } From 304350f6bf03367d5479ab487a02bfff3067c43c Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Thu, 11 Apr 2024 04:19:27 +0700 Subject: [PATCH 4/8] fix test --- client/rpc/rpc_test.go | 2 + server/api/server_test.go | 1 + simapp/app_config.go | 7 ++ simapp/app_di.go | 3 + simapp/simd/cmd/testnet_test.go | 3 +- tests/e2e/baseapp/block_gas_test.go | 2 + tests/integration/bank/app_test.go | 2 + .../bank/keeper/deterministic_test.go | 1 + tests/integration/distribution/appconfig.go | 2 + .../distribution/keeper/msg_server_test.go | 7 ++ tests/integration/evidence/app_config.go | 2 + .../evidence/keeper/infraction_test.go | 7 ++ tests/integration/example/example_test.go | 2 + tests/integration/gov/common_test.go | 2 + tests/integration/gov/genesis_test.go | 2 + tests/integration/gov/keeper/keeper_test.go | 7 ++ tests/integration/gov/module_test.go | 2 + tests/integration/mint/app_config.go | 2 + tests/integration/runtime/query_test.go | 2 + tests/integration/slashing/app_config.go | 2 + .../slashing/keeper/keeper_test.go | 7 ++ tests/integration/slashing/slashing_test.go | 1 + tests/integration/staking/app_config.go | 2 + .../integration/staking/keeper/common_test.go | 7 ++ .../staking/keeper/deterministic_test.go | 7 ++ tests/integration/tx/context_test.go | 2 + tests/sims/authz/operations_test.go | 4 +- tests/sims/bank/operations_test.go | 2 + tests/sims/distribution/app_config.go | 2 + tests/sims/feegrant/operations_test.go | 2 + tests/sims/gov/operations_test.go | 2 + tests/sims/nft/app_config.go | 2 + tests/sims/protocolpool/app_config.go | 2 + tests/sims/slashing/app_config.go | 2 + testutil/configurator/configurator.go | 11 +++ testutil/network/network.go | 2 + types/query/pagination_test.go | 2 + x/accounts/depinject.go | 67 ++++++++++++++++++- x/accounts/utils_test.go | 2 +- x/auth/depinject.go | 4 +- x/auth/keeper/account.go | 7 +- x/auth/keeper/keeper.go | 28 ++++---- x/auth/testutil/app_config.go | 2 + x/auth/testutil/expected_keepers_mocks.go | 40 +++++++++++ x/auth/types/expected_keepers.go | 4 +- x/bank/keeper/keeper.go | 14 ++-- x/bank/keeper/keeper_test.go | 1 + x/bank/testutil/expected_keepers_mocks.go | 6 +- x/bank/types/expected_keepers.go | 2 - .../migrations/v4/migrate_funds_test.go | 1 + x/epochs/go.mod | 2 +- x/epochs/go.sum | 4 +- x/group/migrations/v2/migrate_test.go | 7 +- x/group/testutil/app_config.go | 2 + 54 files changed, 269 insertions(+), 43 deletions(-) diff --git a/client/rpc/rpc_test.go b/client/rpc/rpc_test.go index 7606602127f4..4fa96fa9c2e6 100644 --- a/client/rpc/rpc_test.go +++ b/client/rpc/rpc_test.go @@ -10,6 +10,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/metadata" + _ "cosmossdk.io/x/accounts" + "github.com/cosmos/cosmos-sdk/testutil/network" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types/address" diff --git a/server/api/server_test.go b/server/api/server_test.go index 1dbc7e6677cb..d867678883aa 100644 --- a/server/api/server_test.go +++ b/server/api/server_test.go @@ -18,6 +18,7 @@ import ( "github.com/stretchr/testify/suite" "google.golang.org/grpc/codes" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" _ "cosmossdk.io/x/bank" diff --git a/simapp/app_config.go b/simapp/app_config.go index 46eadb103a7e..2cd1c81c2db7 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -6,6 +6,7 @@ import ( "google.golang.org/protobuf/types/known/durationpb" + accountsmodulev1 "cosmossdk.io/api/cosmos/accounts/module/v1" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -29,6 +30,7 @@ import ( upgrademodulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" vestingmodulev1 "cosmossdk.io/api/cosmos/vesting/module/v1" "cosmossdk.io/depinject/appconfig" + "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth/tx/config" // import for side-effects authtypes "cosmossdk.io/x/auth/types" _ "cosmossdk.io/x/auth/vesting" // import for side-effects @@ -138,6 +140,7 @@ var ( // properly initialized with tokens from genesis accounts. // NOTE: The genutils module must also occur after auth so that it can access the params from auth. InitGenesis: []string{ + accounts.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, @@ -256,6 +259,10 @@ var ( Name: pooltypes.ModuleName, Config: appconfig.WrapAny(&poolmodulev1.Module{}), }, + { + Name: accounts.ModuleName, + Config: appconfig.WrapAny(&accountsmodulev1.Module{}), + }, { Name: epochstypes.ModuleName, Config: appconfig.WrapAny(&epochsmodulev1.Module{}), diff --git a/simapp/app_di.go b/simapp/app_di.go index efaca0e3e21f..32d3a3613ad5 100644 --- a/simapp/app_di.go +++ b/simapp/app_di.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/accounts" "cosmossdk.io/x/auth" "cosmossdk.io/x/auth/ante/unorderedtx" authkeeper "cosmossdk.io/x/auth/keeper" @@ -73,6 +74,7 @@ type SimApp struct { UnorderedTxManager *unorderedtx.Manager // keepers + AccountsKeeper accounts.Keeper AuthKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper StakingKeeper *stakingkeeper.Keeper @@ -183,6 +185,7 @@ func NewSimApp( &app.txConfig, &app.interfaceRegistry, &app.AuthKeeper, + &app.AccountsKeeper, &app.BankKeeper, &app.StakingKeeper, &app.SlashingKeeper, diff --git a/simapp/simd/cmd/testnet_test.go b/simapp/simd/cmd/testnet_test.go index e5421a84e37f..58e93e130d52 100644 --- a/simapp/simd/cmd/testnet_test.go +++ b/simapp/simd/cmd/testnet_test.go @@ -27,6 +27,7 @@ import ( func Test_TestnetCmd(t *testing.T) { config := configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.GenutilModule(), @@ -44,7 +45,7 @@ func Test_TestnetCmd(t *testing.T) { ) require.NoError(t, err) require.NotNil(t, moduleManager) - require.Len(t, moduleManager.Modules, 7) + require.Len(t, moduleManager.Modules, 8) home := t.TempDir() cdcOpts := codectestutil.CodecOptions{} diff --git a/tests/e2e/baseapp/block_gas_test.go b/tests/e2e/baseapp/block_gas_test.go index 134771884df1..0098c2d48650 100644 --- a/tests/e2e/baseapp/block_gas_test.go +++ b/tests/e2e/baseapp/block_gas_test.go @@ -17,6 +17,7 @@ import ( "cosmossdk.io/log" sdkmath "cosmossdk.io/math" store "cosmossdk.io/store/types" + _ "cosmossdk.io/x/accounts" xauthsigning "cosmossdk.io/x/auth/signing" "github.com/cosmos/cosmos-sdk/baseapp" @@ -85,6 +86,7 @@ func TestBaseApp_BlockGas(t *testing.T) { err = depinject.Inject( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.TxModule(), configurator.ConsensusModule(), diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index d1b2e91dbe36..7043b1eb0be6 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" authtypes "cosmossdk.io/x/auth/types" @@ -92,6 +93,7 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.TxModule(), diff --git a/tests/integration/bank/keeper/deterministic_test.go b/tests/integration/bank/keeper/deterministic_test.go index 78d736143c35..ec399463c11d 100644 --- a/tests/integration/bank/keeper/deterministic_test.go +++ b/tests/integration/bank/keeper/deterministic_test.go @@ -86,6 +86,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + nil, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/distribution/appconfig.go b/tests/integration/distribution/appconfig.go index 7cf9a5a7436b..c22f15e63fd8 100644 --- a/tests/integration/distribution/appconfig.go +++ b/tests/integration/distribution/appconfig.go @@ -1,6 +1,7 @@ package distribution_test import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 962d6c8779e9..386e5edab56a 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" @@ -16,6 +17,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -85,6 +87,10 @@ func initFixture(t *testing.T) *fixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(t) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -93,6 +99,7 @@ func initFixture(t *testing.T) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/evidence/app_config.go b/tests/integration/evidence/app_config.go index 1132ea10e9f1..6a9bba7e164f 100644 --- a/tests/integration/evidence/app_config.go +++ b/tests/integration/evidence/app_config.go @@ -1,6 +1,7 @@ package evidence_test import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -14,6 +15,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 87d5a52c9fa4..d0b890abe627 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -9,6 +9,7 @@ import ( "time" abci "github.com/cometbft/cometbft/abci/types" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "cosmossdk.io/collections" @@ -20,6 +21,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -98,6 +100,10 @@ func initFixture(tb testing.TB) *fixture { authority := authtypes.NewModuleAddress("gov") + // gomock initializations + ctrl := gomock.NewController(tb) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + maccPerms := map[string][]string{ pooltypes.ModuleName: {}, minttypes.ModuleName: {authtypes.Minter}, @@ -113,6 +119,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/example/example_test.go b/tests/integration/example/example_test.go index e921c175021b..b995e00b18c4 100644 --- a/tests/integration/example/example_test.go +++ b/tests/integration/example/example_test.go @@ -50,6 +50,7 @@ func Example() { addresscodec.NewBech32Codec("cosmos"), "cosmos", authority, + nil, ) // subspace is nil because we don't test params (which is legacy anyway) @@ -141,6 +142,7 @@ func Example_oneModule() { addresscodec.NewBech32Codec("cosmos"), "cosmos", authority, + nil, ) // subspace is nil because we don't test params (which is legacy anyway) diff --git a/tests/integration/gov/common_test.go b/tests/integration/gov/common_test.go index d5243c15e66f..65a66cf52cf4 100644 --- a/tests/integration/gov/common_test.go +++ b/tests/integration/gov/common_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/depinject" sdklog "cosmossdk.io/log" "cosmossdk.io/math" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authtypes "cosmossdk.io/x/auth/types" _ "cosmossdk.io/x/bank" @@ -105,6 +106,7 @@ func createTestSuite(t *testing.T) suite { app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index 6cbe8e7be48c..8959cd3335bb 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" sdkmath "cosmossdk.io/math" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authtypes "cosmossdk.io/x/auth/types" @@ -46,6 +47,7 @@ type suite struct { } var appConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index 1a7b2608163c..f7f24c1fb7fc 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -26,6 +27,7 @@ import ( "cosmossdk.io/x/staking" stakingkeeper "cosmossdk.io/x/staking/keeper" stakingtypes "cosmossdk.io/x/staking/types" + "github.com/golang/mock/gomock" "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" @@ -72,6 +74,10 @@ func initFixture(tb testing.TB) *fixture { types.ModuleName: {authtypes.Burner}, } + // gomock initializations + ctrl := gomock.NewController(tb) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -80,6 +86,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/gov/module_test.go b/tests/integration/gov/module_test.go index c482716aae96..c1d41a0b6cb5 100644 --- a/tests/integration/gov/module_test.go +++ b/tests/integration/gov/module_test.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" authkeeper "cosmossdk.io/x/auth/keeper" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/gov/types" @@ -22,6 +23,7 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { app, err := simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/integration/mint/app_config.go b/tests/integration/mint/app_config.go index 1d080c94acbc..5a00b66295cd 100644 --- a/tests/integration/mint/app_config.go +++ b/tests/integration/mint/app_config.go @@ -1,6 +1,7 @@ package mint import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -13,6 +14,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/runtime/query_test.go b/tests/integration/runtime/query_test.go index 4ad7a7553aed..de3e3e7457d4 100644 --- a/tests/integration/runtime/query_test.go +++ b/tests/integration/runtime/query_test.go @@ -14,6 +14,7 @@ import ( reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" _ "cosmossdk.io/x/bank" @@ -42,6 +43,7 @@ func initFixture(t assert.TestingT) *fixture { app, err := simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.TxModule(), configurator.ConsensusModule(), diff --git a/tests/integration/slashing/app_config.go b/tests/integration/slashing/app_config.go index ee2e36f41cbe..7ee06d925aff 100644 --- a/tests/integration/slashing/app_config.go +++ b/tests/integration/slashing/app_config.go @@ -1,6 +1,7 @@ package slashing import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -16,6 +17,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index dc14c0284836..09fec08e575e 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "gotest.tools/v3/assert" @@ -14,6 +15,7 @@ import ( storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -73,6 +75,10 @@ func initFixture(tb testing.TB) *fixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(&testing.T{}) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -81,6 +87,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/slashing/slashing_test.go b/tests/integration/slashing/slashing_test.go index 0ac41336231a..bec39e2449f8 100644 --- a/tests/integration/slashing/slashing_test.go +++ b/tests/integration/slashing/slashing_test.go @@ -62,6 +62,7 @@ func TestSlashingMsgs(t *testing.T) { app, err := sims.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.SlashingModule(), diff --git a/tests/integration/staking/app_config.go b/tests/integration/staking/app_config.go index 89b85e88b2b0..86972f92e649 100644 --- a/tests/integration/staking/app_config.go +++ b/tests/integration/staking/app_config.go @@ -1,6 +1,7 @@ package staking import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -16,6 +17,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index f864019603c0..c67341031eb1 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "cosmossdk.io/core/appmodule" @@ -13,6 +14,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -122,6 +124,10 @@ func initFixture(tb testing.TB) *fixture { types.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(&testing.T{}) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -130,6 +136,7 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/staking/keeper/deterministic_test.go b/tests/integration/staking/keeper/deterministic_test.go index cc8c2fbae654..3c90367d4025 100644 --- a/tests/integration/staking/keeper/deterministic_test.go +++ b/tests/integration/staking/keeper/deterministic_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "pgregory.net/rapid" @@ -14,6 +15,7 @@ import ( "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" authsims "cosmossdk.io/x/auth/simulation" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/bank" bankkeeper "cosmossdk.io/x/bank/keeper" @@ -86,6 +88,10 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, } + // gomock initializations + ctrl := gomock.NewController(t) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + accountKeeper := authkeeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger()), cdc, @@ -94,6 +100,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture { addresscodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authority.String(), + acctsModKeeper, ) blockedAddresses := map[string]bool{ diff --git a/tests/integration/tx/context_test.go b/tests/integration/tx/context_test.go index 7246a2c798d1..ffe21c2053cb 100644 --- a/tests/integration/tx/context_test.go +++ b/tests/integration/tx/context_test.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -33,6 +34,7 @@ func TestDefineCustomGetSigners(t *testing.T) { _, err := simtestutil.SetupAtGenesis( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.StakingModule(), configurator.BankModule(), diff --git a/tests/sims/authz/operations_test.go b/tests/sims/authz/operations_test.go index 60e4ca724112..0a2ef3354859 100644 --- a/tests/sims/authz/operations_test.go +++ b/tests/sims/authz/operations_test.go @@ -11,7 +11,8 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" - _ "cosmossdk.io/x/auth" // import as blank for app wiring + _ "cosmossdk.io/x/accounts" // import as blank for app wiring + _ "cosmossdk.io/x/auth" // import as blank for app wiring authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring "cosmossdk.io/x/authz" @@ -39,6 +40,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/bank/operations_test.go b/tests/sims/bank/operations_test.go index 5d4564af1f11..9ba074f4efee 100644 --- a/tests/sims/bank/operations_test.go +++ b/tests/sims/bank/operations_test.go @@ -9,6 +9,7 @@ import ( "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" _ "cosmossdk.io/x/auth/tx/config" _ "cosmossdk.io/x/bank" @@ -47,6 +48,7 @@ func (suite *SimTestSuite) SetupTest() { suite.app, err = simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/distribution/app_config.go b/tests/sims/distribution/app_config.go index 02130ff2387b..efd27dcf1a9d 100644 --- a/tests/sims/distribution/app_config.go +++ b/tests/sims/distribution/app_config.go @@ -1,6 +1,7 @@ package distribution import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/feegrant/operations_test.go b/tests/sims/feegrant/operations_test.go index cf00c52389f8..21ef34e3aa57 100644 --- a/tests/sims/feegrant/operations_test.go +++ b/tests/sims/feegrant/operations_test.go @@ -11,6 +11,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/auth/tx/config" @@ -56,6 +57,7 @@ func (suite *SimTestSuite) SetupTest() { suite.app, err = simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/gov/operations_test.go b/tests/sims/gov/operations_test.go index 239049e76bc9..2b81623fac61 100644 --- a/tests/sims/gov/operations_test.go +++ b/tests/sims/gov/operations_test.go @@ -13,6 +13,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/depinject" "cosmossdk.io/log" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/auth/tx/config" @@ -384,6 +385,7 @@ func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { app, err := simtestutil.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.TxModule(), configurator.BankModule(), diff --git a/tests/sims/nft/app_config.go b/tests/sims/nft/app_config.go index 8ce4a69e09e4..156056fe4bdf 100644 --- a/tests/sims/nft/app_config.go +++ b/tests/sims/nft/app_config.go @@ -1,6 +1,7 @@ package nft import ( + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -14,6 +15,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/protocolpool/app_config.go b/tests/sims/protocolpool/app_config.go index 7163523f09ea..b0c680cf9572 100644 --- a/tests/sims/protocolpool/app_config.go +++ b/tests/sims/protocolpool/app_config.go @@ -1,6 +1,7 @@ package protocolpool import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/tests/sims/slashing/app_config.go b/tests/sims/slashing/app_config.go index ee2e36f41cbe..7ee06d925aff 100644 --- a/tests/sims/slashing/app_config.go +++ b/tests/sims/slashing/app_config.go @@ -1,6 +1,7 @@ package slashing import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/bank" // import as blank for app wiring @@ -16,6 +17,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), diff --git a/testutil/configurator/configurator.go b/testutil/configurator/configurator.go index 44f0ba461369..f1476221d2c3 100644 --- a/testutil/configurator/configurator.go +++ b/testutil/configurator/configurator.go @@ -1,6 +1,7 @@ package configurator import ( + accountsmodulev1 "cosmossdk.io/api/cosmos/accounts/module/v1" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" @@ -89,6 +90,7 @@ func defaultConfig() *Config { testutil.ProtocolPoolModuleName, }, InitGenesisOrder: []string{ + testutil.AccountsModuleName, testutil.AuthModuleName, testutil.BankModuleName, testutil.DistributionModuleName, @@ -330,6 +332,15 @@ func ProtocolPoolModule() ModuleOption { } } +func AccountsModule() ModuleOption { + return func(config *Config) { + config.ModuleConfigs[testutil.AccountsModuleName] = &appv1alpha1.ModuleConfig{ + Name: testutil.AccountsModuleName, + Config: appconfig.WrapAny(&accountsmodulev1.Module{}), + } + } +} + func CounterModule() ModuleOption { return func(config *Config) { config.ModuleConfigs["counter"] = &appv1alpha1.ModuleConfig{ diff --git a/testutil/network/network.go b/testutil/network/network.go index 8dca40ae5473..42e288b614a5 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -25,6 +25,7 @@ import ( sdkmath "cosmossdk.io/math" "cosmossdk.io/math/unsafe" pruningtypes "cosmossdk.io/store/pruning/types" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" // import auth as a blank _ "cosmossdk.io/x/auth/tx/config" // import auth tx config as a blank authtypes "cosmossdk.io/x/auth/types" @@ -168,6 +169,7 @@ func DefaultConfig(factory TestFixtureFactory) Config { // MinimumAppConfig defines the minimum of modules required for a call to New to succeed func MinimumAppConfig() depinject.Config { return configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.GenutilModule(), diff --git a/types/query/pagination_test.go b/types/query/pagination_test.go index 7893ef78d354..a35257ccabfa 100644 --- a/types/query/pagination_test.go +++ b/types/query/pagination_test.go @@ -12,6 +12,7 @@ import ( "cosmossdk.io/log" "cosmossdk.io/math" "cosmossdk.io/store/prefix" + _ "cosmossdk.io/x/accounts" _ "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" _ "cosmossdk.io/x/bank" @@ -68,6 +69,7 @@ func (s *paginationTestSuite) SetupTest() { app, err := testutilsims.Setup( depinject.Configs( configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.ConsensusModule(), diff --git a/x/accounts/depinject.go b/x/accounts/depinject.go index bef3dd4208cf..8714d98ba1d9 100644 --- a/x/accounts/depinject.go +++ b/x/accounts/depinject.go @@ -1,8 +1,73 @@ package accounts -import "cosmossdk.io/depinject" +import ( + "context" + + modulev1 "cosmossdk.io/api/cosmos/accounts/module/v1" + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + "cosmossdk.io/depinject/appconfig" + baseaccount "cosmossdk.io/x/accounts/defaults/base" + "cosmossdk.io/x/tx/signing" + + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" +) var _ depinject.OnePerModuleType = AppModule{} // IsOnePerModuleType implements the depinject.OnePerModuleType interface. func (am AppModule) IsOnePerModuleType() {} + +func init() { + appconfig.RegisterModule( + &modulev1.Module{}, + appconfig.Provide(ProvideModule), + ) +} + +type ModuleInputs struct { + depinject.In + + Cdc codec.Codec + Environment appmodule.Environment + AddressCodec address.Codec + ExecRouter MsgRouter + QueryRouter QueryRouter + Registry cdctypes.InterfaceRegistry +} + +type ModuleOutputs struct { + depinject.Out + + AccountsKeeper Keeper + Module appmodule.AppModule +} + +var _ signing.SignModeHandler = directHandler{} + +type directHandler struct{} + +func (s directHandler) Mode() signingv1beta1.SignMode { + return signingv1beta1.SignMode_SIGN_MODE_DIRECT +} + +func (s directHandler) GetSignBytes(_ context.Context, _ signing.SignerData, _ signing.TxData) ([]byte, error) { + panic("not implemented") +} + +func ProvideModule(in ModuleInputs) ModuleOutputs { + handler := directHandler{} + account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler)) + accountskeeper, err := NewKeeper( + in.Cdc, in.Environment, in.AddressCodec, in.Cdc, + in.ExecRouter, in.QueryRouter, in.Registry, account, + ) + if err != nil { + panic(err) + } + m := NewAppModule(in.Cdc, accountskeeper) + return ModuleOutputs{AccountsKeeper: accountskeeper, Module: m} +} diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 0fec9839686d..88b6e735e579 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - gogoproto "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/runtime/protoiface" @@ -16,6 +15,7 @@ import ( "cosmossdk.io/x/accounts/internal/implementation" "github.com/cosmos/cosmos-sdk/runtime" + gogoproto "github.com/cosmos/gogoproto/proto" ) var _ address.Codec = (*addressCodec)(nil) diff --git a/x/auth/depinject.go b/x/auth/depinject.go index 866e4ae2f512..d8f4ca497f84 100644 --- a/x/auth/depinject.go +++ b/x/auth/depinject.go @@ -27,7 +27,7 @@ func init() { type ModuleInputs struct { depinject.In - AccountsKeeper types.AccountsKeeper + AccountsModKeeper types.AccountsModKeeper Config *modulev1.Module Environment appmodule.Environment @@ -70,7 +70,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { panic(err) } - k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth, in.AccountsKeeper) + k := keeper.NewAccountKeeper(in.Environment, in.Cdc, in.AccountI, maccPerms, in.AddressCodec, in.Config.Bech32Prefix, auth, in.AccountsModKeeper) m := NewAppModule(in.Cdc, k, in.RandomGenesisAccountsFn) return ModuleOutputs{AccountKeeper: k, Module: m} diff --git a/x/auth/keeper/account.go b/x/auth/keeper/account.go index 37e940ce9404..3e21fd9a8594 100644 --- a/x/auth/keeper/account.go +++ b/x/auth/keeper/account.go @@ -32,7 +32,7 @@ func (ak AccountKeeper) NewAccount(ctx context.Context, acc sdk.AccountI) sdk.Ac // HasAccount implements AccountKeeperI. func (ak AccountKeeper) HasAccount(ctx context.Context, addr sdk.AccAddress) bool { has, _ := ak.Accounts.Has(ctx, addr) - return has + return has || ak.AccountsModKeeper.IsAccountsModuleAccount(ctx, addr) } // GetAccount implements AccountKeeperI. @@ -60,8 +60,3 @@ func (ak AccountKeeper) RemoveAccount(ctx context.Context, acc sdk.AccountI) { panic(err) } } - -// IsAccountsModuleAccount check an address belong to an x/accounts account -func (ak AccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr sdk.AccAddress) bool { - return ak.AccountsKeeper.IsAccountsModuleAccount(ctx, addr) -} diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index e68e7fe4b5c0..8f8bf42f5006 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -80,8 +80,8 @@ func (a AccountsIndexes) IndexesList() []collections.Index[sdk.AccAddress, sdk.A // AccountKeeper encodes/decodes accounts using the go-amino (binary) // encoding/decoding library. type AccountKeeper struct { - addressCodec address.Codec - AccountsKeeper types.AccountsKeeper + addressCodec address.Codec + AccountsModKeeper types.AccountsModKeeper environment appmodule.Environment cdc codec.BinaryCodec @@ -113,7 +113,7 @@ var _ AccountKeeperI = &AccountKeeper{} // may use auth.Keeper to access the accounts permissions map. func NewAccountKeeper( env appmodule.Environment, cdc codec.BinaryCodec, proto func() sdk.AccountI, - maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, AccountsKeeper types.AccountsKeeper, + maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, AccountsModKeeper types.AccountsModKeeper, ) AccountKeeper { permAddrs := make(map[string]types.PermissionsForAddress) for name, perms := range maccPerms { @@ -123,17 +123,17 @@ func NewAccountKeeper( sb := collections.NewSchemaBuilder(env.KVStoreService) ak := AccountKeeper{ - addressCodec: ac, - bech32Prefix: bech32Prefix, - environment: env, - proto: proto, - cdc: cdc, - 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)), - AccountsKeeper: AccountsKeeper, + addressCodec: ac, + bech32Prefix: bech32Prefix, + environment: env, + proto: proto, + cdc: cdc, + 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)), + AccountsModKeeper: AccountsModKeeper, } schema, err := sb.Build() if err != nil { diff --git a/x/auth/testutil/app_config.go b/x/auth/testutil/app_config.go index eeb5a324cb45..f72850c4bf1a 100644 --- a/x/auth/testutil/app_config.go +++ b/x/auth/testutil/app_config.go @@ -1,6 +1,7 @@ package testutil import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/auth/vesting" // import as blank for app wiring @@ -13,6 +14,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.VestingModule(), diff --git a/x/auth/testutil/expected_keepers_mocks.go b/x/auth/testutil/expected_keepers_mocks.go index 2d0e602a8cbc..2604271001d9 100644 --- a/x/auth/testutil/expected_keepers_mocks.go +++ b/x/auth/testutil/expected_keepers_mocks.go @@ -81,3 +81,43 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), ctx, senderAddr, recipientModule, amt) } + + +// MockAccountsModKeeper is a mock of AccountsModKeeper interface. +type MockAccountsModKeeper struct { + ctrl *gomock.Controller + recorder *MockAccountsModKeeperMockRecorder +} + +// MockAccountsModKeeperMockRecorder is the mock recorder for MockAccountsModKeeper. +type MockAccountsModKeeperMockRecorder struct { + mock *MockAccountsModKeeper +} + +// NewMockAccountsModKeeper creates a new mock instance. +func NewMockAccountsModKeeper(ctrl *gomock.Controller) *MockAccountsModKeeper { + mock := &MockAccountsModKeeper{ctrl: ctrl} + mock.recorder = &MockAccountsModKeeperMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAccountsModKeeper) EXPECT() *MockAccountsModKeeperMockRecorder { + return m.recorder +} + +// IsAccountsModuleAccount mocks base method. +func (m *MockAccountsModKeeper) IsAccountsModuleAccount(ctx context.Context, addr []byte) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsAccountsModuleAccount", ctx, addr) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsAccountsModuleAccount indicates an expected call of IsAccountsModuleAccount. +func (mr *MockAccountsModKeeperMockRecorder) IsAccountsModuleAccount(ctx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountsModKeeper)(nil).IsAccountsModuleAccount), ctx, addr) +} + + diff --git a/x/auth/types/expected_keepers.go b/x/auth/types/expected_keepers.go index 31c3bf0c7626..f7821d91251b 100644 --- a/x/auth/types/expected_keepers.go +++ b/x/auth/types/expected_keepers.go @@ -13,7 +13,7 @@ type BankKeeper interface { SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error } -// AccountsKeeper defines the contract for x/accounts APIs -type AccountsKeeper interface { +// AccountsModKeeper defines the contract for x/accounts APIs +type AccountsModKeeper interface { IsAccountsModuleAccount(ctx context.Context, accountAddr []byte) bool } diff --git a/x/bank/keeper/keeper.go b/x/bank/keeper/keeper.go index 41c463eef83c..749c81ace578 100644 --- a/x/bank/keeper/keeper.go +++ b/x/bank/keeper/keeper.go @@ -437,11 +437,12 @@ func (k BaseKeeper) setSupply(ctx context.Context, coin sdk.Coin) { // trackDelegation tracks the delegation of the given account if it is a vesting account func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, balance, amt sdk.Coins) error { - if k.ak.IsAccountsModuleAccount(ctx, addr) { - return nil - } acc := k.ak.GetAccount(ctx, addr) if acc == nil { + // check if it's an x/accounts smart account + if k.ak.HasAccount(ctx, addr) { + return nil + } return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } @@ -457,11 +458,12 @@ func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, ba // trackUndelegation tracks undelegation of the given account if it is a vesting account func (k BaseKeeper) trackUndelegation(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error { - if k.ak.IsAccountsModuleAccount(ctx, addr) { - return nil - } acc := k.ak.GetAccount(ctx, addr) if acc == nil { + // check if it's an x/accounts smart account + if k.ak.HasAccount(ctx, addr) { + return nil + } return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr) } diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 86043fc81074..2c8f114ee8e3 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -1778,6 +1778,7 @@ func (suite *KeeperTestSuite) TestUndelegateCoins_Invalid() { suite.mockFundAccount(accAddrs[0]) require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins)) + suite.authKeeper.EXPECT().HasAccount(ctx, accAddrs[0]).Return(false) suite.mockDelegateCoins(ctx, acc0, holderAcc) require.NoError(suite.bankKeeper.DelegateCoins(ctx, accAddrs[0], holderAcc.GetAddress(), delCoins)) diff --git a/x/bank/testutil/expected_keepers_mocks.go b/x/bank/testutil/expected_keepers_mocks.go index 55e66c0d6c09..0b3ded8ec673 100644 --- a/x/bank/testutil/expected_keepers_mocks.go +++ b/x/bank/testutil/expected_keepers_mocks.go @@ -217,15 +217,15 @@ func (mr *MockAccountKeeperMockRecorder) ValidatePermissions(macc interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatePermissions", reflect.TypeOf((*MockAccountKeeper)(nil).ValidatePermissions), macc) } -// ValidatePermissions mocks base method. -func (m *MockAccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr types0.AccAddress) bool { +// IsAccountsModuleAccount mocks base method. +func (m *MockAccountKeeper) IsAccountsModuleAccount(ctx context.Context, addr []byte) bool { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "IsAccountsModuleAccount", ctx, addr) ret0, _ := ret[0].(bool) return ret0 } -// ValidatePermissions indicates an expected call of ValidatePermissions. +// IsAccountsModuleAccount indicates an expected call of IsAccountsModuleAccount. func (mr *MockAccountKeeperMockRecorder) IsAccountsModuleAccount(ctx, addr interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsAccountsModuleAccount", reflect.TypeOf((*MockAccountKeeper)(nil).IsAccountsModuleAccount), ctx, addr) diff --git a/x/bank/types/expected_keepers.go b/x/bank/types/expected_keepers.go index 08fc1fcb9b36..0cebc65d3952 100644 --- a/x/bank/types/expected_keepers.go +++ b/x/bank/types/expected_keepers.go @@ -28,6 +28,4 @@ type AccountKeeper interface { GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI) GetModulePermissions() map[string]types.PermissionsForAddress - - IsAccountsModuleAccount(ctx context.Context, addr sdk.AccAddress) bool } diff --git a/x/distribution/migrations/v4/migrate_funds_test.go b/x/distribution/migrations/v4/migrate_funds_test.go index 7158037befe5..43516921b4cd 100644 --- a/x/distribution/migrations/v4/migrate_funds_test.go +++ b/x/distribution/migrations/v4/migrate_funds_test.go @@ -55,6 +55,7 @@ func TestFundsMigration(t *testing.T) { addressCodec, sdk.Bech32MainPrefix, authority, + nil, ) // create bank keeper diff --git a/x/epochs/go.mod b/x/epochs/go.mod index f712b61afd92..b1d0a5d783f3 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -56,7 +56,7 @@ require ( github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/dgraph-io/badger/v2 v2.2007.4 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index dfef53b3919b..c6d135f6ffa4 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -160,8 +160,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= diff --git a/x/group/migrations/v2/migrate_test.go b/x/group/migrations/v2/migrate_test.go index 80e42c0d2862..2b40bd9ed236 100644 --- a/x/group/migrations/v2/migrate_test.go +++ b/x/group/migrations/v2/migrate_test.go @@ -11,12 +11,14 @@ import ( storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth" authkeeper "cosmossdk.io/x/auth/keeper" + authtestutil "cosmossdk.io/x/auth/testutil" authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/group" "cosmossdk.io/x/group/internal/orm" groupkeeper "cosmossdk.io/x/group/keeper" v2 "cosmossdk.io/x/group/migrations/v2" groupmodule "cosmossdk.io/x/group/module" + "github.com/golang/mock/gomock" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" @@ -101,7 +103,10 @@ func createOldPolicyAccount(ctx sdk.Context, storeKey storetypes.StoreKey, cdc c if err != nil { return nil, nil, err } - accountKeeper := authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), log.NewNopLogger()), cdc, authtypes.ProtoBaseAccount, nil, addressCodec, sdk.Bech32MainPrefix, authorityStrAddr) + ctrl := gomock.NewController(&testing.T{}) + acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) + + accountKeeper := authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)), log.NewNopLogger()), cdc, authtypes.ProtoBaseAccount, nil, addressCodec, sdk.Bech32MainPrefix, authorityStrAddr, acctsModKeeper) oldPolicyAccounts := make([]*authtypes.ModuleAccount, len(policies)) for i, policyAddr := range policies { diff --git a/x/group/testutil/app_config.go b/x/group/testutil/app_config.go index f760be271998..d23caa88ebf2 100644 --- a/x/group/testutil/app_config.go +++ b/x/group/testutil/app_config.go @@ -1,6 +1,7 @@ package testutil import ( + _ "cosmossdk.io/x/accounts" // import as blank for app wiring _ "cosmossdk.io/x/auth" // import as blank for app wiring _ "cosmossdk.io/x/auth/tx/config" // import as blank for app wiring _ "cosmossdk.io/x/authz" // import as blank for app wiring @@ -15,6 +16,7 @@ import ( ) var AppConfig = configurator.NewAppConfig( + configurator.AccountsModule(), configurator.AuthModule(), configurator.BankModule(), configurator.StakingModule(), From c803dd29468bea38ae3a205fb004f612bea34e2a Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Thu, 11 Apr 2024 04:43:13 +0700 Subject: [PATCH 5/8] fix test --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index bee3d1931335..1c077ed7fb21 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -309,7 +309,7 @@ func NewSimApp( } app.AccountsKeeper = accountsKeeper - app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.AuthKeeper = authkeeper.NewAccountKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), logger), appCodec, authtypes.ProtoBaseAccount, maccPerms, signingCtx.AddressCodec(), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AccountsKeeper) app.BankKeeper = bankkeeper.NewBaseKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), logger), From 30e55f57b2bf5aae3a48899b53a68951b7f12c49 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Thu, 11 Apr 2024 15:56:00 +0700 Subject: [PATCH 6/8] use has --- x/accounts/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 5fb3ec9e2fa6..667f6c19a742 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -131,8 +131,8 @@ func (k Keeper) IsAccountsModuleAccount( ctx context.Context, accountAddr []byte, ) bool { - _, err := k.AccountByNumber.Get(ctx, accountAddr) - return err == nil + hasAcc, _ := k.AccountByNumber.Has(ctx, accountAddr) + return hasAcc } // Init creates a new account of the given type. From 4808e6ff0b87c2b3c6d3b4bf6a96bc42c2d57204 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Thu, 11 Apr 2024 16:26:30 +0700 Subject: [PATCH 7/8] fix lint --- tests/integration/gov/keeper/keeper_test.go | 2 +- x/accounts/utils_test.go | 2 +- x/group/migrations/v2/migrate_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index f7f24c1fb7fc..426e80037dde 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/golang/mock/gomock" "gotest.tools/v3/assert" "cosmossdk.io/core/appmodule" @@ -27,7 +28,6 @@ import ( "cosmossdk.io/x/staking" stakingkeeper "cosmossdk.io/x/staking/keeper" stakingtypes "cosmossdk.io/x/staking/types" - "github.com/golang/mock/gomock" "github.com/cosmos/cosmos-sdk/baseapp" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 88b6e735e579..0fec9839686d 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + gogoproto "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/runtime/protoiface" @@ -15,7 +16,6 @@ import ( "cosmossdk.io/x/accounts/internal/implementation" "github.com/cosmos/cosmos-sdk/runtime" - gogoproto "github.com/cosmos/gogoproto/proto" ) var _ address.Codec = (*addressCodec)(nil) diff --git a/x/group/migrations/v2/migrate_test.go b/x/group/migrations/v2/migrate_test.go index 2b40bd9ed236..942a47ca097a 100644 --- a/x/group/migrations/v2/migrate_test.go +++ b/x/group/migrations/v2/migrate_test.go @@ -3,6 +3,7 @@ package v2_test import ( "testing" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" "cosmossdk.io/core/address" @@ -18,7 +19,6 @@ import ( groupkeeper "cosmossdk.io/x/group/keeper" v2 "cosmossdk.io/x/group/migrations/v2" groupmodule "cosmossdk.io/x/group/module" - "github.com/golang/mock/gomock" "github.com/cosmos/cosmos-sdk/codec" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" From b62f90e8990c725e62b02b56ec4d2bd325def3e9 Mon Sep 17 00:00:00 2001 From: sontrinh16 Date: Thu, 11 Apr 2024 16:35:29 +0700 Subject: [PATCH 8/8] linter are friend --- x/auth/keeper/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index c4f6d1addb68..1991bae32bf4 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -116,7 +116,7 @@ var _ AccountKeeperI = &AccountKeeper{} // may use auth.Keeper to access the accounts permissions map. func NewAccountKeeper( env appmodule.Environment, cdc codec.BinaryCodec, proto func() sdk.AccountI, - maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, AccountsModKeeper types.AccountsModKeeper, + maccPerms map[string][]string, ac address.Codec, bech32Prefix, authority string, accountsModKeeper types.AccountsModKeeper, ) AccountKeeper { permAddrs := make(map[string]types.PermissionsForAddress) for name, perms := range maccPerms { @@ -136,7 +136,7 @@ func NewAccountKeeper( 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)), - AccountsModKeeper: AccountsModKeeper, + AccountsModKeeper: accountsModKeeper, } schema, err := sb.Build() if err != nil {