-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for nil address and add tests for TestIsGroupAddress.
- Loading branch information
Showing
2 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,72 @@ | ||
package app | ||
|
||
import "testing" | ||
import ( | ||
"context" | ||
"testing" | ||
|
||
type MockGroupPolicyQuerier struct { | ||
} | ||
"github.com/stretchr/testify/assert" | ||
|
||
cerrs "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/group" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
) | ||
|
||
func TestNewGroupCheckerFunc(t *testing.T) { | ||
|
||
} | ||
|
||
func TestIsGroupAddress(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
querySuccess bool | ||
address sdk.AccAddress | ||
}{ | ||
{ | ||
name: "should be true with group address", | ||
querySuccess: true, | ||
address: sdk.AccAddress("test"), | ||
}, | ||
{ | ||
name: "should return false with non group address", | ||
querySuccess: false, | ||
address: sdk.AccAddress("test"), | ||
}, | ||
{ | ||
name: "should return false with nil address", | ||
querySuccess: false, | ||
address: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
querier := NewMockGroupPolicyQuerier(tc.querySuccess) | ||
checker := NewGroupCheckerFunc(querier) | ||
ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) | ||
success := checker.IsGroupAddress(ctx, tc.address) | ||
assert.Equal(t, tc.querySuccess, success, "should correctly detect if the supplied address is a group address") | ||
}) | ||
} | ||
} | ||
|
||
// MockGroupPolicyQuerier mocks the querier so a GroupKeeper isn't needed. | ||
type MockGroupPolicyQuerier struct { | ||
isGroupAddress bool | ||
} | ||
|
||
// NewMockGroupPolicyQuerier creates a new MockGroupPolicyQuerier. | ||
func NewMockGroupPolicyQuerier(isGroupAddress bool) *MockGroupPolicyQuerier { | ||
return &MockGroupPolicyQuerier{ | ||
isGroupAddress: isGroupAddress, | ||
} | ||
} | ||
|
||
// GroupPolicyInfo provides a stubbed implementation of the GroupPolicyInfo method. | ||
func (t MockGroupPolicyQuerier) GroupPolicyInfo(goCtx context.Context, request *group.QueryGroupPolicyInfoRequest) (*group.QueryGroupPolicyInfoResponse, error) { | ||
var err error | ||
if !t.isGroupAddress { | ||
err = cerrs.New("", 1, "") | ||
} | ||
return nil, err | ||
} |