refactor(query): align with cosmos-sdk style (#466)

- use one `cmd.AddCommand(...)`
- sort commands
- use `GetCmd...` function name style

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2024-11-12 15:59:52 +01:00 committed by GitHub
parent 8db682d994
commit bead62bd04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 54 additions and 58 deletions

View File

@ -85,7 +85,7 @@ func (s *E2ETestSuite) TestNotarizeAsset() {
if !tc.expectCheckTxErr { if !tc.expectCheckTxErr {
assert.Equal(s.T(), int(0), int(txResponse.Code)) assert.Equal(s.T(), int(0), int(txResponse.Code))
args := []string{sample.Asset()} args := []string{sample.Asset()}
asset, err := clitestutil.ExecTestCLICmd(val.ClientCtx, assetcli.CmdGetByCID(), args) asset, err := clitestutil.ExecTestCLICmd(val.ClientCtx, assetcli.GetCmdByCID(), args)
s.Require().NoError(err) s.Require().NoError(err)
assert.Contains(s.T(), asset.String(), sample.Asset()) assert.Contains(s.T(), asset.String(), sample.Asset())
} else { } else {

View File

@ -207,6 +207,6 @@ func (s *E2ETestSuite) TestReissuance() {
// - because we waited on the reissuance result, see above // - because we waited on the reissuance result, see above
intValue := strconv.FormatInt(latestHeight-wait, 10) intValue := strconv.FormatInt(latestHeight-wait, 10)
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetReissuance(), []string{intValue}) _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.GetCmdReissuance(), []string{intValue})
s.Require().NoError(err) s.Require().NoError(err)
} }

View File

@ -91,7 +91,7 @@ func (s *AssetDistributionE2ETestSuite) TestAssetDistribution() {
} }
for _, tc := range testCases { for _, tc := range testCases {
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetDistribution(), []string{ _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.GetCmdDistribution(), []string{
strconv.FormatInt(tc.requestHeight, 10), strconv.FormatInt(tc.requestHeight, 10),
}) })
if tc.expectedErr == "" { if tc.expectedErr == "" {

View File

@ -122,7 +122,7 @@ func (s *SelectionE2ETestSuite) perpareLocalTest() testutil.BufferWriter {
} }
} }
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdGetChallenge(), []string{ out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.GetCmdChallenge(), []string{
strconv.FormatInt(latestHeight-wait, 10), strconv.FormatInt(latestHeight-wait, 10),
}) })
s.Require().NoError(err) s.Require().NoError(err)
@ -331,11 +331,11 @@ func (s *SelectionE2ETestSuite) TestTokenRedeemClaim() {
s.Require().NoError(s.network.WaitForNextBlock()) s.Require().NoError(s.network.WaitForNextBlock())
// QueryRedeemClaim // QueryRedeemClaim
qOut, err := clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdShowRedeemClaim(), []string{"liquidAddress", "0"}) qOut, err := clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.GetCmdShowRedeemClaim(), []string{"liquidAddress", "0"})
s.Require().NoError(err) s.Require().NoError(err)
assert.Equal(s.T(), "redeemClaim:\n amount: \"5993160682\"\n beneficiary: liquidAddress\n confirmed: true\n creator: plmnt1kp93kns6hs2066d8qw0uz84fw3vlthewt2ck6p\n id: \"0\"\n liquidTxHash: \"0000000000000000000000000000000000000000000000000000000000000000\"\n", qOut.String()) assert.Equal(s.T(), "redeemClaim:\n amount: \"5993160682\"\n beneficiary: liquidAddress\n confirmed: true\n creator: plmnt1kp93kns6hs2066d8qw0uz84fw3vlthewt2ck6p\n id: \"0\"\n liquidTxHash: \"0000000000000000000000000000000000000000000000000000000000000000\"\n", qOut.String())
qOut, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.CmdRedeemClaimByLiquidTxHash(), []string{"0000000000000000000000000000000000000000000000000000000000000000"}) qOut, err = clitestutil.ExecTestCLICmd(val.ClientCtx, daocli.GetCmdRedeemClaimByLiquidTxHash(), []string{"0000000000000000000000000000000000000000000000000000000000000000"})
s.Require().NoError(err) s.Require().NoError(err)
assert.Equal(s.T(), "redeemClaim:\n amount: \"5993160682\"\n beneficiary: liquidAddress\n confirmed: true\n creator: plmnt1kp93kns6hs2066d8qw0uz84fw3vlthewt2ck6p\n id: \"0\"\n liquidTxHash: \"0000000000000000000000000000000000000000000000000000000000000000\"\n", qOut.String()) assert.Equal(s.T(), "redeemClaim:\n amount: \"5993160682\"\n beneficiary: liquidAddress\n confirmed: true\n creator: plmnt1kp93kns6hs2066d8qw0uz84fw3vlthewt2ck6p\n id: \"0\"\n liquidTxHash: \"0000000000000000000000000000000000000000000000000000000000000000\"\n", qOut.String())

