Skip to content

Commit

Permalink
Add QueryAllLiquidityTiers to CLI (dydxprotocol#1434)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding authored Apr 30, 2024
1 parent 9275e81 commit 55992eb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions protocol/x/perpetuals/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions protocol/x/perpetuals/client/cli/query_all_liquidity_tiers.go
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions protocol/x/perpetuals/client/cli/query_all_liquidity_tiers_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
13 changes: 7 additions & 6 deletions protocol/x/perpetuals/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 55992eb

Please sign in to comment.