remove hyphen in module name

This commit is contained in:
2022-09-06 22:18:09 +00:00
parent 5d2534234d
commit 2326952cd4
77 changed files with 270 additions and 272 deletions

View File

@@ -0,0 +1,36 @@
package cli
import (
"fmt"
// "strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"
"colinear/x/colinearcore/types"
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group colinear queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdShowNextAuction())
cmd.AddCommand(CmdListAuction())
cmd.AddCommand(CmdShowAuction())
cmd.AddCommand(CmdAuctionBids())
// this line is used by starport scaffolding # 1
return cmd
}

View File

@@ -0,0 +1,74 @@
package cli
import (
"context"
"colinear/x/colinearcore/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
func CmdListAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "list-auction",
Short: "list all auction",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryAllAuctionRequest{
Pagination: pageReq,
}
res, err := queryClient.AuctionAll(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddPaginationFlagsToCmd(cmd, cmd.Use)
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func CmdShowAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "show-auction [index]",
Short: "shows a auction",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
argIndex := args[0]
params := &types.QueryGetAuctionRequest{
Index: argIndex,
}
res, err := queryClient.Auction(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@@ -0,0 +1,47 @@
package cli
import (
"strconv"
"colinear/x/colinearcore/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdAuctionBids() *cobra.Command {
cmd := &cobra.Command{
Use: "auction-bids [index]",
Short: "Query auctionBids",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqIndex := args[0]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryAuctionBidsRequest{
Index: reqIndex,
}
res, err := queryClient.AuctionBids(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@@ -0,0 +1,161 @@
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/tendermint/tendermint/libs/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"colinear/testutil/network"
"colinear/testutil/nullify"
"colinear/x/colinearcore/client/cli"
"colinear/x/colinearcore/types"
)
// Prevent strconv unused error
var _ = strconv.IntSize
func networkWithAuctionObjects(t *testing.T, n int) (*network.Network, []types.Auction) {
t.Helper()
cfg := network.DefaultConfig()
state := types.GenesisState{}
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))
for i := 0; i < n; i++ {
auction := types.Auction{
Index: strconv.Itoa(i),
}
nullify.Fill(&auction)
state.AuctionList = append(state.AuctionList, auction)
}
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
return network.New(t, cfg), state.AuctionList
}
func TestShowAuction(t *testing.T) {
net, objs := networkWithAuctionObjects(t, 2)
ctx := net.Validators[0].ClientCtx
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
idIndex string
args []string
err error
obj types.Auction
}{
{
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"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
args := []string{
tc.idIndex,
}
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowAuction(), 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.QueryGetAuctionResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.Auction)
require.Equal(t,
nullify.Fill(&tc.obj),
nullify.Fill(&resp.Auction),
)
}
})
}
}
func TestListAuction(t *testing.T) {
net, objs := networkWithAuctionObjects(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.CmdListAuction(), args)
require.NoError(t, err)
var resp types.QueryAllAuctionResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.LessOrEqual(t, len(resp.Auction), step)
require.Subset(t,
nullify.Fill(objs),
nullify.Fill(resp.Auction),
)
}
})
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.CmdListAuction(), args)
require.NoError(t, err)
var resp types.QueryAllAuctionResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.LessOrEqual(t, len(resp.Auction), step)
require.Subset(t,
nullify.Fill(objs),
nullify.Fill(resp.Auction),
)
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.CmdListAuction(), args)
require.NoError(t, err)
var resp types.QueryAllAuctionResponse
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.Auction),
)
})
}

View File

@@ -0,0 +1,37 @@
package cli
import (
"context"
"colinear/x/colinearcore/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
func CmdShowNextAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "show-next-auction",
Short: "shows nextAuction",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryGetNextAuctionRequest{}
res, err := queryClient.NextAuction(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@@ -0,0 +1,72 @@
package cli_test
import (
"fmt"
"testing"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/stretchr/testify/require"
tmcli "github.com/tendermint/tendermint/libs/cli"
"google.golang.org/grpc/status"
"colinear/testutil/network"
"colinear/testutil/nullify"
"colinear/x/colinearcore/client/cli"
"colinear/x/colinearcore/types"
)
func networkWithNextAuctionObjects(t *testing.T) (*network.Network, types.NextAuction) {
t.Helper()
cfg := network.DefaultConfig()
state := types.GenesisState{}
require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state))
nextAuction := &types.NextAuction{}
nullify.Fill(&nextAuction)
state.NextAuction = nextAuction
buf, err := cfg.Codec.MarshalJSON(&state)
require.NoError(t, err)
cfg.GenesisState[types.ModuleName] = buf
return network.New(t, cfg), *state.NextAuction
}
func TestShowNextAuction(t *testing.T) {
net, obj := networkWithNextAuctionObjects(t)
ctx := net.Validators[0].ClientCtx
common := []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
}
for _, tc := range []struct {
desc string
args []string
err error
obj types.NextAuction
}{
{
desc: "get",
args: common,
obj: obj,
},
} {
t.Run(tc.desc, func(t *testing.T) {
var args []string
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowNextAuction(), 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.QueryGetNextAuctionResponse
require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.NotNil(t, resp.NextAuction)
require.Equal(t,
nullify.Fill(&tc.obj),
nullify.Fill(&resp.NextAuction),
)
}
})
}
}

View File

@@ -0,0 +1,35 @@
package cli
import (
"context"
"colinear/x/colinearcore/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
)
func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@@ -0,0 +1,38 @@
package cli
import (
"fmt"
"time"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
"colinear/x/colinearcore/types"
)
var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
)
const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)
// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(CmdNewAuction())
cmd.AddCommand(CmdNewBid())
// this line is used by starport scaffolding # 1
return cmd
}

View File

@@ -0,0 +1,57 @@
package cli
import (
"strconv"
"colinear/x/colinearcore/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdNewAuction() *cobra.Command {
cmd := &cobra.Command{
Use: "new-auction [name] [description] [ceiling] [denom] [end date]",
Short: "Broadcast message newAuction",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argName := args[0]
argDescription := args[1]
argCeiling := args[2]
argDenom := args[3]
argLeaseEnd := args[4]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
var le int
le, err = strconv.Atoi(argLeaseEnd)
if err != nil {
return err
}
msg := types.NewMsgNewAuction(
clientCtx.GetFromAddress().String(),
argName,
argDescription,
argCeiling,
argDenom,
uint64(le),
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}

View File

@@ -0,0 +1,45 @@
package cli
import (
"strconv"
"colinear/x/colinearcore/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
)
var _ = strconv.Itoa(0)
func CmdNewBid() *cobra.Command {
cmd := &cobra.Command{
Use: "new-bid [auction-index] [amount]",
Short: "Broadcast message newBid",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argAuctionIndex := args[0]
argAmount := args[1]
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgNewBid(
clientCtx.GetFromAddress().String(),
argAuctionIndex,
argAmount,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}