## Description ref: #10490 [comment](https://github.com/cosmos/cosmos-sdk/issues/10490#issuecomment-1047110188) --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/group"
|
|
"github.com/stretchr/testify/require"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
)
|
|
|
|
func TestQueryGroupsByMember(t *testing.T) {
|
|
app := simapp.Setup(t, false)
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
|
group.RegisterQueryServer(queryHelper, app.GroupKeeper)
|
|
queryClient := group.NewQueryClient(queryHelper)
|
|
sdkCtx := sdk.WrapSDKContext(ctx)
|
|
|
|
addrs := simapp.AddTestAddrsIncremental(app, ctx, 6, sdk.NewInt(30000000))
|
|
|
|
// Initial group, group policy and balance setup
|
|
members := []group.Member{
|
|
{Address: addrs[2].String(), Weight: "1"}, {Address: addrs[3].String(), Weight: "2"},
|
|
}
|
|
_, err := app.GroupKeeper.CreateGroup(sdkCtx, &group.MsgCreateGroup{
|
|
Admin: addrs[0].String(),
|
|
Members: members,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
members = []group.Member{
|
|
{Address: addrs[3].String(), Weight: "1"}, {Address: addrs[4].String(), Weight: "2"},
|
|
}
|
|
_, err = app.GroupKeeper.CreateGroup(sdkCtx, &group.MsgCreateGroup{
|
|
Admin: addrs[1].String(),
|
|
Members: members,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
// not part of any group
|
|
resp, err := queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
|
Address: addrs[5].String(),
|
|
})
|
|
require.NoError(t, err)
|
|
require.Len(t, resp.Groups, 0)
|
|
|
|
// expect one group
|
|
resp, err = queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
|
Address: addrs[4].String(),
|
|
})
|
|
require.NoError(t, err)
|
|
require.Len(t, resp.Groups, 1)
|
|
|
|
// expect two groups
|
|
resp, err = queryClient.GroupsByMember(context.Background(), &group.QueryGroupsByMemberRequest{
|
|
Address: addrs[3].String(),
|
|
})
|
|
require.NoError(t, err)
|
|
require.Len(t, resp.Groups, 2)
|
|
}
|