Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Supplier] Scaffold the Proof type and adjust some of the defaults #197

Merged
merged 20 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ignite scaffold map proof --module supplier supplier_address session_…
…id root_hash --no-message --yes
Olshansk committed Nov 17, 2023
commit 1745b6af2696d9da73016c43805873080f78c0dc
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"io"
"os"
"path/filepath"

// this line is used by starport scaffolding # stargate/app/moduleImport

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1591,6 +1591,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pokt-network/poktroll v0.0.0-20231116164404-dd3434115ee1 h1:Y0eeoa4cDqykM3dPmXW4D6nMKNlalV5YjGqzCbAglqE=
github.com/pokt-network/poktroll v0.0.0-20231116164404-dd3434115ee1/go.mod h1:YLe1YzoVPuhPXiyIzUzhKpwf/70mjUZxdbKpFpX6js8=
github.com/pokt-network/smt v0.7.1 h1:WHcZeMLe+9U1/kCAhdbssdyTYzYxxb74sf8MCvG34M8=
github.com/pokt-network/smt v0.7.1/go.mod h1:K7BLEOWoZGZmY5USQuYvTkZ3qXjE6m39BMufBvVo3U8=
github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4=
5 changes: 4 additions & 1 deletion proto/pocket/supplier/genesis.proto
Original file line number Diff line number Diff line change
@@ -6,14 +6,17 @@ import "gogoproto/gogo.proto";
import "pocket/supplier/params.proto";
import "pocket/shared/supplier.proto";
import "pocket/supplier/claim.proto";
import "pocket/supplier/proof.proto";

option go_package = "github.com/pokt-network/poktroll/x/supplier/types";

// GenesisState defines the supplier module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated pocket.shared.Supplier supplierList = 2 [(gogoproto.nullable) = false];

// TODO_UPNEXT(@Olshansk): Delete `claimList` from the genesis state.
repeated Claim claimList = 3 [(gogoproto.nullable) = false];
repeated Claim claimList = 3 [(gogoproto.nullable) = false];
repeated Proof proofList = 4 [(gogoproto.nullable) = false];
}

13 changes: 13 additions & 0 deletions proto/pocket/supplier/proof.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package pocket.supplier;

option go_package = "pocket/x/supplier/types";

message Proof {
string index = 1;
string supplierAddress = 2;
string sessionId = 3;
string rootHash = 4;

}

47 changes: 41 additions & 6 deletions proto/pocket/supplier/query.proto
Original file line number Diff line number Diff line change
@@ -8,38 +8,55 @@ import "cosmos/base/query/v1beta1/pagination.proto";
import "pocket/supplier/params.proto";
import "pocket/shared/supplier.proto";
import "pocket/supplier/claim.proto";
import "pocket/supplier/proof.proto";

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) {
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) {
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";

}

// 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) {
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];
}
@@ -76,4 +93,22 @@ message QueryAllClaimsRequest {
message QueryAllClaimsResponse {
repeated Claim claim = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
}

message QueryGetProofRequest {
string index = 1;
}

message QueryGetProofResponse {
Proof proof = 1 [(gogoproto.nullable) = false];
}

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

message QueryAllProofResponse {
repeated Proof proof = 1 [(gogoproto.nullable) = false];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

7 changes: 7 additions & 0 deletions proto/poktroll/supplier/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package poktroll.supplier;

option go_package = "github.com/pokt-network/poktroll/x/supplier/types";

// Msg defines the Msg service.
service Msg {}
4 changes: 3 additions & 1 deletion x/supplier/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -29,7 +29,9 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdShowSupplier())
cmd.AddCommand(CmdListClaim())
cmd.AddCommand(CmdShowClaim())
// this line is used by starport scaffolding # 1
cmd.AddCommand(CmdListProof())
cmd.AddCommand(CmdShowProof())
// this line is used by starport scaffolding # 1

return cmd
}
80 changes: 80 additions & 0 deletions x/supplier/client/cli/query_proof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cli

import (
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"


"pocket/x/supplier/types"
)

