-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Application] Scaffolded the Application type (without CRUD messages)…
… and nothing else (#47) Ran the following command: ``` ignite scaffold map application --module application --signer address --no-message --index address --yes ```
- Loading branch information
Showing
15 changed files
with
672 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
syntax = "proto3"; | ||
package pocket.application; | ||
|
||
option go_package = "pocket/x/application/types"; | ||
|
||
message Application { | ||
string address = 1; | ||
|
||
} | ||
|
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,12 +1,16 @@ | ||
syntax = "proto3"; | ||
|
||
package pocket.application; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "pocket/application/params.proto"; | ||
import "pocket/application/application.proto"; | ||
|
||
option go_package = "pocket/x/application/types"; | ||
|
||
// GenesisState defines the application module's genesis state. | ||
message GenesisState { | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
Params params = 1 [(gogoproto.nullable) = false]; | ||
repeated Application applicationList = 2 [(gogoproto.nullable) = false]; | ||
} | ||
|
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,26 +1,58 @@ | ||
syntax = "proto3"; | ||
|
||
package pocket.application; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "pocket/application/params.proto"; | ||
import "pocket/application/application.proto"; | ||
|
||
option go_package = "pocket/x/application/types"; | ||
|
||
// Query defines the gRPC querier service. | ||
service Query { | ||
|
||
// Parameters queries the parameters of the module. | ||
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { | ||
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) { | ||
option (google.api.http).get = "/pocket/application/params"; | ||
|
||
} | ||
|
||
// Queries a list of Application items. | ||
rpc Application (QueryGetApplicationRequest) returns (QueryGetApplicationResponse) { | ||
option (google.api.http).get = "/pocket/application/application/{address}"; | ||
|
||
} | ||
rpc ApplicationAll (QueryAllApplicationRequest) returns (QueryAllApplicationResponse) { | ||
option (google.api.http).get = "/pocket/application/application"; | ||
|
||
} | ||
} | ||
|
||
// 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]; | ||
} | ||
} | ||
|
||
message QueryGetApplicationRequest { | ||
string address = 1; | ||
} | ||
|
||
message QueryGetApplicationResponse { | ||
Application application = 1 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
message QueryAllApplicationRequest { | ||
cosmos.base.query.v1beta1.PageRequest pagination = 1; | ||
} | ||
|
||
message QueryAllApplicationResponse { | ||
repeated Application application = 1 [(gogoproto.nullable) = false]; | ||
cosmos.base.query.v1beta1.PageResponse pagination = 2; | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/spf13/cobra" | ||
|
||
"pocket/x/application/types" | ||
) | ||
|
||
func CmdListApplication() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list-application", | ||
Short: "list all application", | ||
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.QueryAllApplicationRequest{ | ||
Pagination: pageReq, | ||
} | ||
|
||
res, err := queryClient.ApplicationAll(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddPaginationFlagsToCmd(cmd, cmd.Use) | ||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func CmdShowApplication() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show-application [address]", | ||
Short: "shows a application", | ||
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) | ||
|
||
argAddress := args[0] | ||
|
||
params := &types.QueryGetApplicationRequest{ | ||
Address: argAddress, | ||
} | ||
|
||
res, err := queryClient.Application(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
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 |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package cli_test | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
tmcli "github.com/cometbft/cometbft/libs/cli" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/stretchr/testify/require" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"pocket/testutil/network" | ||
"pocket/testutil/nullify" | ||
"pocket/x/application/client/cli" | ||
"pocket/x/application/types" | ||
) | ||
|
||
// Prevent strconv unused error | ||
var _ = strconv.IntSize | ||
|
||
func networkWithApplicationObjects(t *testing.T, n int) (*network.Network, []types.Application) { | ||
t.Helper() | ||
cfg := network.DefaultConfig() | ||
state := types.GenesisState{} | ||
for i := 0; i < n; i++ { | ||
application := types.Application{ | ||
Address: strconv.Itoa(i), | ||
} | ||
nullify.Fill(&application) | ||
state.ApplicationList = append(state.ApplicationList, application) | ||
} | ||
buf, err := cfg.Codec.MarshalJSON(&state) | ||
require.NoError(t, err) | ||
cfg.GenesisState[types.ModuleName] = buf | ||
return network.New(t, cfg), state.ApplicationList | ||
} | ||
|
||
func TestShowApplication(t *testing.T) { | ||
net, objs := networkWithApplicationObjects(t, 2) | ||
|
||
ctx := net.Validators[0].ClientCtx | ||
common := []string{ | ||
fmt.Sprintf("--%s=json", tmcli.OutputFlag), | ||
} | ||
tests := []struct { | ||
desc string | ||
idAddress string | ||
|
||
args []string | ||
err error | ||
obj types.Application | ||
}{ | ||
{ | ||
desc: "found", | ||
idAddress: objs[0].Address, | ||
|
||
args: common, | ||
obj: objs[0], | ||
}, | ||
{ | ||
desc: "not found", | ||
idAddress: 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.idAddress, | ||
} | ||
args = append(args, tc.args...) | ||
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowApplication(), 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.QueryGetApplicationResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.NotNil(t, resp.Application) | ||
require.Equal(t, | ||
nullify.Fill(&tc.obj), | ||
nullify.Fill(&resp.Application), | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestListApplication(t *testing.T) { | ||
net, objs := networkWithApplicationObjects(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.CmdListApplication(), args) | ||
require.NoError(t, err) | ||
var resp types.QueryAllApplicationResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.LessOrEqual(t, len(resp.Application), step) | ||
require.Subset(t, | ||
nullify.Fill(objs), | ||
nullify.Fill(resp.Application), | ||
) | ||
} | ||
}) | ||
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.CmdListApplication(), args) | ||
require.NoError(t, err) | ||
var resp types.QueryAllApplicationResponse | ||
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) | ||
require.LessOrEqual(t, len(resp.Application), step) | ||
require.Subset(t, | ||
nullify.Fill(objs), | ||
nullify.Fill(resp.Application), | ||
) | ||
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.CmdListApplication(), args) | ||
require.NoError(t, err) | ||
var resp types.QueryAllApplicationResponse | ||
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.Application), | ||
) | ||
}) | ||
} |
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
Oops, something went wrong.