Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move x/auth's AccountI and ModuleAccountI interfaces to types package #13937

Merged
merged 37 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
45d1e2a
move auth's AccountI interface to types package
likhita-809 Nov 21, 2022
254fad6
wip: more changes
likhita-809 Nov 21, 2022
ab573c5
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Nov 21, 2022
94554d0
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 21, 2022
544dbf0
small fix
likhita-809 Dec 22, 2022
28cdaea
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 22, 2022
9a9cf2f
wip
likhita-809 Dec 23, 2022
951e1c4
Revert "wip"
likhita-809 Dec 23, 2022
759e0cf
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 26, 2022
fad126a
wip
likhita-809 Dec 26, 2022
ae0204f
wip
likhita-809 Dec 26, 2022
3155931
wip: add alias AccountI interface
likhita-809 Dec 26, 2022
34b37b5
wip: final changes
likhita-809 Dec 26, 2022
d5ee7ec
wip
likhita-809 Dec 26, 2022
f58f055
add nit
likhita-809 Dec 26, 2022
ebf09b3
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 26, 2022
9b51ed3
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 27, 2022
326cd30
wip
likhita-809 Dec 27, 2022
3dc41ba
wip: fix tests
likhita-809 Dec 27, 2022
0d1aa39
fix import
likhita-809 Dec 27, 2022
6b97714
fix failing test
likhita-809 Dec 27, 2022
8e74c91
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 28, 2022
98a3bb4
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 28, 2022
da98282
try fixing failing tests
likhita-809 Dec 28, 2022
da16612
fix something
likhita-809 Dec 28, 2022
13ef65c
move ModuleAccountI interface to types package
likhita-809 Dec 28, 2022
5454b01
fix lint
likhita-809 Dec 28, 2022
0d88632
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 28, 2022
7dd023e
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 29, 2022
e820e3a
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 29, 2022
c96e8de
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Dec 30, 2022
cb53bbd
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jan 2, 2023
0cd4c81
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jan 2, 2023
52c9fb5
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jan 2, 2023
8b580a6
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 Jan 3, 2023
03a928d
try fixing rosetta test
likhita-809 Jan 3, 2023
0e831de
wip: fix tests
likhita-809 Jan 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions simapp/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"cosmossdk.io/math"
simappparams "cosmossdk.io/simapp/params"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/auth/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (s *E2ETestSuite) TestCLISignAminoJSON() {
// query account info
queryResJSON, err := authclitestutil.QueryAccountExec(val1.ClientCtx, val1.Address)
require.NoError(err)
var account authtypes.AccountI
var account sdk.AccountI
require.NoError(val1.ClientCtx.Codec.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account))

/**** test signature-only ****/
Expand Down Expand Up @@ -1327,7 +1327,7 @@ func (s *E2ETestSuite) TestMultisignBatch() {

queryResJSON, err := authclitestutil.QueryAccountExec(val.ClientCtx, addr)
s.Require().NoError(err)
var account authtypes.AccountI
var account sdk.AccountI
s.Require().NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account))

// sign-batch file
Expand Down Expand Up @@ -1398,7 +1398,7 @@ func (s *E2ETestSuite) TestGetAccountCmd() {
s.Require().Error(err)
s.Require().NotEqual("internal", err.Error())
} else {
var acc authtypes.AccountI
var acc sdk.AccountI
s.Require().NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(out.Bytes(), &acc))
s.Require().Equal(val.Address, acc.GetAddress())
}
Expand Down Expand Up @@ -1456,11 +1456,11 @@ func (s *E2ETestSuite) TestQueryModuleAccountByNameCmd() {
var res authtypes.QueryModuleAccountByNameResponse
s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))

var account authtypes.AccountI
var account sdk.AccountI
err := val.ClientCtx.InterfaceRegistry.UnpackAny(res.Account, &account)
s.Require().NoError(err)

moduleAccount, ok := account.(authtypes.ModuleAccountI)
moduleAccount, ok := account.(sdk.ModuleAccountI)
s.Require().True(ok)
s.Require().Equal(tc.moduleName, moduleAccount.GetName())
}
Expand Down
1 change: 1 addition & 0 deletions tools/rosetta/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

crgerrs "cosmossdk.io/tools/rosetta/lib/errors"
crgtypes "cosmossdk.io/tools/rosetta/lib/types"

sdkclient "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down
42 changes: 42 additions & 0 deletions types/dependencies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package types

