Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Aug 1, 2023
1 parent 9a9e22f commit a7c6349
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
4 changes: 2 additions & 2 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ func (s *StorageTestSuite) TestLeaveGroup() {
s.Require().Equal(headGroupNftResponse.MetaData.GroupName, groupName)

// 3. ListGroup
queryListGroupReq := storagetypes.QueryListGroupRequest{GroupOwner: owner.GetAddr().String()}
queryListGroupResp, err := s.Client.ListGroup(ctx, &queryListGroupReq)
queryListGroupReq := storagetypes.QueryListGroupsRequest{GroupOwner: owner.GetAddr().String()}
queryListGroupResp, err := s.Client.ListGroups(ctx, &queryListGroupReq)
s.Require().NoError(err)
s.Require().GreaterOrEqual(len(queryListGroupResp.GroupInfos), 1)

Expand Down
42 changes: 40 additions & 2 deletions x/challenge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -23,6 +24,7 @@ func GetQueryCmd() *cobra.Command {

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdLatestAttestedChallenges())
cmd.AddCommand(CmdAttestedChallenge())
cmd.AddCommand(CmdInturnChallenger())

// this line is used by starport scaffolding # 1
Expand Down Expand Up @@ -54,6 +56,42 @@ func CmdQueryParams() *cobra.Command {
return cmd
}

func CmdAttestedChallenge() *cobra.Command {
cmd := &cobra.Command{
Use: "attested-challenge",
Short: "Query result for an attested challenge",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argChallengeId, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("challenge-id %s not a valid uint, please input a valid challenge-id", args[0])
}

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

req := &types.QueryAttestedChallengeRequest{
ChallengeId: argChallengeId,
}

res, err := queryClient.AttestedChallenge(cmd.Context(), req)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdLatestAttestedChallenges() *cobra.Command {
cmd := &cobra.Command{
Use: "latest-attested-challenges",
Expand All @@ -68,9 +106,9 @@ func CmdLatestAttestedChallenges() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryLatestAttestedChallengesRequest{}
req := &types.QueryLatestAttestedChallengesRequest{}

res, err := queryClient.LatestAttestedChallenges(cmd.Context(), params)
res, err := queryClient.LatestAttestedChallenges(cmd.Context(), req)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions x/payment/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *CLITestSuite) TestQueryCmd() {
},
commonFlags...,
),
false, "", &types.QueryGetPaymentAccountsByOwnerResponse{},
false, "", &types.QueryPaymentAccountsByOwnerResponse{},
},
{
"query list-auto-settle-record",
Expand All @@ -64,7 +64,7 @@ func (s *CLITestSuite) TestQueryCmd() {
},
commonFlags...,
),
false, "", &types.QueryAllAutoSettleRecordResponse{},
false, "", &types.QueryAutoSettleRecordsResponse{},
},
{
"query list-payment-account",
Expand All @@ -74,7 +74,7 @@ func (s *CLITestSuite) TestQueryCmd() {
},
commonFlags...,
),
false, "", &types.QueryAllPaymentAccountResponse{},
false, "", &types.QueryPaymentAccountsResponse{},
},
{
"query list-payment-account-count",
Expand All @@ -84,7 +84,7 @@ func (s *CLITestSuite) TestQueryCmd() {
},
commonFlags...,
),
false, "", &types.QueryAllPaymentAccountCountResponse{},
false, "", &types.QueryPaymentAccountCountsResponse{},
},
{
"query list-stream-record",
Expand All @@ -94,7 +94,7 @@ func (s *CLITestSuite) TestQueryCmd() {
},
commonFlags...,
),
false, "", &types.QueryAllStreamRecordResponse{},
false, "", &types.QueryStreamRecordsResponse{},
},
{
"query show-payment-account",
Expand All @@ -116,7 +116,7 @@ func (s *CLITestSuite) TestQueryCmd() {
},
commonFlags...,
),
false, "", &types.QueryGetPaymentAccountCountResponse{},
false, "", &types.QueryPaymentAccountCountResponse{},
},
{
"query show-stream-record",
Expand Down
8 changes: 4 additions & 4 deletions x/storage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetQueryCmd() *cobra.Command {
CmdListObjects(),
CmdVerifyPermission(),
CmdHeadGroup(),
CmdListGroup(),
CmdListGroups(),
CmdHeadGroupMember())

// this line is used by starport scaffolding # 1
Expand Down Expand Up @@ -249,10 +249,10 @@ func CmdHeadGroup() *cobra.Command {
return cmd
}

func CmdListGroup() *cobra.Command {
func CmdListGroups() *cobra.Command {
cmd := &cobra.Command{
Use: "list-group [group-owner]",
Short: "Query list group of owner",
Use: "list-groups [group-owner]",
Short: "Query list groups of owner",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqGroupOwner := args[0]
Expand Down
6 changes: 3 additions & 3 deletions x/storage/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ func (s *CLITestSuite) TestQueryCmd() {
false, "", &types.QueryListBucketsResponse{},
},
{
"query list-group",
"query list-groups",
append(
[]string{
"list-group",
"list-groups",
sample.RandAccAddressHex(),
},
commonFlags...,
),
false, "", &types.QueryListGroupResponse{},
false, "", &types.QueryListGroupsResponse{},
},
{
"query list-objects",
Expand Down
8 changes: 4 additions & 4 deletions x/storage/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,17 @@ func TestHeadGroup(t *testing.T) {
func TestListGroup(t *testing.T) {
// invalid argument
k, ctx := makeKeeper(t)
_, err := k.ListGroup(ctx, nil)
_, err := k.ListGroups(ctx, nil)
require.ErrorContains(t, err, "invalid request")

_, err = k.ListGroup(ctx, &types.QueryListGroupRequest{
_, err = k.ListGroups(ctx, &types.QueryListGroupsRequest{
Pagination: &query.PageRequest{
Limit: types.MaxPaginationLimit + 1,
},
})
require.ErrorContains(t, err, "exceed pagination limit")

_, err = k.ListGroup(ctx, &types.QueryListGroupRequest{
_, err = k.ListGroups(ctx, &types.QueryListGroupsRequest{
GroupOwner: "xxx",
})
require.ErrorContains(t, err, "invalid address hex length")
Expand All @@ -356,7 +356,7 @@ func TestListGroup(t *testing.T) {
func TestHeadGroupMember(t *testing.T) {
// invalid argument
k, ctx := makeKeeper(t)
_, err := k.ListGroup(ctx, nil)
_, err := k.ListGroups(ctx, nil)
require.ErrorContains(t, err, "invalid request")

_, err = k.HeadGroupMember(ctx, &types.QueryHeadGroupMemberRequest{
Expand Down

0 comments on commit a7c6349

Please sign in to comment.