Skip to content

Commit

Permalink
Fix grammer for AllProof querying
Browse files Browse the repository at this point in the history
  • Loading branch information
Olshansk committed Nov 17, 2023
1 parent a0e9e8d commit 9a9ca7a
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 66 deletions.
10 changes: 7 additions & 3 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47648,7 +47648,7 @@ paths:
- Query
/pocket/supplier/proof:
get:
operationId: PocketSupplierProofAll
operationId: PocketSupplierAllProofs
responses:
'200':
description: A successful response.
Expand Down Expand Up @@ -47780,7 +47780,11 @@ paths:
- Query
/pocket/supplier/proof/{index}:
get:
summary: Queries a list of Proof items.
summary: >-
TODO_UPNEXT(@Olshansk): Update these endpoints after implementing proof
persistence

Queries a list of Proof items.
operationId: PocketSupplierProof
responses:
'200':
Expand Down Expand Up @@ -78289,7 +78293,7 @@ definitions:
repeated Bar results = 1;
PageResponse page = 2;
}
pocket.supplier.QueryAllProofResponse:
pocket.supplier.QueryAllProofsResponse:
type: object
properties:
proof:
Expand Down
31 changes: 16 additions & 15 deletions proto/pocket/supplier/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,50 @@ option go_package = "github.com/pokt-network/poktroll/x/supplier/types";

// Query defines the gRPC querier service.
service Query {

// Parameters queries the parameters of the module.
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/pocket/supplier/params";

}

// Queries a list of Supplier items.
rpc Supplier (QueryGetSupplierRequest) returns (QueryGetSupplierResponse) {
option (google.api.http).get = "/pocket/supplier/supplier/{address}";

}
rpc SupplierAll (QueryAllSupplierRequest) returns (QueryAllSupplierResponse) {
option (google.api.http).get = "/pocket/supplier/supplier";

}

// Queries a list of Claim items.
rpc Claim (QueryGetClaimRequest ) returns (QueryGetClaimResponse ) {
option (google.api.http).get = "/pocket/supplier/claim/{index}";

}
rpc AllClaims (QueryAllClaimsRequest) returns (QueryAllClaimsResponse) {
option (google.api.http).get = "/pocket/supplier/claim";

}


// TODO_UPNEXT(@Olshansk): Update these endpoints after implementing proof persistence
// Queries a list of Proof items.
rpc Proof (QueryGetProofRequest) returns (QueryGetProofResponse) {
option (google.api.http).get = "/pocket/supplier/proof/{index}";

}
rpc ProofAll (QueryAllProofRequest) returns (QueryAllProofResponse) {
rpc AllProofs (QueryAllProofsRequest) returns (QueryAllProofsResponse) {
option (google.api.http).get = "/pocket/supplier/proof";

}
}
// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {

// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}
Expand Down Expand Up @@ -103,11 +104,11 @@ message QueryGetProofResponse {
Proof proof = 1 [(gogoproto.nullable) = false];
}