import (
"github.com/cosmos/gogoproto/proto"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

// AccountI is an interface used to store coins at a given address within state.
// It presumes a notion of sequence numbers for replay protection,
// a notion of account numbers for replay protection for previously pruned accounts,
// and a pubkey for authentication purposes.
//
// Many complex conditions can be used in the concrete struct which implements AccountI.
type AccountI interface {
proto.Message

GetAddress() AccAddress
SetAddress(AccAddress) error // errors if already set.

GetPubKey() cryptotypes.PubKey // can return nil.
SetPubKey(cryptotypes.PubKey) error

GetAccountNumber() uint64
SetAccountNumber(uint64) error

GetSequence() uint64
SetSequence(uint64) error

// Ensure that account implements stringer
String() string
}

// ModuleAccountI defines an account interface for modules that hold tokens in
// an escrow.
type ModuleAccountI interface {
AccountI

GetName() string
GetPermissions() []string
HasPermission(string) bool
}
4 changes: 2 additions & 2 deletions x/auth/ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
// Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators.
type AccountKeeper interface {
GetParams(ctx sdk.Context) (params types.Params)
GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI
SetAccount(ctx sdk.Context, acc types.AccountI)
GetAccount(ctx sdk.Context, addr sdk.AccAddress) sdk.AccountI
SetAccount(ctx sdk.Context, acc sdk.AccountI)
GetModuleAddress(moduleName string) sdk.AccAddress
}

Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee
}

