Skip to content

Commit

Permalink
Move group related functions to group.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Taztingo committed Jan 25, 2024
1 parent cd0127e commit e458581
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/group.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package app

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
)

// GroupCheckerFunc convenient type to match the GroupChecker interface.
type GroupCheckerFunc func(sdk.Context, sdk.AccAddress) bool

// GroupPolicyQuerier provides functionality to query group policies.
type GroupPolicyQuerier interface {
GroupPolicyInfo(goCtx context.Context, request *group.QueryGroupPolicyInfoRequest) (*group.QueryGroupPolicyInfoResponse, error)
}

// IsGroupAddress checks if the account is a group address.
func (t GroupCheckerFunc) IsGroupAddress(ctx sdk.Context, account sdk.AccAddress) bool {
return t(ctx, account)

Check warning on line 20 in app/group.go

View check run for this annotation

Codecov / codecov/patch

app/group.go#L19-L20

Added lines #L19 - L20 were not covered by tests
}

// NewGroupChecker creates a new GroupChecker function for checking if an account is in a group.
func NewGroupCheckerFunc(keeper groupkeeper.Keeper) GroupCheckerFunc {
func NewGroupCheckerFunc(querier GroupPolicyQuerier) GroupCheckerFunc {
return GroupCheckerFunc(func(ctx sdk.Context, account sdk.AccAddress) bool {
msg := &group.QueryGroupPolicyInfoRequest{Address: account.String()}
goCtx := sdk.WrapSDKContext(ctx)
_, err := keeper.GroupPolicyInfo(goCtx, msg)
_, err := querier.GroupPolicyInfo(goCtx, msg)
return err == nil
})

Check warning on line 30 in app/group.go

View check run for this annotation

Codecov / codecov/patch

app/group.go#L26-L30

Added lines #L26 - L30 were not covered by tests
}
14 changes: 14 additions & 0 deletions app/group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app

import "testing"

type MockGroupPolicyQuerier struct {
}

func TestNewGroupCheckerFunc(t *testing.T) {

}

func TestIsGroupAddress(t *testing.T) {

}

0 comments on commit e458581

Please sign in to comment.