View File

@ -111,7 +111,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
pubKey, pubKey,
} }
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args) _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.GetCmdMachineByPublicKey(), args)
s.Require().NoError(err) s.Require().NoError(err)
txResponse, err := lib.GetTxResponseFromOut(out) txResponse, err := lib.GetTxResponseFromOut(out)
s.Require().NoError(err) s.Require().NoError(err)
@ -230,6 +230,6 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
pubKey, pubKey,
} }
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args) _, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.GetCmdMachineByPublicKey(), args)
s.Require().NoError(err) s.Require().NoError(err)
} }

View File

@ -24,9 +24,11 @@ func GetQueryCmd(_ string) *cobra.Command {
RunE: client.ValidateCmd, RunE: client.ValidateCmd,
} }
cmd.AddCommand(CmdGetByAddress()) cmd.AddCommand(
cmd.AddCommand(CmdGetByCID()) GetCmdByAddress(),
cmd.AddCommand(CmdQueryParams()) GetCmdByCID(),
GetCmdQueryParams(),
)
// this line is used by starport scaffolding # 1 // this line is used by starport scaffolding # 1

View File

@ -12,7 +12,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetByAddress() *cobra.Command { func GetCmdByAddress() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "address [address] [num-elements]", Use: "address [address] [num-elements]",
Short: "Query for assets by address", Short: "Query for assets by address",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetByCID() *cobra.Command { func GetCmdByCID() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "cid [cid]", Use: "cid [cid]",
Short: "Query for assets by CID", Short: "Query for assets by CID",

View File

@ -8,7 +8,7 @@ import (
"github.com/planetmint/planetmint-go/x/asset/types" "github.com/planetmint/planetmint-go/x/asset/types"
) )
func CmdQueryParams() *cobra.Command { func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "params", Use: "params",
Short: "Query the current asset parameters information", Short: "Query the current asset parameters information",

View File

@ -21,23 +21,18 @@ func GetQueryCmd(_ string) *cobra.Command {
RunE: client.ValidateCmd, RunE: client.ValidateCmd,
} }
cmd.AddCommand(CmdQueryParams()) cmd.AddCommand(
GetCmdChallenge(),
cmd.AddCommand(CmdGetMintRequests()) GetCmdChallenges(),
GetCmdDistribution(),
cmd.AddCommand(CmdGetReissuance()) GetCmdListRedeemClaim(),
GetCmdMintRequests(),
cmd.AddCommand(CmdGetReissuances()) GetCmdQueryParams(),
GetCmdRedeemClaimByLiquidTxHash(),
cmd.AddCommand(CmdGetChallenge()) GetCmdReissuance(),
GetCmdReissuances(),
cmd.AddCommand(CmdChallenges()) GetCmdShowRedeemClaim(),
)
cmd.AddCommand(CmdGetDistribution())
cmd.AddCommand(CmdListRedeemClaim())
cmd.AddCommand(CmdShowRedeemClaim())
cmd.AddCommand(CmdRedeemClaimByLiquidTxHash())
// this line is used by starport scaffolding # 1 // this line is used by starport scaffolding # 1

View File

@ -12,7 +12,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetChallenge() *cobra.Command { func GetCmdChallenge() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "challenge [height]", Use: "challenge [height]",
Short: "Query for challenge by height", Short: "Query for challenge by height",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdChallenges() *cobra.Command { func GetCmdChallenges() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "challenges", Use: "challenges",
Short: "Query for challenges", Short: "Query for challenges",

View File

@ -14,7 +14,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetDistribution() *cobra.Command { func GetCmdDistribution() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "distribution [height]", Use: "distribution [height]",
Short: "Query for distributions by height", Short: "Query for distributions by height",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetMintRequests() *cobra.Command { func GetCmdMintRequests() *cobra.Command {
// Group mint-requests queries under a subcommand // Group mint-requests queries under a subcommand
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "mint-requests", Use: "mint-requests",

View File

@ -8,7 +8,7 @@ import (
"github.com/planetmint/planetmint-go/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
) )
func CmdQueryParams() *cobra.Command { func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "params", Use: "params",
Short: "Query the current dao parameters information", Short: "Query the current dao parameters information",

View File

@ -10,7 +10,7 @@ import (
"github.com/planetmint/planetmint-go/x/dao/types" "github.com/planetmint/planetmint-go/x/dao/types"
) )
func CmdListRedeemClaim() *cobra.Command { func GetCmdListRedeemClaim() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list-redeem-claim", Use: "list-redeem-claim",
Short: "list all redeem-claim", Short: "list all redeem-claim",
@ -46,7 +46,7 @@ func CmdListRedeemClaim() *cobra.Command {
return cmd return cmd
} }
func CmdShowRedeemClaim() *cobra.Command { func GetCmdShowRedeemClaim() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "show-redeem-claim [beneficiary] [id]", Use: "show-redeem-claim [beneficiary] [id]",
Short: "shows a redeem-claim", Short: "shows a redeem-claim",
@ -86,7 +86,7 @@ func CmdShowRedeemClaim() *cobra.Command {
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdRedeemClaimByLiquidTxHash() *cobra.Command { func GetCmdRedeemClaimByLiquidTxHash() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "redeem-claim-by-liquid-tx-hash [liquid-tx-hash]", Use: "redeem-claim-by-liquid-tx-hash [liquid-tx-hash]",
Short: "Query redeem-claim-by-liquid-tx-hash", Short: "Query redeem-claim-by-liquid-tx-hash",

View File

@ -12,7 +12,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetReissuance() *cobra.Command { func GetCmdReissuance() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "reissuance [height]", Use: "reissuance [height]",
Short: "Query for reissuance by height", Short: "Query for reissuance by height",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetReissuances() *cobra.Command { func GetCmdReissuances() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "reissuances", Use: "reissuances",
Short: "Query for reissuances", Short: "Query for reissuances",

View File

@ -24,16 +24,15 @@ func GetQueryCmd(_ string) *cobra.Command {
RunE: client.ValidateCmd, RunE: client.ValidateCmd,
} }
cmd.AddCommand(CmdQueryParams()) cmd.AddCommand(
cmd.AddCommand(CmdGetMachineByPublicKey()) GetCmdActivatedTrustAnchorCount(),
GetCmdActiveTrustAnchorCount(),
cmd.AddCommand(CmdGetTrustAnchor()) GetCmdLiquidAssetsByMachineid(),
cmd.AddCommand(CmdGetMachineByAddress()) GetCmdMachineByAddress(),
GetCmdMachineByPublicKey(),
cmd.AddCommand(CmdGetLiquidAssetsByMachineid()) GetCmdQueryParams(),
GetCmdTrustAnchor(),
cmd.AddCommand(CmdActiveTrustAnchorCount()) )
cmd.AddCommand(CmdActivatedTrustAnchorCount())
// this line is used by starport scaffolding # 1 // this line is used by starport scaffolding # 1

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdActivatedTrustAnchorCount() *cobra.Command { func GetCmdActivatedTrustAnchorCount() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "activated-trust-anchor-count", Use: "activated-trust-anchor-count",
Short: "Query activated-trust-anchor-count", Short: "Query activated-trust-anchor-count",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdActiveTrustAnchorCount() *cobra.Command { func GetCmdActiveTrustAnchorCount() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "active-trust-anchor-count", Use: "active-trust-anchor-count",
Short: "Query active-trust-anchor-count", Short: "Query active-trust-anchor-count",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetMachineByAddress() *cobra.Command { func GetCmdMachineByAddress() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "address [address]", Use: "address [address]",
Short: "Query for machines by address", Short: "Query for machines by address",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetLiquidAssetsByMachineid() *cobra.Command { func GetCmdLiquidAssetsByMachineid() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "liquid-assets [machine-id]", Use: "liquid-assets [machine-id]",
Short: "Query for liquid assets by machine ID", Short: "Query for liquid assets by machine ID",

View File

@ -8,7 +8,7 @@ import (
"github.com/planetmint/planetmint-go/x/machine/types" "github.com/planetmint/planetmint-go/x/machine/types"
) )
func CmdQueryParams() *cobra.Command { func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "params", Use: "params",
Short: "Query the current machine parameters information", Short: "Query the current machine parameters information",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetMachineByPublicKey() *cobra.Command { func GetCmdMachineByPublicKey() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "public-key [public-key]", Use: "public-key [public-key]",
Short: "Query for machines by public key", Short: "Query for machines by public key",

View File

@ -11,7 +11,7 @@ import (
var _ = strconv.Itoa(0) var _ = strconv.Itoa(0)
func CmdGetTrustAnchor() *cobra.Command { func GetCmdTrustAnchor() *cobra.Command {
// Group trust-anchor queries under a subcommand // Group trust-anchor queries under a subcommand
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "trust-anchor", Use: "trust-anchor",