From 55992ebfe48d8852be66d27d904adfa4d0441e82 Mon Sep 17 00:00:00 2001 From: Teddy Ding Date: Mon, 29 Apr 2024 18:46:38 -0600 Subject: [PATCH] Add `QueryAllLiquidityTiers` to CLI (#1434) --- protocol/x/perpetuals/client/cli/query.go | 1 + .../client/cli/query_all_liquidity_tiers.go | 33 +++++++++++++++++++ .../cli/query_all_liquidity_tiers_test.go | 28 ++++++++++++++++ protocol/x/perpetuals/module_test.go | 13 ++++---- 4 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 protocol/x/perpetuals/client/cli/query_all_liquidity_tiers.go create mode 100644 protocol/x/perpetuals/client/cli/query_all_liquidity_tiers_test.go diff --git a/protocol/x/perpetuals/client/cli/query.go b/protocol/x/perpetuals/client/cli/query.go index 81cf4f40e1..87b2c2d1a3 100644 --- a/protocol/x/perpetuals/client/cli/query.go +++ b/protocol/x/perpetuals/client/cli/query.go @@ -29,6 +29,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryParams()) cmd.AddCommand(CmdQueryPremiumSamples()) cmd.AddCommand(CmdQueryPremiumVotes()) + cmd.AddCommand(CmdQueryAllLiquidityTiers()) // this line is used by starport scaffolding # 1 return cmd diff --git a/protocol/x/perpetuals/client/cli/query_all_liquidity_tiers.go b/protocol/x/perpetuals/client/cli/query_all_liquidity_tiers.go new file mode 100644 index 0000000000..b5730ef414 --- /dev/null +++ b/protocol/x/perpetuals/client/cli/query_all_liquidity_tiers.go @@ -0,0 +1,33 @@ +package cli + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" + "github.com/spf13/cobra" +) + +func CmdQueryAllLiquidityTiers() *cobra.Command { + cmd := &cobra.Command{ + Use: "get-all-liquidity-tiers", + Short: "get all liquidity tiers", + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx := client.GetClientContextFromCmd(cmd) + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.AllLiquidityTiers( + context.Background(), + &types.QueryAllLiquidityTiersRequest{}, + ) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/protocol/x/perpetuals/client/cli/query_all_liquidity_tiers_test.go b/protocol/x/perpetuals/client/cli/query_all_liquidity_tiers_test.go new file mode 100644 index 0000000000..f7e7290287 --- /dev/null +++ b/protocol/x/perpetuals/client/cli/query_all_liquidity_tiers_test.go @@ -0,0 +1,28 @@ +//go:build all || integration_test + +package cli_test + +import ( + "fmt" + "testing" + + tmcli "github.com/cometbft/cometbft/libs/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/client/cli" + "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" + "github.com/stretchr/testify/require" +) + +func TestAllLiquidityTiers(t *testing.T) { + net, _, _ := networkWithLiquidityTierAndPerpetualObjects(t, 2, 2) + ctx := net.Validators[0].ClientCtx + + common := []string{fmt.Sprintf("--%s=json", tmcli.OutputFlag)} + + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdQueryAllLiquidityTiers(), common) + require.NoError(t, err) + + var resp types.QueryAllLiquidityTiersResponse + require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.Equal(t, 2, len(resp.LiquidityTiers)) +} diff --git a/protocol/x/perpetuals/module_test.go b/protocol/x/perpetuals/module_test.go index 68147a9afc..5cf71ea2ea 100644 --- a/protocol/x/perpetuals/module_test.go +++ b/protocol/x/perpetuals/module_test.go @@ -211,12 +211,13 @@ func TestAppModuleBasic_GetQueryCmd(t *testing.T) { cmd := am.GetQueryCmd() require.Equal(t, "perpetuals", cmd.Use) - require.Equal(t, 5, len(cmd.Commands())) - require.Equal(t, "get-params", cmd.Commands()[0].Name()) - require.Equal(t, "get-premium-samples", cmd.Commands()[1].Name()) - require.Equal(t, "get-premium-votes", cmd.Commands()[2].Name()) - require.Equal(t, "list-perpetual", cmd.Commands()[3].Name()) - require.Equal(t, "show-perpetual", cmd.Commands()[4].Name()) + require.Equal(t, 6, len(cmd.Commands())) + require.Equal(t, "get-all-liquidity-tiers", cmd.Commands()[0].Name()) + require.Equal(t, "get-params", cmd.Commands()[1].Name()) + require.Equal(t, "get-premium-samples", cmd.Commands()[2].Name()) + require.Equal(t, "get-premium-votes", cmd.Commands()[3].Name()) + require.Equal(t, "list-perpetual", cmd.Commands()[4].Name()) + require.Equal(t, "show-perpetual", cmd.Commands()[5].Name()) } func TestAppModule_Name(t *testing.T) {