From 31a36f117d3d71cbec29502fab30b3d07f418934 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 5 Apr 2023 12:38:20 +0200 Subject: [PATCH 1/9] remove global bech32 from groups --- x/evidence/testutil/expected_keepers_mocks.go | 9 ++--- x/feegrant/testutil/expected_keepers_mocks.go | 2 +- x/group/client/cli/tx.go | 10 +++--- x/group/client/cli/tx_test.go | 3 +- x/group/expected_keepers.go | 3 ++ x/group/keeper/grpc_query.go | 14 ++++---- x/group/keeper/keeper.go | 20 +++++------ x/group/keeper/keeper_test.go | 36 ++++++++++--------- x/group/keeper/msg_server.go | 27 +++++++------- x/group/module/abci_test.go | 32 +++++++++++------ x/group/module/module.go | 6 ++-- x/group/testutil/expected_keepers_mocks.go | 30 ++++++++++++++++ 12 files changed, 122 insertions(+), 70 deletions(-) diff --git a/x/evidence/testutil/expected_keepers_mocks.go b/x/evidence/testutil/expected_keepers_mocks.go index 845322d2ce1a..e6b93cdf7f43 100644 --- a/x/evidence/testutil/expected_keepers_mocks.go +++ b/x/evidence/testutil/expected_keepers_mocks.go @@ -9,6 +9,7 @@ import ( reflect "reflect" time "time" + math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/crypto/types" types0 "github.com/cosmos/cosmos-sdk/types" types1 "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -157,7 +158,7 @@ func (mr *MockSlashingKeeperMockRecorder) JailUntil(arg0, arg1, arg2 interface{} } // Slash mocks base method. -func (m *MockSlashingKeeper) Slash(arg0 types0.Context, arg1 types0.ConsAddress, arg2 types0.Dec, arg3, arg4 int64) { +func (m *MockSlashingKeeper) Slash(arg0 types0.Context, arg1 types0.ConsAddress, arg2 math.LegacyDec, arg3, arg4 int64) { m.ctrl.T.Helper() m.ctrl.Call(m, "Slash", arg0, arg1, arg2, arg3, arg4) } @@ -169,10 +170,10 @@ func (mr *MockSlashingKeeperMockRecorder) Slash(arg0, arg1, arg2, arg3, arg4 int } // SlashFractionDoubleSign mocks base method. -func (m *MockSlashingKeeper) SlashFractionDoubleSign(arg0 types0.Context) types0.Dec { +func (m *MockSlashingKeeper) SlashFractionDoubleSign(arg0 types0.Context) math.LegacyDec { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SlashFractionDoubleSign", arg0) - ret0, _ := ret[0].(types0.Dec) + ret0, _ := ret[0].(math.LegacyDec) return ret0 } @@ -183,7 +184,7 @@ func (mr *MockSlashingKeeperMockRecorder) SlashFractionDoubleSign(arg0 interface } // SlashWithInfractionReason mocks base method. -func (m *MockSlashingKeeper) SlashWithInfractionReason(arg0 types0.Context, arg1 types0.ConsAddress, arg2 types0.Dec, arg3, arg4 int64, arg5 types1.Infraction) { +func (m *MockSlashingKeeper) SlashWithInfractionReason(arg0 types0.Context, arg1 types0.ConsAddress, arg2 math.LegacyDec, arg3, arg4 int64, arg5 types1.Infraction) { m.ctrl.T.Helper() m.ctrl.Call(m, "SlashWithInfractionReason", arg0, arg1, arg2, arg3, arg4, arg5) } diff --git a/x/feegrant/testutil/expected_keepers_mocks.go b/x/feegrant/testutil/expected_keepers_mocks.go index e659ee5cf601..b73d1735322d 100644 --- a/x/feegrant/testutil/expected_keepers_mocks.go +++ b/x/feegrant/testutil/expected_keepers_mocks.go @@ -5,7 +5,7 @@ package testutil import ( - "context" + context "context" reflect "reflect" types "github.com/cosmos/cosmos-sdk/types" diff --git a/x/group/client/cli/tx.go b/x/group/client/cli/tx.go index 93dc5627d16b..349e3c747925 100644 --- a/x/group/client/cli/tx.go +++ b/x/group/client/cli/tx.go @@ -5,12 +5,12 @@ import ( "fmt" "strconv" + "cosmossdk.io/core/address" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/group" ) @@ -22,7 +22,7 @@ const ( ) // TxCmd returns a root CLI command handler for all x/group transaction commands. -func TxCmd(name string) *cobra.Command { +func TxCmd(name string, ac address.Codec) *cobra.Command { txCmd := &cobra.Command{ Use: name, Short: "Group transaction subcommands", @@ -39,7 +39,7 @@ func TxCmd(name string) *cobra.Command { MsgCreateGroupWithPolicyCmd(), MsgCreateGroupPolicyCmd(), MsgUpdateGroupPolicyAdminCmd(), - MsgUpdateGroupPolicyDecisionPolicyCmd(), + MsgUpdateGroupPolicyDecisionPolicyCmd(ac), MsgUpdateGroupPolicyMetadataCmd(), MsgWithdrawProposalCmd(), MsgSubmitProposalCmd(), @@ -461,7 +461,7 @@ func MsgUpdateGroupPolicyAdminCmd() *cobra.Command { } // MsgUpdateGroupPolicyDecisionPolicyCmd creates a CLI command for Msg/UpdateGroupPolicyDecisionPolicy. -func MsgUpdateGroupPolicyDecisionPolicyCmd() *cobra.Command { +func MsgUpdateGroupPolicyDecisionPolicyCmd(ac address.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "update-group-policy-decision-policy [admin] [group-policy-account] [decision-policy-json-file]", Short: "Update a group policy's decision policy", @@ -482,7 +482,7 @@ func MsgUpdateGroupPolicyDecisionPolicyCmd() *cobra.Command { return err } - accountAddress, err := sdk.AccAddressFromBech32(args[1]) + accountAddress, err := ac.StringToBytes(args[1]) if err != nil { return err } diff --git a/x/group/client/cli/tx_test.go b/x/group/client/cli/tx_test.go index 46f35b137c80..c06eb5ba7f8e 100644 --- a/x/group/client/cli/tx_test.go +++ b/x/group/client/cli/tx_test.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" @@ -1181,7 +1182,7 @@ func (s *CLITestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { invalidNegativePercentageDecisionPolicy := testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"-0.5", "windows":{"voting_period":"1s"}}`) invalidPercentageDecisionPolicy := testutil.WriteToNewTempFile(s.T(), `{"@type":"/cosmos.group.v1.PercentageDecisionPolicy", "percentage":"2", "windows":{"voting_period":"40000s"}}`) - cmd := groupcli.MsgUpdateGroupPolicyDecisionPolicyCmd() + cmd := groupcli.MsgUpdateGroupPolicyDecisionPolicyCmd(address.NewBech32Codec("cosmos")) cmd.SetOutput(io.Discard) testCases := []struct { diff --git a/x/group/expected_keepers.go b/x/group/expected_keepers.go index 037d639604a3..e346fd513652 100644 --- a/x/group/expected_keepers.go +++ b/x/group/expected_keepers.go @@ -3,10 +3,13 @@ package group import ( context "context" + "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" ) type AccountKeeper interface { + address.Codec + // NewAccount returns a new account with the next account number. Does not save the new account to the store. NewAccount(context.Context, sdk.AccountI) sdk.AccountI diff --git a/x/group/keeper/grpc_query.go b/x/group/keeper/grpc_query.go index a54e3bedf293..aeabe5ca4700 100644 --- a/x/group/keeper/grpc_query.go +++ b/x/group/keeper/grpc_query.go @@ -83,7 +83,7 @@ func (k Keeper) getGroupMembers(ctx sdk.Context, id uint64, pageRequest *query.P // GroupsByAdmin queries all groups where a given address is admin. func (k Keeper) GroupsByAdmin(goCtx context.Context, request *group.QueryGroupsByAdminRequest) (*group.QueryGroupsByAdminResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - addr, err := sdk.AccAddressFromBech32(request.Admin) + addr, err := k.accKeeper.StringToBytes(request.Admin) if err != nil { return nil, err } @@ -139,7 +139,7 @@ func (k Keeper) getGroupPoliciesByGroup(ctx sdk.Context, id uint64, pageRequest // admin. func (k Keeper) GroupPoliciesByAdmin(goCtx context.Context, request *group.QueryGroupPoliciesByAdminRequest) (*group.QueryGroupPoliciesByAdminResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - addr, err := sdk.AccAddressFromBech32(request.Admin) + addr, err := k.accKeeper.StringToBytes(request.Admin) if err != nil { return nil, err } @@ -180,7 +180,7 @@ func (k Keeper) Proposal(goCtx context.Context, request *group.QueryProposalRequ // ProposalsByGroupPolicy queries all proposals of a group policy. func (k Keeper) ProposalsByGroupPolicy(goCtx context.Context, request *group.QueryProposalsByGroupPolicyRequest) (*group.QueryProposalsByGroupPolicyResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - addr, err := sdk.AccAddressFromBech32(request.Address) + addr, err := k.accKeeper.StringToBytes(request.Address) if err != nil { return nil, err } @@ -218,7 +218,7 @@ func (k Keeper) getProposal(ctx sdk.Context, proposalID uint64) (group.Proposal, // VoteByProposalVoter queries a vote given a voter and a proposal ID. func (k Keeper) VoteByProposalVoter(goCtx context.Context, request *group.QueryVoteByProposalVoterRequest) (*group.QueryVoteByProposalVoterResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - addr, err := sdk.AccAddressFromBech32(request.Voter) + addr, err := k.accKeeper.StringToBytes(request.Voter) if err != nil { return nil, err } @@ -256,7 +256,7 @@ func (k Keeper) VotesByProposal(goCtx context.Context, request *group.QueryVotes // VotesByVoter queries all votes of a voter. func (k Keeper) VotesByVoter(goCtx context.Context, request *group.QueryVotesByVoterRequest) (*group.QueryVotesByVoterResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - addr, err := sdk.AccAddressFromBech32(request.Voter) + addr, err := k.accKeeper.StringToBytes(request.Voter) if err != nil { return nil, err } @@ -284,12 +284,12 @@ func (k Keeper) GroupsByMember(goCtx context.Context, request *group.QueryGroups } ctx := sdk.UnwrapSDKContext(goCtx) - member, err := sdk.AccAddressFromBech32(request.Address) + member, err := k.accKeeper.StringToBytes(request.Address) if err != nil { return nil, err } - iter, err := k.groupMemberByMemberIndex.GetPaginated(ctx.KVStore(k.key), member.Bytes(), request.Pagination) + iter, err := k.groupMemberByMemberIndex.GetPaginated(ctx.KVStore(k.key), member, request.Pagination) if err != nil { return nil, err } diff --git a/x/group/keeper/keeper.go b/x/group/keeper/keeper.go index 73df21e9372f..c3b705b2c369 100644 --- a/x/group/keeper/keeper.go +++ b/x/group/keeper/keeper.go @@ -94,11 +94,11 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.Mes panic(err.Error()) } k.groupByAdminIndex, err = orm.NewIndex(groupTable, GroupByAdminIndexPrefix, func(val interface{}) ([]interface{}, error) { - addr, err := sdk.AccAddressFromBech32(val.(*group.GroupInfo).Admin) + addr, err := accKeeper.StringToBytes(val.(*group.GroupInfo).Admin) if err != nil { return nil, err } - return []interface{}{addr.Bytes()}, nil + return []interface{}{addr}, nil }, []byte{}) if err != nil { panic(err.Error()) @@ -119,11 +119,11 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.Mes } k.groupMemberByMemberIndex, err = orm.NewIndex(groupMemberTable, GroupMemberByMemberIndexPrefix, func(val interface{}) ([]interface{}, error) { memberAddr := val.(*group.GroupMember).Member.Address - addr, err := sdk.AccAddressFromBech32(memberAddr) + addr, err := accKeeper.StringToBytes(memberAddr) if err != nil { return nil, err } - return []interface{}{addr.Bytes()}, nil + return []interface{}{addr}, nil }, []byte{}) if err != nil { panic(err.Error()) @@ -144,11 +144,11 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.Mes } k.groupPolicyByAdminIndex, err = orm.NewIndex(groupPolicyTable, GroupPolicyByAdminIndexPrefix, func(value interface{}) ([]interface{}, error) { admin := value.(*group.GroupPolicyInfo).Admin - addr, err := sdk.AccAddressFromBech32(admin) + addr, err := accKeeper.StringToBytes(admin) if err != nil { return nil, err } - return []interface{}{addr.Bytes()}, nil + return []interface{}{addr}, nil }, []byte{}) if err != nil { panic(err.Error()) @@ -162,11 +162,11 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.Mes } k.proposalByGroupPolicyIndex, err = orm.NewIndex(proposalTable, ProposalByGroupPolicyIndexPrefix, func(value interface{}) ([]interface{}, error) { account := value.(*group.Proposal).GroupPolicyAddress - addr, err := sdk.AccAddressFromBech32(account) + addr, err := accKeeper.StringToBytes(account) if err != nil { return nil, err } - return []interface{}{addr.Bytes()}, nil + return []interface{}{addr}, nil }, []byte{}) if err != nil { panic(err.Error()) @@ -192,11 +192,11 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.Mes panic(err.Error()) } k.voteByVoterIndex, err = orm.NewIndex(voteTable, VoteByVoterIndexPrefix, func(value interface{}) ([]interface{}, error) { - addr, err := sdk.AccAddressFromBech32(value.(*group.Vote).Voter) + addr, err := accKeeper.StringToBytes(value.(*group.Vote).Voter) if err != nil { return nil, err } - return []interface{}{addr.Bytes()}, nil + return []interface{}{addr}, nil }, []byte{}) if err != nil { panic(err.Error()) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 40a25f591eba..be9ca7d51f92 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -62,8 +62,11 @@ func (s *TestSuite) SetupTest() { // setup gomock and initialize some globally expected executions ctrl := gomock.NewController(s.T()) s.accountKeeper = grouptestutil.NewMockAccountKeeper(ctrl) - for i := range s.addrs { + for i, addr := range s.addrs { s.accountKeeper.EXPECT().GetAccount(gomock.Any(), s.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(s.addrs[i])).AnyTimes() + s.accountKeeper.EXPECT().BytesToString(addr).Return(addr.String(), nil).AnyTimes() + s.accountKeeper.EXPECT().StringToBytes(addr.String()).Return(addr, nil).AnyTimes() + } s.bankKeeper = grouptestutil.NewMockBankKeeper(ctrl) @@ -114,7 +117,7 @@ func (s *TestSuite) SetupTest() { policyRes, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) s.policy = policy - addr, err := sdk.AccAddressFromBech32(policyRes.Address) + addr, err := s.accountKeeper.StringToBytes(policyRes.Address) s.Require().NoError(err) s.groupPolicyAddr = addr @@ -308,9 +311,9 @@ func (s *TestSuite) TestCreateGroup() { s.Require().Equal(len(members), len(loadedMembers)) // we reorder members by address to be able to compare them sort.Slice(members, func(i, j int) bool { - addri, err := sdk.AccAddressFromBech32(members[i].Address) + addri, err := s.accountKeeper.StringToBytes(members[i].Address) s.Require().NoError(err) - addrj, err := sdk.AccAddressFromBech32(members[j].Address) + addrj, err := s.accountKeeper.StringToBytes(members[j].Address) s.Require().NoError(err) return bytes.Compare(addri, addrj) < 0 }) @@ -768,9 +771,9 @@ func (s *TestSuite) TestUpdateGroupMembers() { s.Require().Equal(len(spec.expMembers), len(loadedMembers)) // we reorder group members by address to be able to compare them sort.Slice(spec.expMembers, func(i, j int) bool { - addri, err := sdk.AccAddressFromBech32(spec.expMembers[i].Member.Address) + addri, err := s.accountKeeper.StringToBytes(spec.expMembers[i].Member.Address) s.Require().NoError(err) - addrj, err := sdk.AccAddressFromBech32(spec.expMembers[j].Member.Address) + addrj, err := s.accountKeeper.StringToBytes(spec.expMembers[j].Member.Address) s.Require().NoError(err) return bytes.Compare(addri, addrj) < 0 }) @@ -962,9 +965,9 @@ func (s *TestSuite) TestCreateGroupWithPolicy() { s.Require().Equal(len(members), len(loadedMembers)) // we reorder members by address to be able to compare them sort.Slice(members, func(i, j int) bool { - addri, err := sdk.AccAddressFromBech32(members[i].Address) + addri, err := s.accountKeeper.StringToBytes(members[i].Address) s.Require().NoError(err) - addrj, err := sdk.AccAddressFromBech32(members[j].Address) + addrj, err := s.accountKeeper.StringToBytes(members[j].Address) s.Require().NoError(err) return bytes.Compare(addri, addrj) < 0 }) @@ -1594,7 +1597,8 @@ func (s *TestSuite) TestSubmitProposal() { s.setNextAccount() res, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) - noMinExecPeriodPolicyAddr := sdk.MustAccAddressFromBech32(res.Address) + noMinExecPeriodPolicyAddr, err := s.accountKeeper.StringToBytes(res.Address) + s.Require().NoError(err) // Create a new group policy with super high threshold bigThresholdPolicy := group.NewThresholdDecisionPolicy( @@ -1610,7 +1614,7 @@ func (s *TestSuite) TestSubmitProposal() { bigThresholdAddr := bigThresholdRes.Address msgSend := &banktypes.MsgSend{ - FromAddress: noMinExecPeriodPolicyAddr.String(), + FromAddress: res.Address, ToAddress: addr2.String(), Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)}, } @@ -1732,13 +1736,13 @@ func (s *TestSuite) TestSubmitProposal() { } }, req: &group.MsgSubmitProposal{ - GroupPolicyAddress: noMinExecPeriodPolicyAddr.String(), + GroupPolicyAddress: res.Address, Proposers: []string{addr2.String()}, Exec: group.Exec_EXEC_TRY, }, msgs: []sdk.Msg{msgSend}, expProposal: group.Proposal{ - GroupPolicyAddress: noMinExecPeriodPolicyAddr.String(), + GroupPolicyAddress: res.Address, Status: group.PROPOSAL_STATUS_ACCEPTED, FinalTallyResult: group.TallyResult{ YesCount: "2", @@ -1760,13 +1764,13 @@ func (s *TestSuite) TestSubmitProposal() { }, "with try exec, not enough yes votes for proposal to pass": { req: &group.MsgSubmitProposal{ - GroupPolicyAddress: noMinExecPeriodPolicyAddr.String(), + GroupPolicyAddress: res.Address, Proposers: []string{addr5.String()}, Exec: group.Exec_EXEC_TRY, }, msgs: []sdk.Msg{msgSend}, expProposal: group.Proposal{ - GroupPolicyAddress: noMinExecPeriodPolicyAddr.String(), + GroupPolicyAddress: res.Address, Status: group.PROPOSAL_STATUS_SUBMITTED, FinalTallyResult: group.TallyResult{ YesCount: "0", // Since tally doesn't pass Allow(), we consider the proposal not final @@ -1950,7 +1954,7 @@ func (s *TestSuite) TestVote() { policyRes, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) accountAddr := policyRes.Address - groupPolicy, err := sdk.AccAddressFromBech32(accountAddr) + groupPolicy, err := s.accountKeeper.StringToBytes(accountAddr) s.Require().NoError(err) s.Require().NotNil(groupPolicy) @@ -3262,7 +3266,7 @@ func (s *TestSuite) TestTallyProposalsAtVPEnd() { groupRes, err := s.groupKeeper.CreateGroupWithPolicy(s.ctx, groupMsg) s.Require().NoError(err) accountAddr := groupRes.GetGroupPolicyAddress() - groupPolicy, err := sdk.AccAddressFromBech32(accountAddr) + groupPolicy, err := s.accountKeeper.StringToBytes(accountAddr) s.Require().NoError(err) s.Require().NotNil(groupPolicy) diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index 999fbfe4f3de..76f4ba5c9968 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -1,6 +1,7 @@ package keeper import ( + "bytes" "context" "encoding/binary" "fmt" @@ -263,7 +264,7 @@ func (k Keeper) CreateGroupWithPolicy(goCtx context.Context, req *group.MsgCreat } policyAddr := groupPolicyRes.Address - groupPolicyAddr, err = sdk.AccAddressFromBech32(policyAddr) + groupPolicyAddr, err = k.accKeeper.StringToBytes(policyAddr) if err != nil { return nil, errorsmod.Wrap(err, "group policy address") } @@ -296,7 +297,7 @@ func (k Keeper) CreateGroupWithPolicy(goCtx context.Context, req *group.MsgCreat func (k Keeper) CreateGroupPolicy(goCtx context.Context, req *group.MsgCreateGroupPolicy) (*group.MsgCreateGroupPolicyResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - admin, err := sdk.AccAddressFromBech32(req.GetAdmin()) + admin, err := k.accKeeper.StringToBytes(req.GetAdmin()) if err != nil { return nil, errorsmod.Wrap(err, "request admin") } @@ -315,12 +316,12 @@ func (k Keeper) CreateGroupPolicy(goCtx context.Context, req *group.MsgCreateGro if err != nil { return nil, err } - groupAdmin, err := sdk.AccAddressFromBech32(g.Admin) + groupAdmin, err := k.accKeeper.StringToBytes(g.Admin) if err != nil { return nil, errorsmod.Wrap(err, "group admin") } // Only current group admin is authorized to create a group policy for this - if !groupAdmin.Equals(admin) { + if !bytes.Equal(groupAdmin, admin) { return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "not group admin") } @@ -461,7 +462,7 @@ func (k Keeper) UpdateGroupPolicyMetadata(goCtx context.Context, req *group.MsgU func (k Keeper) SubmitProposal(goCtx context.Context, req *group.MsgSubmitProposal) (*group.MsgSubmitProposalResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - groupPolicyAddr, err := sdk.AccAddressFromBech32(req.GroupPolicyAddress) + groupPolicyAddr, err := k.accKeeper.StringToBytes(req.GroupPolicyAddress) if err != nil { return nil, errorsmod.Wrap(err, "request account address of group policy") } @@ -761,7 +762,7 @@ func (k Keeper) Exec(goCtx context.Context, req *group.MsgExec) (*group.MsgExecR // Caching context so that we don't update the store in case of failure. cacheCtx, flush := ctx.CacheContext() - addr, err := sdk.AccAddressFromBech32(policyInfo.Address) + addr, err := k.accKeeper.StringToBytes(policyInfo.Address) if err != nil { return nil, err } @@ -812,7 +813,7 @@ func (k Keeper) Exec(goCtx context.Context, req *group.MsgExec) (*group.MsgExecR // LeaveGroup implements the MsgServer/LeaveGroup method. func (k Keeper) LeaveGroup(goCtx context.Context, req *group.MsgLeaveGroup) (*group.MsgLeaveGroupResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - _, err := sdk.AccAddressFromBech32(req.Address) + _, err := k.accKeeper.StringToBytes(req.Address) if err != nil { return nil, err } @@ -903,18 +904,18 @@ func (k Keeper) doUpdateGroupPolicy(ctx sdk.Context, groupPolicy, admin string, return errorsmod.Wrap(err, "load group policy") } - groupPolicyAddr, err := sdk.AccAddressFromBech32(groupPolicy) + groupPolicyAddr, err := k.accKeeper.StringToBytes(groupPolicy) if err != nil { return errorsmod.Wrap(err, "group policy address") } - groupPolicyAdmin, err := sdk.AccAddressFromBech32(admin) + _, err = k.accKeeper.StringToBytes(admin) if err != nil { return errorsmod.Wrap(err, "group policy admin") } // Only current group policy admin is authorized to update a group policy. - if groupPolicyAdmin.String() != groupPolicyInfo.Admin { + if admin != groupPolicyInfo.Admin { return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "not group policy admin") } @@ -956,15 +957,15 @@ func (k Keeper) doAuthenticated(ctx sdk.Context, req authNGroupReq, action actio if err != nil { return err } - admin, err := sdk.AccAddressFromBech32(group.Admin) + admin, err := k.accKeeper.StringToBytes(group.Admin) if err != nil { return errorsmod.Wrap(err, "group admin") } - reqAdmin, err := sdk.AccAddressFromBech32(req.GetAdmin()) + reqAdmin, err := k.accKeeper.StringToBytes(req.GetAdmin()) if err != nil { return errorsmod.Wrap(err, "request admin") } - if !admin.Equals(reqAdmin) { + if !bytes.Equal(admin, reqAdmin) { return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "not group admin; got %s, expected %s", req.GetAdmin(), group.Admin) } if err := action(&group); err != nil { diff --git a/x/group/module/abci_test.go b/x/group/module/abci_test.go index f4d006f375c4..b8a0e89e572d 100644 --- a/x/group/module/abci_test.go +++ b/x/group/module/abci_test.go @@ -5,8 +5,11 @@ import ( "testing" "time" + "cosmossdk.io/core/address" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttime "github.com/cometbft/cometbft/types/time" + codecaddress "github.com/cosmos/cosmos-sdk/codec/address" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -32,6 +35,8 @@ type IntegrationTestSuite struct { bankKeeper bankkeeper.Keeper stakingKeeper *stakingkeeper.Keeper interfaceRegistry codectypes.InterfaceRegistry + + addressCodec address.Codec } func TestIntegrationTestSuite(t *testing.T) { @@ -54,6 +59,8 @@ func (s *IntegrationTestSuite) SetupTest() { s.ctx = ctx s.addrs = simtestutil.AddTestAddrsIncremental(s.bankKeeper, s.stakingKeeper, ctx, 4, sdk.NewInt(30000000)) + + s.addressCodec = codecaddress.NewBech32Codec("cosmos") } func (s *IntegrationTestSuite) TestEndBlockerPruning() { @@ -62,13 +69,16 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() { addr2 := s.addrs[1] addr3 := s.addrs[2] + addr1st, err := s.addressCodec.BytesToString(addr1) + s.Require().NoError(err) + // Initial group, group policy and balance setup members := []group.MemberRequest{ - {Address: addr1.String(), Weight: "1"}, {Address: addr2.String(), Weight: "2"}, + {Address: addr1st, Weight: "1"}, {Address: addr2.String(), Weight: "2"}, } groupRes, err := s.groupKeeper.CreateGroup(ctx, &group.MsgCreateGroup{ - Admin: addr1.String(), + Admin: addr1st, Members: members, }) s.Require().NoError(err) @@ -114,23 +124,23 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() { policyRes2, err := s.groupKeeper.CreateGroupPolicy(ctx, policyReq2) s.Require().NoError(err) - groupPolicyAddr, err := sdk.AccAddressFromBech32(policyRes.Address) + groupPolicyAddr, err := s.addressCodec.StringToBytes(policyRes.Address) s.Require().NoError(err) s.Require().NoError(testutil.FundAccount(s.bankKeeper, ctx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10000)})) - groupPolicyAddr2, err := sdk.AccAddressFromBech32(policyRes2.Address) + groupPolicyAddr2, err := s.addressCodec.StringToBytes(policyRes2.Address) s.Require().NoError(err) s.Require().NoError(testutil.FundAccount(s.bankKeeper, ctx, groupPolicyAddr2, sdk.Coins{sdk.NewInt64Coin("test", 10000)})) votingPeriod := policy.GetVotingPeriod() msgSend1 := &banktypes.MsgSend{ - FromAddress: groupPolicyAddr.String(), + FromAddress: policyRes.Address, ToAddress: addr2.String(), Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)}, } msgSend2 := &banktypes.MsgSend{ - FromAddress: groupPolicyAddr2.String(), + FromAddress: policyRes2.Address, ToAddress: addr2.String(), Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)}, } @@ -213,7 +223,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() { s.Require().NoError(err) _, err = s.groupKeeper.UpdateGroupPolicyMetadata(ctx, &group.MsgUpdateGroupPolicyMetadata{ Admin: addr1.String(), - GroupPolicyAddress: groupPolicyAddr.String(), + GroupPolicyAddress: policyRes.Address, }) s.Require().NoError(err) _, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID}) @@ -279,7 +289,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() { policy := group.NewThresholdDecisionPolicy("3", time.Second, 0) msg := &group.MsgUpdateGroupPolicyDecisionPolicy{ Admin: s.addrs[1].String(), - GroupPolicyAddress: groupPolicyAddr2.String(), + GroupPolicyAddress: policyRes2.Address, } err = msg.SetDecisionPolicy(policy) s.Require().NoError(err) @@ -301,7 +311,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() { policy := group.NewThresholdDecisionPolicy("3", time.Second, 0) msg := &group.MsgUpdateGroupPolicyDecisionPolicy{ Admin: s.addrs[1].String(), - GroupPolicyAddress: groupPolicyAddr2.String(), + GroupPolicyAddress: policyRes2.Address, } err = msg.SetDecisionPolicy(policy) s.Require().NoError(err) @@ -389,13 +399,13 @@ func (s *IntegrationTestSuite) TestEndBlockerTallying() { policyRes, err := s.groupKeeper.CreateGroupPolicy(ctx, policyReq) s.Require().NoError(err) - groupPolicyAddr, err := sdk.AccAddressFromBech32(policyRes.Address) + groupPolicyAddr, err := s.addressCodec.StringToBytes(policyRes.Address) s.Require().NoError(err) votingPeriod := policy.GetVotingPeriod() msgSend := &banktypes.MsgSend{ - FromAddress: groupPolicyAddr.String(), + FromAddress: policyRes.Address, ToAddress: addrs[3].String(), Amount: sdk.Coins{sdk.NewInt64Coin("test", 100)}, } diff --git a/x/group/module/module.go b/x/group/module/module.go index e95536e70e8d..d073242f2263 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" modulev1 "cosmossdk.io/api/cosmos/group/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" @@ -47,7 +48,7 @@ type AppModule struct { // NewAppModule creates a new AppModule object func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak group.AccountKeeper, bk group.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule { return AppModule{ - AppModuleBasic: AppModuleBasic{cdc: cdc}, + AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak}, keeper: keeper, bankKeeper: bk, accKeeper: ak, @@ -68,6 +69,7 @@ func (am AppModule) IsAppModule() {} type AppModuleBasic struct { cdc codec.Codec + ac address.Codec } // Name returns the group module's name. @@ -97,7 +99,7 @@ func (a AppModuleBasic) GetQueryCmd() *cobra.Command { // GetTxCmd returns the transaction commands for the group module func (a AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.TxCmd(a.Name()) + return cli.TxCmd(a.Name(), a.ac) } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the group module. diff --git a/x/group/testutil/expected_keepers_mocks.go b/x/group/testutil/expected_keepers_mocks.go index a03a662ee176..ae05d4e8e1ff 100644 --- a/x/group/testutil/expected_keepers_mocks.go +++ b/x/group/testutil/expected_keepers_mocks.go @@ -36,6 +36,21 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder { return m.recorder } +// BytesToString mocks base method. +func (m *MockAccountKeeper) BytesToString(bz []byte) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BytesToString", bz) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BytesToString indicates an expected call of BytesToString. +func (mr *MockAccountKeeperMockRecorder) BytesToString(bz interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesToString", reflect.TypeOf((*MockAccountKeeper)(nil).BytesToString), bz) +} + // GetAccount mocks base method. func (m *MockAccountKeeper) GetAccount(arg0 context.Context, arg1 types.AccAddress) types.AccountI { m.ctrl.T.Helper() @@ -88,6 +103,21 @@ func (mr *MockAccountKeeperMockRecorder) SetAccount(arg0, arg1 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetAccount), arg0, arg1) } +// StringToBytes mocks base method. +func (m *MockAccountKeeper) StringToBytes(text string) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StringToBytes", text) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StringToBytes indicates an expected call of StringToBytes. +func (mr *MockAccountKeeperMockRecorder) StringToBytes(text interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringToBytes", reflect.TypeOf((*MockAccountKeeper)(nil).StringToBytes), text) +} + // MockBankKeeper is a mock of BankKeeper interface. type MockBankKeeper struct { ctrl *gomock.Controller From eeecfe12ae4d300f7e3ae69bbc51c69c541d94b8 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 5 Apr 2023 13:31:35 +0200 Subject: [PATCH 2/9] testing --- x/group/keeper/genesis_test.go | 4 ++++ x/group/keeper/grpc_query_test.go | 11 +++++------ x/group/keeper/keeper_test.go | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index 4b3a4107fd44..109cc1c2cf68 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -55,6 +55,10 @@ func (s *GenesisTestSuite) SetupTest() { accountKeeper := grouptestutil.NewMockAccountKeeper(ctrl) accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() accountKeeper.EXPECT().GetAccount(gomock.Any(), memberAddr).Return(authtypes.NewBaseAccountWithAddress(memberAddr)).AnyTimes() + accountKeeper.EXPECT().BytesToString(accAddr).Return(accAddr.String(), nil).AnyTimes() + accountKeeper.EXPECT().StringToBytes(accAddr.String()).Return(accAddr, nil).AnyTimes() + accountKeeper.EXPECT().BytesToString(memberAddr).Return(memberAddr.String(), nil).AnyTimes() + accountKeeper.EXPECT().StringToBytes(memberAddr.String()).Return(memberAddr, nil).AnyTimes() bApp := baseapp.NewBaseApp( "group", diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index a57165751511..ed37c6928a16 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -46,12 +46,11 @@ func initKeeper(t *testing.T) (types.Context, groupkeeper.Keeper, []types.AccAdd addrs := simtestutil.CreateIncrementalAccounts(6) ctrl := gomock.NewController(t) accountKeeper := grouptestutil.NewMockAccountKeeper(ctrl) - accountKeeper.EXPECT().GetAccount(gomock.Any(), addrs[0]).Return(authtypes.NewBaseAccountWithAddress(addrs[0])).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), addrs[1]).Return(authtypes.NewBaseAccountWithAddress(addrs[1])).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), addrs[2]).Return(authtypes.NewBaseAccountWithAddress(addrs[2])).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), addrs[3]).Return(authtypes.NewBaseAccountWithAddress(addrs[3])).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), addrs[4]).Return(authtypes.NewBaseAccountWithAddress(addrs[4])).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), addrs[5]).Return(authtypes.NewBaseAccountWithAddress(addrs[5])).AnyTimes() + for _, addr := range addrs { + accountKeeper.EXPECT().GetAccount(gomock.Any(), addr).Return(authtypes.NewBaseAccountWithAddress(addr)).AnyTimes() + accountKeeper.EXPECT().BytesToString(addr).Return(addr.String(), nil).AnyTimes() + accountKeeper.EXPECT().StringToBytes(addr.String()).Return(addr, nil).AnyTimes() + } groupKeeper = groupkeeper.NewKeeper(key, encCfg.Codec, bApp.MsgServiceRouter(), accountKeeper, group.DefaultConfig()) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index be9ca7d51f92..edb0985f5483 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -18,6 +18,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -62,12 +63,12 @@ func (s *TestSuite) SetupTest() { // setup gomock and initialize some globally expected executions ctrl := gomock.NewController(s.T()) s.accountKeeper = grouptestutil.NewMockAccountKeeper(ctrl) - for i, addr := range s.addrs { + for i := range s.addrs { s.accountKeeper.EXPECT().GetAccount(gomock.Any(), s.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(s.addrs[i])).AnyTimes() - s.accountKeeper.EXPECT().BytesToString(addr).Return(addr.String(), nil).AnyTimes() - s.accountKeeper.EXPECT().StringToBytes(addr.String()).Return(addr, nil).AnyTimes() - + s.accountKeeper.EXPECT().BytesToString(s.addrs[i]).Return(s.addrs[i].String(), nil).AnyTimes() + s.accountKeeper.EXPECT().StringToBytes(s.addrs[i].String()).Return(s.addrs[i], nil).AnyTimes() } + s.bankKeeper = grouptestutil.NewMockBankKeeper(ctrl) bApp := baseapp.NewBaseApp( @@ -114,12 +115,10 @@ func (s *TestSuite) SetupTest() { groupSeq := s.groupKeeper.GetGroupSequence(s.sdkCtx) s.Require().Equal(groupSeq, uint64(1)) - policyRes, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) + _, err = s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) s.policy = policy - addr, err := s.accountKeeper.StringToBytes(policyRes.Address) - s.Require().NoError(err) - s.groupPolicyAddr = addr + s.groupPolicyAddr = s.addrs[0] s.bankKeeper.EXPECT().MintCoins(s.sdkCtx, minttypes.ModuleName, sdk.Coins{sdk.NewInt64Coin("test", 100000)}).Return(nil).AnyTimes() s.bankKeeper.MintCoins(s.sdkCtx, minttypes.ModuleName, sdk.Coins{sdk.NewInt64Coin("test", 100000)}) @@ -1954,6 +1953,10 @@ func (s *TestSuite) TestVote() { policyRes, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) accountAddr := policyRes.Address + // module account will be created and returned + addrbz, err := address.NewBech32Codec("cosmos").StringToBytes(accountAddr) + s.Require().NoError(err) + s.accountKeeper.EXPECT().StringToBytes(accountAddr).Return(addrbz, nil).AnyTimes() groupPolicy, err := s.accountKeeper.StringToBytes(accountAddr) s.Require().NoError(err) s.Require().NotNil(groupPolicy) From 11aa13657f83a8eaf5cd838256247abb8cb5658b Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 12 Apr 2023 23:01:10 +0200 Subject: [PATCH 3/9] some changes --- tests/e2e/group/tx.go | 3 ++- x/group/keeper/keeper_test.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/e2e/group/tx.go b/tests/e2e/group/tx.go index 6b6265c6c73b..b0773eab2483 100644 --- a/tests/e2e/group/tx.go +++ b/tests/e2e/group/tx.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil" @@ -1309,7 +1310,7 @@ func (s *E2ETestSuite) TestTxUpdateGroupPolicyDecisionPolicy() { tc := tc s.Run(tc.name, func() { - cmd := client.MsgUpdateGroupPolicyDecisionPolicyCmd() + cmd := client.MsgUpdateGroupPolicyDecisionPolicyCmd(address.NewBech32Codec("cosmos")) out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args) if tc.expectErr { diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index edb0985f5483..cab83cf5eea0 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -1596,6 +1596,8 @@ func (s *TestSuite) TestSubmitProposal() { s.setNextAccount() res, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) s.Require().NoError(err) + + s.accountKeeper.EXPECT().StringToBytes(res.Address).Return(sdk.MustAccAddressFromBech32(res.Address).Bytes(), nil).AnyTimes() noMinExecPeriodPolicyAddr, err := s.accountKeeper.StringToBytes(res.Address) s.Require().NoError(err) From d3e650ddd1a4813288c180fd6eee681aef1c5879 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 12 Apr 2023 23:39:51 +0200 Subject: [PATCH 4/9] some fixes --- x/group/keeper/keeper_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index cab83cf5eea0..34e483bbaeab 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/binary" + "errors" "fmt" "sort" "strings" @@ -69,6 +70,9 @@ func (s *TestSuite) SetupTest() { s.accountKeeper.EXPECT().StringToBytes(s.addrs[i].String()).Return(s.addrs[i], nil).AnyTimes() } + // add empty string to the list of expected calls + s.accountKeeper.EXPECT().StringToBytes("").Return(nil, errors.New("unable to decode")).AnyTimes() + s.bankKeeper = grouptestutil.NewMockBankKeeper(ctrl) bApp := baseapp.NewBaseApp( @@ -141,9 +145,15 @@ func (s *TestSuite) setNextAccount() { s.Require().NoError(err) groupPolicyAccBumpAccountNumber.SetAccountNumber(nextAccVal) + addrcdc := address.NewBech32Codec("cosmos") + addrst, err := addrcdc.BytesToString(ac.Address()) + s.Require().NoError(err) + s.accountKeeper.EXPECT().GetAccount(gomock.Any(), sdk.AccAddress(ac.Address())).Return(nil).AnyTimes() s.accountKeeper.EXPECT().NewAccount(gomock.Any(), groupPolicyAcc).Return(groupPolicyAccBumpAccountNumber).AnyTimes() s.accountKeeper.EXPECT().SetAccount(gomock.Any(), sdk.AccountI(groupPolicyAccBumpAccountNumber)).Return().AnyTimes() + s.accountKeeper.EXPECT().StringToBytes(addrst).Return(ac.Address().Bytes(), nil).AnyTimes() + s.accountKeeper.EXPECT().BytesToString(ac.Address().Bytes()).Return(addrst, nil).AnyTimes() } func TestKeeperTestSuite(t *testing.T) { @@ -165,6 +175,8 @@ func (s *TestSuite) createGroupAndGetMembers(numMembers int) []*group.GroupMembe Address: addressPool[i].String(), Weight: "1", } + s.accountKeeper.EXPECT().StringToBytes(addressPool[i].String()).Return(addressPool[i].Bytes(), nil).AnyTimes() + s.accountKeeper.EXPECT().BytesToString(addressPool[i].Bytes()).Return(addressPool[i].String(), nil).AnyTimes() } g, err := s.groupKeeper.CreateGroup(s.ctx, &group.MsgCreateGroup{ @@ -2965,6 +2977,11 @@ func (s *TestSuite) TestLeaveGroup() { admin3 := addrs[6] require := s.Require() + for _, addr := range addrs { + s.accountKeeper.EXPECT().StringToBytes(addr.String()).Return(addr.Bytes(), nil).AnyTimes() + s.accountKeeper.EXPECT().BytesToString(addr).Return(addr.String(), nil).AnyTimes() + } + members := []group.MemberRequest{ { Address: member1.String(), From e32f4583ef82ceb2268148f802c5a4bdd872afaf Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 13 Apr 2023 00:02:19 +0200 Subject: [PATCH 5/9] fix tests --- x/group/keeper/keeper_test.go | 9 +++++++-- x/group/keeper/msg_server.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 34e483bbaeab..69e5031e588a 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -119,10 +119,13 @@ func (s *TestSuite) SetupTest() { groupSeq := s.groupKeeper.GetGroupSequence(s.sdkCtx) s.Require().Equal(groupSeq, uint64(1)) - _, err = s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) + policyRes, err := s.groupKeeper.CreateGroupPolicy(s.ctx, policyReq) + s.Require().NoError(err) + + addrbz, err := address.NewBech32Codec("cosmos").StringToBytes(policyRes.Address) s.Require().NoError(err) s.policy = policy - s.groupPolicyAddr = s.addrs[0] + s.groupPolicyAddr = addrbz s.bankKeeper.EXPECT().MintCoins(s.sdkCtx, minttypes.ModuleName, sdk.Coins{sdk.NewInt64Coin("test", 100000)}).Return(nil).AnyTimes() s.bankKeeper.MintCoins(s.sdkCtx, minttypes.ModuleName, sdk.Coins{sdk.NewInt64Coin("test", 100000)}) @@ -2435,6 +2438,8 @@ func (s *TestSuite) TestExecProposal() { } proposers := []string{addr2.String()} + fmt.Println(s.groupPolicyAddr.String()) + specs := map[string]struct { srcBlockTime time.Time setupProposal func(ctx context.Context) uint64 diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index 76f4ba5c9968..4f16f25fc052 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -487,7 +487,7 @@ func (k Keeper) SubmitProposal(goCtx context.Context, req *group.MsgSubmitPropos policyAcc, err := k.getGroupPolicyInfo(ctx, req.GroupPolicyAddress) if err != nil { - return nil, errorsmod.Wrap(err, "load group policy") + return nil, errorsmod.Wrapf(err, "load group policy: %s", req.GroupPolicyAddress) } g, err := k.getGroupInfo(ctx, policyAcc.GroupId) From 17ce67010d8e882110c8a4ad59ee2e02ca2f6558 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 13 Apr 2023 10:14:40 +0200 Subject: [PATCH 6/9] feedback --- x/group/keeper/keeper_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index 69e5031e588a..53d95b84a478 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -2438,8 +2438,6 @@ func (s *TestSuite) TestExecProposal() { } proposers := []string{addr2.String()} - fmt.Println(s.groupPolicyAddr.String()) - specs := map[string]struct { srcBlockTime time.Time setupProposal func(ctx context.Context) uint64 From 7740e7045a91823b9cb9cc8635e43c3f7988fd27 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 14 Apr 2023 11:32:17 +0200 Subject: [PATCH 7/9] fix lint --- server/mock/store.go | 3 +++ x/group/module/abci_test.go | 1 - x/mint/testutil/expected_keepers_mocks.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/mock/store.go b/server/mock/store.go index 31b73f3fd86f..218ce50d398d 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -167,6 +167,9 @@ func (ms multiStore) RollbackToVersion(version int64) error { func (ms multiStore) LatestVersion() int64 { panic("not implemented") } +func (ms multiStore) WorkingHash() []byte { + panic("not implemented") +} var _ storetypes.KVStore = kvStore{} diff --git a/x/group/module/abci_test.go b/x/group/module/abci_test.go index 2b9fa6f78a5e..c669fb3b4654 100644 --- a/x/group/module/abci_test.go +++ b/x/group/module/abci_test.go @@ -6,7 +6,6 @@ import ( "time" "cosmossdk.io/core/address" - sdkmath "cosmossdk.io/math" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttime "github.com/cometbft/cometbft/types/time" diff --git a/x/mint/testutil/expected_keepers_mocks.go b/x/mint/testutil/expected_keepers_mocks.go index 9fb2e88af02e..6504d5122930 100644 --- a/x/mint/testutil/expected_keepers_mocks.go +++ b/x/mint/testutil/expected_keepers_mocks.go @@ -37,10 +37,10 @@ func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder { } // BondedRatio mocks base method. -func (m *MockStakingKeeper) BondedRatio(ctx types.Context) types.Dec { +func (m *MockStakingKeeper) BondedRatio(ctx types.Context) math.LegacyDec { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "BondedRatio", ctx) - ret0, _ := ret[0].(types.Dec) + ret0, _ := ret[0].(math.LegacyDec) return ret0 } From 2297cee586e89f1b27c9ce226300101dabb095f4 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Fri, 14 Apr 2023 12:10:58 +0200 Subject: [PATCH 8/9] further cleanup --- server/mock/store.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/mock/store.go b/server/mock/store.go index 218ce50d398d..2094e2905d0a 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -167,6 +167,7 @@ func (ms multiStore) RollbackToVersion(version int64) error { func (ms multiStore) LatestVersion() int64 { panic("not implemented") } + func (ms multiStore) WorkingHash() []byte { panic("not implemented") } From f1d83b964c1fde85d71cf1a08f04103744ea3c14 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Apr 2023 18:03:40 +0200 Subject: [PATCH 9/9] fix e2e --- tests/e2e/group/query.go | 2 +- tests/e2e/group/tx.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/group/query.go b/tests/e2e/group/query.go index 27c7b609e692..c4cbc4fbded9 100644 --- a/tests/e2e/group/query.go +++ b/tests/e2e/group/query.go @@ -393,7 +393,7 @@ func (s *E2ETestSuite) TestQueryGroupPolicyInfo() { "group policy not found", []string{val.Address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)}, true, - "group policy: not found", + "not found", 0, }, { diff --git a/tests/e2e/group/tx.go b/tests/e2e/group/tx.go index b0773eab2483..be371cb9ab93 100644 --- a/tests/e2e/group/tx.go +++ b/tests/e2e/group/tx.go @@ -1609,7 +1609,7 @@ func (s *E2ETestSuite) TestTxSubmitProposal() { s.commonFlags..., ), false, - "group policy: not found", + "not found", &sdk.TxResponse{}, sdkerrors.ErrNotFound.ABCICode(), },