message QueryAllProofRequest {
message QueryAllProofsRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllProofResponse {
message QueryAllProofsResponse {
repeated Proof proof = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
Expand Down
3 changes: 1 addition & 2 deletions testutil/keeper/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

"github.com/pokt-network/poktroll/testutil/sample"
"github.com/pokt-network/poktroll/testutil/session/mocks"
apptypes "github.com/pokt-network/poktroll/x/application/types"
"github.com/pokt-network/poktroll/x/session/keeper"
"github.com/pokt-network/poktroll/x/session/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
"github.com/stretchr/testify/require"
)

type option[V any] func(k *keeper.Keeper)
Expand Down
3 changes: 2 additions & 1 deletion x/pocket/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package types

import (
// this line is used by starport scaffolding # 1

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
// this line is used by starport scaffolding # 1
)

func RegisterCodec(cdc *codec.LegacyAmino) {
Expand Down
3 changes: 2 additions & 1 deletion x/service/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package types

import (
// this line is used by starport scaffolding # 1

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
// this line is used by starport scaffolding # 1
)

func RegisterCodec(cdc *codec.LegacyAmino) {
Expand Down
3 changes: 2 additions & 1 deletion x/session/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package types

import (
// this line is used by starport scaffolding # 1

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
// this line is used by starport scaffolding # 1
)

func RegisterCodec(cdc *codec.LegacyAmino) {
Expand Down
11 changes: 5 additions & 6 deletions x/supplier/client/cli/query_proof.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package cli

import (
"github.com/pokt-network/poktroll/x/supplier/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/pokt-network/poktroll/x/supplier/types"
"github.com/spf13/cobra"
)

func CmdListProof() *cobra.Command {
cmd := &cobra.Command{
Use: "list-proof",
Short: "list all proof",
Use: "list-proofs",
Short: "list all proofs",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand All @@ -25,11 +24,11 @@ func CmdListProof() *cobra.Command {

queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryAllProofRequest{
params := &types.QueryAllProofsRequest{
Pagination: pageReq,
}

res, err := queryClient.ProofAll(cmd.Context(), params)
res, err := queryClient.AllProofs(cmd.Context(), params)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions x/supplier/client/cli/query_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ package cli_test
// args := request(nil, uint64(i), uint64(step), false)
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args)
// require.NoError(t, err)
// var resp types.QueryAllProofResponse
// var resp types.QueryAllProofsResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.LessOrEqual(t, len(resp.Proof), step)
// require.Subset(t,
Expand All @@ -119,7 +119,7 @@ package cli_test
// args := request(next, 0, uint64(step), false)
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args)
// require.NoError(t, err)
// var resp types.QueryAllProofResponse
// var resp types.QueryAllProofsResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.LessOrEqual(t, len(resp.Proof), step)
// require.Subset(t,
Expand All @@ -133,7 +133,7 @@ package cli_test
// args := request(nil, 0, uint64(len(objs)), true)
// out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args)
// require.NoError(t, err)
// var resp types.QueryAllProofResponse
// var resp types.QueryAllProofsResponse
// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
// require.NoError(t, err)
// require.Equal(t, len(objs), int(resp.Pagination.Total))
Expand Down
6 changes: 3 additions & 3 deletions x/supplier/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
keepertest "github.com/pokt-network/poktroll/testutil/keeper"
"github.com/pokt-network/poktroll/x/supplier/keeper"
"github.com/pokt-network/poktroll/x/supplier/types"
"github.com/stretchr/testify/require"
"github.com/pokt-network/poktroll/x/supplier/types"
"github.com/pokt-network/poktroll/x/supplier/keeper"
keepertest "github.com/pokt-network/poktroll/testutil/keeper"
)

func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
Expand Down
5 changes: 2 additions & 3 deletions x/supplier/keeper/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"strconv"
"testing"

keepertest "pocket/testutil/keeper"
"pocket/testutil/nullify"

sdk "github.com/cosmos/cosmos-sdk/types"
keepertest "github.com/pokt-network/poktroll/testutil/keeper"
"github.com/pokt-network/poktroll/testutil/nullify"
"github.com/pokt-network/poktroll/x/supplier/keeper"
"github.com/pokt-network/poktroll/x/supplier/types"
"github.com/stretchr/testify/require"
Expand Down
4 changes: 2 additions & 2 deletions x/supplier/keeper/query_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"google.golang.org/grpc/status"
)

func (k Keeper) ProofAll(goCtx context.Context, req *types.QueryAllProofRequest) (*types.QueryAllProofResponse, error) {
func (k Keeper) AllProofs(goCtx context.Context, req *types.QueryAllProofsRequest) (*types.QueryAllProofsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
Expand All @@ -36,7 +36,7 @@ func (k Keeper) ProofAll(goCtx context.Context, req *types.QueryAllProofRequest)
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryAllProofResponse{Proof: proofs, Pagination: pageRes}, nil
return &types.QueryAllProofsResponse{Proof: proofs, Pagination: pageRes}, nil
}

func (k Keeper) Proof(goCtx context.Context, req *types.QueryGetProofRequest) (*types.QueryGetProofResponse, error) {
Expand Down
20 changes: 9 additions & 11 deletions x/supplier/keeper/query_proof_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package keeper_test

import (
keepertest "pocket/testutil/keeper"
"pocket/testutil/nullify"
"strconv"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/pokt-network/poktroll/x/supplier/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

keepertest "pocket/testutil/keeper"
"pocket/testutil/nullify"

"github.com/pokt-network/poktroll/x/supplier/types"
)

// Prevent strconv unused error
Expand Down Expand Up @@ -76,8 +74,8 @@ func TestProofQueryPaginated(t *testing.T) {
wctx := sdk.WrapSDKContext(ctx)
msgs := createNProof(keeper, ctx, 5)

request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllProofRequest {
return &types.QueryAllProofRequest{
request := func(next []byte, offset, limit uint64, total bool) *types.QueryAllProofsRequest {
return &types.QueryAllProofsRequest{
Pagination: &query.PageRequest{
Key: next,
Offset: offset,
Expand All @@ -89,7 +87,7 @@ func TestProofQueryPaginated(t *testing.T) {
t.Run("ByOffset", func(t *testing.T) {
step := 2
for i := 0; i < len(msgs); i += step {
resp, err := keeper.ProofAll(wctx, request(nil, uint64(i), uint64(step), false))
resp, err := keeper.AllProofs(wctx, request(nil, uint64(i), uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.Proof), step)
require.Subset(t,
Expand All @@ -102,7 +100,7 @@ func TestProofQueryPaginated(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(msgs); i += step {
resp, err := keeper.ProofAll(wctx, request(next, 0, uint64(step), false))
resp, err := keeper.AllProofs(wctx, request(next, 0, uint64(step), false))
require.NoError(t, err)
require.LessOrEqual(t, len(resp.Proof), step)
require.Subset(t,
Expand All @@ -113,7 +111,7 @@ func TestProofQueryPaginated(t *testing.T) {
}
})
t.Run("Total", func(t *testing.T) {
resp, err := keeper.ProofAll(wctx, request(nil, 0, 0, true))
resp, err := keeper.AllProofs(wctx, request(nil, 0, 0, true))
require.NoError(t, err)
require.Equal(t, len(msgs), int(resp.Pagination.Total))
require.ElementsMatch(t,
Expand All @@ -122,7 +120,7 @@ func TestProofQueryPaginated(t *testing.T) {
)
})
t.Run("InvalidRequest", func(t *testing.T) {
_, err := keeper.ProofAll(wctx, nil)
_, err := keeper.AllProofs(wctx, nil)
require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request"))
})
}
3 changes: 1 addition & 2 deletions x/supplier/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package types

import (
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -29,7 +28,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
)
// this line is used by starport scaffolding # 3

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)

Expand Down
5 changes: 0 additions & 5 deletions x/supplier/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,6 @@ func TestGenesisState_Validate(t *testing.T) {
},
valid: false,
},
{
desc: "duplicated proof",
genState: &types.GenesisState{},
valid: false,
},
// this line is used by starport scaffolding # types/genesis/testcase
}
for _, tc := range tests {
Expand Down
16 changes: 8 additions & 8 deletions x/supplier/types/key_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import "encoding/binary"
var _ binary.ByteOrder

const (
// ProofKeyPrefix is the prefix to retrieve all Proof
// ProofKeyPrefix is the prefix to retrieve all Proof
ProofKeyPrefix = "Proof/value/"
)

// ProofKey returns the store key to retrieve a Proof from the index fields
func ProofKey(
index string,
index string,
) []byte {
var key []byte
indexBytes := []byte(index)
key = append(key, indexBytes...)
key = append(key, []byte("/")...)

indexBytes := []byte(index)
key = append(key, indexBytes...)
key = append(key, []byte("/")...)

return key
}
}

0 comments on commit 9a9ca7a

Please sign in to comment.