// DeductFees deducts fees from the given account.
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins) error {
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc sdk.AccountI, fees sdk.Coins) error {
if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func ConsumeMultisignatureVerificationGas(

// GetSignerAcc returns an account for a given address that is expected to sign
// a transaction.
func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (types.AccountI, error) {
func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (sdk.AccountI, error) {
if acc := ak.GetAccount(ctx, addr); acc != nil {
return acc, nil
}
Expand Down
6 changes: 3 additions & 3 deletions x/auth/ante/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/auth/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// TestAccount represents an account used in the tests in x/auth/ante.
type TestAccount struct {
acc types.AccountI
acc sdk.AccountI
priv cryptotypes.PrivKey
}

Expand Down
16 changes: 8 additions & 8 deletions x/auth/keeper/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// NewAccountWithAddress implements AccountKeeperI.
func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) types.AccountI {
func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) sdk.AccountI {
acc := ak.proto()
err := acc.SetAddress(addr)
if err != nil {
Expand All @@ -17,7 +17,7 @@ func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddre
}

// NewAccount sets the next account number to a given account interface
func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc types.AccountI) types.AccountI {
func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc sdk.AccountI) sdk.AccountI {
if err := acc.SetAccountNumber(ak.NextAccountNumber(ctx)); err != nil {
panic(err)
}
Expand All @@ -38,7 +38,7 @@ func (ak AccountKeeper) HasAccountAddressByID(ctx sdk.Context, id uint64) bool {
}

// GetAccount implements AccountKeeperI.
func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI {
func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) sdk.AccountI {
store := ctx.KVStore(ak.storeKey)
bz := store.Get(types.AddressStoreKey(addr))
if bz == nil {
Expand All @@ -59,8 +59,8 @@ func (ak AccountKeeper) GetAccountAddressByID(ctx sdk.Context, id uint64) string
}

// GetAllAccounts returns all accounts in the accountKeeper.
func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []types.AccountI) {
ak.IterateAccounts(ctx, func(acc types.AccountI) (stop bool) {
func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []sdk.AccountI) {
ak.IterateAccounts(ctx, func(acc sdk.AccountI) (stop bool) {
accounts = append(accounts, acc)
return false
})
Expand All @@ -69,7 +69,7 @@ func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) (accounts []types.Accoun
}

// SetAccount implements AccountKeeperI.
func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc types.AccountI) {
func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc sdk.AccountI) {
addr := acc.GetAddress()
store := ctx.KVStore(ak.storeKey)

Expand All @@ -84,7 +84,7 @@ func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc types.AccountI) {

// RemoveAccount removes an account for the account mapper store.
// NOTE: this will cause supply invariant violation if called
func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc types.AccountI) {
func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc sdk.AccountI) {
addr := acc.GetAddress()
store := ctx.KVStore(ak.storeKey)
store.Delete(types.AddressStoreKey(addr))
Expand All @@ -93,7 +93,7 @@ func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc types.AccountI) {

// IterateAccounts iterates over all the stored accounts and performs a callback function.
// Stops iteration when callback returns true.
func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, cb func(account types.AccountI) (stop bool)) {
func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, cb func(account sdk.AccountI) (stop bool)) {
store := ctx.KVStore(ak.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.AddressStoreKeyPrefix)

Expand Down
10 changes: 5 additions & 5 deletions x/auth/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (suite *DeterministicTestSuite) SetupTest() {
}

// createAndSetAccount creates a random account and sets to the keeper store.
func (suite *DeterministicTestSuite) createAndSetAccounts(t *rapid.T, count int) []types.AccountI {
accs := make([]types.AccountI, 0, count)
func (suite *DeterministicTestSuite) createAndSetAccounts(t *rapid.T, count int) []sdk.AccountI {
accs := make([]sdk.AccountI, 0, count)

// We need all generated account-numbers unique
accNums := rapid.SliceOfNDistinct(rapid.Uint64(), count, count, func(i uint64) uint64 { return i }).Draw(t, "acc-numss")
Expand Down Expand Up @@ -239,12 +239,12 @@ func (suite *DeterministicTestSuite) createAndReturnQueryClient(ak keeper.Accoun

func (suite *DeterministicTestSuite) setModuleAccounts(
ctx sdk.Context, ak keeper.AccountKeeper, maccs []string,
) []types.AccountI {
) []sdk.AccountI {
sort.Strings(maccs)
moduleAccounts := make([]types.AccountI, 0, len(maccs))
moduleAccounts := make([]sdk.AccountI, 0, len(maccs))
for _, m := range maccs {
acc, _ := ak.GetModuleAccountAndPermissions(ctx, m)
acc1, ok := acc.(types.AccountI)
acc1, ok := acc.(sdk.AccountI)
suite.Require().True(ok)
moduleAccounts = append(moduleAccounts, acc1)
}
Expand Down
2 changes: 1 addition & 1 deletion x/auth/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (ak AccountKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := ak.GetParams(ctx)

var genAccounts types.GenesisAccounts
ak.IterateAccounts(ctx, func(account types.AccountI) bool {
ak.IterateAccounts(ctx, func(account sdk.AccountI) bool {
genAccount := account.(types.GenesisAccount)
genAccounts = append(genAccounts, genAccount)
return false
Expand Down
20 changes: 10 additions & 10 deletions x/auth/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccounts() {
func(res *types.QueryAccountsResponse) {
addresses := make([]sdk.AccAddress, len(res.Accounts))
for i, acc := range res.Accounts {
var account types.AccountI
var account sdk.AccountI
err := suite.encCfg.InterfaceRegistry.UnpackAny(acc, &account)
suite.Require().NoError(err)
addresses[i] = account.GetAddress()
Expand Down Expand Up @@ -123,7 +123,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccount() {
},
true,
func(res *types.QueryAccountResponse) {
var newAccount types.AccountI
var newAccount sdk.AccountI
err := suite.encCfg.InterfaceRegistry.UnpackAny(res.Account, &newAccount)
suite.Require().NoError(err)
suite.Require().NotNil(newAccount)
Expand Down Expand Up @@ -280,11 +280,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryModuleAccounts() {
func(res *types.QueryModuleAccountsResponse) {
mintModuleExists := false
for _, acc := range res.Accounts {
var account types.AccountI
var account sdk.AccountI
err := suite.encCfg.InterfaceRegistry.UnpackAny(acc, &account)
suite.Require().NoError(err)

moduleAccount, ok := account.(types.ModuleAccountI)
moduleAccount, ok := account.(sdk.ModuleAccountI)

suite.Require().True(ok)
if moduleAccount.GetName() == "mint" {
Expand All @@ -303,11 +303,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryModuleAccounts() {
func(res *types.QueryModuleAccountsResponse) {
mintModuleExists := false
for _, acc := range res.Accounts {
var account types.AccountI
var account sdk.AccountI
err := suite.encCfg.InterfaceRegistry.UnpackAny(acc, &account)
suite.Require().NoError(err)

moduleAccount, ok := account.(types.ModuleAccountI)
moduleAccount, ok := account.(sdk.ModuleAccountI)

suite.Require().True(ok)
if moduleAccount.GetName() == "falseCase" {
Expand All @@ -332,10 +332,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryModuleAccounts() {
// Make sure output is sorted alphabetically.
var moduleNames []string
for _, any := range res.Accounts {
var account types.AccountI
var account sdk.AccountI
err := suite.encCfg.InterfaceRegistry.UnpackAny(any, &account)
suite.Require().NoError(err)
moduleAccount, ok := account.(types.ModuleAccountI)
moduleAccount, ok := account.(sdk.ModuleAccountI)
suite.Require().True(ok)
moduleNames = append(moduleNames, moduleAccount.GetName())
}
Expand Down Expand Up @@ -366,11 +366,11 @@ func (suite *KeeperTestSuite) TestGRPCQueryModuleAccountByName() {
},
true,
func(res *types.QueryModuleAccountByNameResponse) {
var account types.AccountI
var account sdk.AccountI
err := suite.encCfg.InterfaceRegistry.UnpackAny(res.Account, &account)
suite.Require().NoError(err)

moduleAccount, ok := account.(types.ModuleAccountI)
moduleAccount, ok := account.(sdk.ModuleAccountI)
suite.Require().True(ok)
suite.Require().Equal(moduleAccount.GetName(), "mint")
},
Expand Down
Loading