func CmdListProof() *cobra.Command {
cmd := &cobra.Command{
Use: "list-proof",
Short: "list all proof",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

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

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

return clientCtx.PrintProto(res)
},
}

flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdShowProof() *cobra.Command {
cmd := &cobra.Command{
Use: "show-proof [index]",
Short: "shows a proof",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

argIndex := args[0]

params := &types.QueryGetProofRequest{
Index: argIndex,

}

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

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
162 changes: 162 additions & 0 deletions x/supplier/client/cli/query_proof_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package cli_test

import (
"fmt"
"strconv"
"testing"

"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/stretchr/testify/require"
tmcli "github.com/cometbft/cometbft/libs/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"pocket/testutil/network"
"pocket/testutil/nullify"
"pocket/x/supplier/client/cli"
"pocket/x/supplier/types"
)

// Prevent strconv unused error
var _ = strconv.IntSize

func networkWithProofObjects(t *testing.T, n int) (*network.Network, []types.Proof) {
t.Helper()
cfg := network.DefaultConfig()
state := types.GenesisState{}
for i := 0; i < n; i++ {
proof := types.Proof{
Index: strconv.Itoa(i),

}
nullify.Fill(&proof)
state.ProofList = append(state.ProofList, proof)
}
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
return network.New(t, cfg), state.ProofList
}

func TestShowProof(t *testing.T) {
net, objs := networkWithProofObjects(t, 2)

ctx := net.Validators[0].ClientCtx
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
tests := []struct {
desc string
idIndex string

args []string
err error
obj types.Proof
}{
{
desc: "found",
idIndex: objs[0].Index,

args: common,
obj: objs[0],
},
{
desc: "not found",
idIndex: strconv.Itoa(100000),

args: common,
err: status.Error(codes.NotFound, "not found"),
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
args := []string{
tc.idIndex,

}
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowProof(), args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
} else {
require.NoError(t, err)
var resp types.QueryGetProofResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.Proof)
require.Equal(t,
nullify.Fill(&tc.obj),
nullify.Fill(&resp.Proof),
)
}
})
}
}

func TestListProof(t *testing.T) {
net, objs := networkWithProofObjects(t, 5)

ctx := net.Validators[0].ClientCtx
request := func(next []byte, offset, limit uint64, total bool) []string {
args := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
if next == nil {
args = append(args, fmt.Sprintf("--%s=%d", flags.FlagOffset, offset))
} else {
args = append(args, fmt.Sprintf("--%s=%s", flags.FlagPageKey, next))
}
args = append(args, fmt.Sprintf("--%s=%d", flags.FlagLimit, limit))
if total {
args = append(args, fmt.Sprintf("--%s", flags.FlagCountTotal))
}
return args
}
t.Run("ByOffset", func(t *testing.T) {
step := 2
for i := 0; i < len(objs); i += step {
args := request(nil, uint64(i), uint64(step), false)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args)
require.NoError(t, err)
var resp types.QueryAllProofResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.LessOrEqual(t, len(resp.Proof), step)
require.Subset(t,
nullify.Fill(objs),
nullify.Fill(resp.Proof),
)
}
})
t.Run("ByKey", func(t *testing.T) {
step := 2
var next []byte
for i := 0; i < len(objs); i += step {
args := request(next, 0, uint64(step), false)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args)
require.NoError(t, err)
var resp types.QueryAllProofResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.LessOrEqual(t, len(resp.Proof), step)
require.Subset(t,
nullify.Fill(objs),
nullify.Fill(resp.Proof),
)
next = resp.Pagination.NextKey
}
})
t.Run("Total", func(t *testing.T) {
args := request(nil, 0, uint64(len(objs)), true)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListProof(), args)
require.NoError(t, err)
var resp types.QueryAllProofResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NoError(t, err)
require.Equal(t, len(objs), int(resp.Pagination.Total))
require.ElementsMatch(t,
nullify.Fill(objs),
nullify.Fill(resp.Proof),
)
})
}
Loading