Skip to content

Commit

Permalink
chore: supplier module review improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Feb 21, 2024
1 parent 9faa010 commit 65e2ac8
Show file tree
Hide file tree
Showing 51 changed files with 561 additions and 503 deletions.
59 changes: 28 additions & 31 deletions api/poktroll/shared/supplier.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/poktroll/supplier/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion proto/poktroll/shared/supplier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ syntax = "proto3";
package poktroll.shared;

option go_package = "github.com/pokt-network/poktroll/x/shared/types";
import "gogoproto/gogo.proto";

import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

import "poktroll/shared/service.proto";

// Supplier is the type defining the actor in Pocket Network that provides RPC services.
Expand Down
6 changes: 3 additions & 3 deletions proto/poktroll/supplier/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
syntax = "proto3";

package poktroll.supplier;

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

import "amino/amino.proto";
import "gogoproto/gogo.proto";

import "poktroll/supplier/params.proto";
import "poktroll/shared/supplier.proto";

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

// GenesisState defines the supplier module's genesis state.
message GenesisState {

Expand Down
6 changes: 2 additions & 4 deletions proto/poktroll/supplier/params.proto
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
syntax = "proto3";
package poktroll.supplier;

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

import "amino/amino.proto";
import "gogoproto/gogo.proto";

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

// Params defines the parameters for the module.
message Params {
option (amino.name) = "poktroll/x/supplier/Params";
option (gogoproto.equal) = true;


}
6 changes: 3 additions & 3 deletions proto/poktroll/supplier/query.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
syntax = "proto3";

package poktroll.supplier;

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

import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";

import "poktroll/supplier/params.proto";
import "poktroll/shared/supplier.proto";

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

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

Expand Down
26 changes: 15 additions & 11 deletions proto/poktroll/supplier/tx.proto
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
syntax = "proto3";

package poktroll.supplier;

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

import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

import "poktroll/supplier/params.proto";
import "poktroll/shared/service.proto";

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

// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;

// UpdateParams defines a (governance) operation for updating the module
// parameters. The authority defaults to the x/gov module account.
rpc UpdateParams (MsgUpdateParams ) returns (MsgUpdateParamsResponse );
Expand All @@ -24,14 +25,17 @@ service Msg {
}
// MsgUpdateParams is the Msg/UpdateParams request type.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/supplier/MsgUpdateParams";
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "poktroll/x/supplier/MsgUpdateParams";

// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the module parameters to update.

// TODO_IMPROVE(#322): The requirement to provide all params is adopted from the
// latest Cosmos SDK version. We should look into either improving this ourselves
// or seeing if it is on their roadmap.

// params defines the x/supplier parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
Expand All @@ -42,16 +46,16 @@ message MsgUpdateParamsResponse {}

message MsgStakeSupplier {
option (cosmos.msg.v1.signer) = "address"; // https://docs.cosmos.network/main/build/building-modules/messages-and-queries
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the supplier has staked. Must be ≥ to the current amount that the supplier has staked (if any)
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
cosmos.base.v1beta1.Coin stake = 2; // The total amount of uPOKT the supplier has staked. Must be ≥ to the current amount that the supplier has staked (if any)
repeated poktroll.shared.SupplierServiceConfig services = 3; // The list of services this supplier is staked to provide service for
}

message MsgStakeSupplierResponse {}

message MsgUnstakeSupplier {
option (cosmos.msg.v1.signer) = "address";
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // The Bech32 address of the supplier using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding using cosmos' ScalarDescriptor to ensure deterministic deterministic encoding
}

message MsgUnstakeSupplierResponse {}
Expand Down
8 changes: 6 additions & 2 deletions testutil/keeper/supplier.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"context"
"testing"

"cosmossdk.io/log"
Expand All @@ -23,7 +24,7 @@ import (
"github.com/pokt-network/poktroll/x/supplier/types"
)

func SupplierKeeper(t testing.TB) (keeper.Keeper, sdk.Context) {
func SupplierKeeper(t testing.TB) (keeper.Keeper, context.Context) {
t.Helper()

storeKey := storetypes.NewKVStoreKey(types.StoreKey)
Expand Down Expand Up @@ -53,7 +54,10 @@ func SupplierKeeper(t testing.TB) (keeper.Keeper, sdk.Context) {
ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())
require.NoError(t, k.SetParams(ctx, types.DefaultParams()))

return k, ctx
}

// TODO_OPTIMIZE: Index suppliers by service so we can easily query k.GetAllSuppliers(ctx, Service)
// func (k Keeper) GetAllSuppliers(ctx, sdkContext, serviceId string) (suppliers []sharedtypes.Supplier) {}
5 changes: 3 additions & 2 deletions x/supplier/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
)

// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// TODO_TECHDEBT(#370): remove if custom query commands are consolidated into AutoCLI.
func (am AppModule) GetQueryCmd() *cobra.Command {
// Group supplier queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Expand All @@ -21,7 +22,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdListSupplier())
cmd.AddCommand(CmdListSuppliers())
cmd.AddCommand(CmdShowSupplier())
cmd.AddCommand(CmdListClaims())
cmd.AddCommand(CmdShowClaim())
Expand Down
2 changes: 1 addition & 1 deletion x/supplier/client/cli/query_supplier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pokt-network/poktroll/x/supplier/types"
)

func CmdListSupplier() *cobra.Command {
func CmdListSuppliers() *cobra.Command {
cmd := &cobra.Command{
Use: "list-supplier",
Short: "list all supplier",
Expand Down
46 changes: 25 additions & 21 deletions x/supplier/client/cli/query_supplier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/pokt-network/poktroll/testutil/nullify"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
"github.com/pokt-network/poktroll/x/supplier/client/cli"
"github.com/pokt-network/poktroll/x/supplier/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pokt-network/poktroll/testutil/nullify"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
supplier "github.com/pokt-network/poktroll/x/supplier/module"
"github.com/pokt-network/poktroll/x/supplier/types"
)

func TestShowSupplier(t *testing.T) {
Expand All @@ -28,51 +32,51 @@ func TestShowSupplier(t *testing.T) {
desc string
idAddress string

args []string
err error
obj sharedtypes.Supplier
args []string
expectedErr error
supplier sharedtypes.Supplier
}{
{
desc: "supplier found",
idAddress: suppliers[0].Address,

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

args: common,
err: status.Error(codes.NotFound, "not found"),
args: common,
expectedErr: status.Error(codes.NotFound, "not found"),
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
args := []string{
tc.idAddress,
test.idAddress,
}
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowSupplier(), args)
if tc.err != nil {
stat, ok := status.FromError(tc.err)
args = append(args, test.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, supplier.CmdShowSupplier(), args)
if test.expectedErr != nil {
stat, ok := status.FromError(test.expectedErr)
require.True(t, ok)
require.ErrorIs(t, stat.Err(), tc.err)
require.ErrorIs(t, stat.Err(), test.expectedErr)
} else {
require.NoError(t, err)
var resp types.QueryGetSupplierResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.Supplier)
require.Equal(t,
nullify.Fill(&tc.obj),
nullify.Fill(&test.supplier),
nullify.Fill(&resp.Supplier),
)
}
})
}
}

func TestListSupplier(t *testing.T) {
func TestListSuppliers(t *testing.T) {
net, suppliers := networkWithSupplierObjects(t, 5)

ctx := net.Validators[0].ClientCtx
Expand All @@ -95,7 +99,7 @@ func TestListSupplier(t *testing.T) {
step := 2
for i := 0; i < len(suppliers); i += step {
args := request(nil, uint64(i), uint64(step), false)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListSupplier(), args)
out, err := clitestutil.ExecTestCLICmd(ctx, supplier.CmdListSuppliers(), args)
require.NoError(t, err)
var resp types.QueryAllSupplierResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
Expand All @@ -111,7 +115,7 @@ func TestListSupplier(t *testing.T) {
var next []byte
for i := 0; i < len(suppliers); i += step {
args := request(next, 0, uint64(step), false)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListSupplier(), args)
out, err := clitestutil.ExecTestCLICmd(ctx, supplier.CmdListSuppliers(), args)
require.NoError(t, err)
var resp types.QueryAllSupplierResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
Expand All @@ -125,7 +129,7 @@ func TestListSupplier(t *testing.T) {
})
t.Run("Total", func(t *testing.T) {
args := request(nil, 0, uint64(len(suppliers)), true)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListSupplier(), args)
out, err := clitestutil.ExecTestCLICmd(ctx, supplier.CmdListSuppliers(), args)
require.NoError(t, err)
var resp types.QueryAllSupplierResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
Expand Down
Loading

0 comments on commit 65e2ac8

Please sign in to comment.