Skip to content

Commit

Permalink
Add pagination response for commands (cosmos#6825)
Browse files Browse the repository at this point in the history
* migrated auth cli to use grpc query client

* unpacker added for account command

* fxed tests

* added grpc register in module.go

* fixed grpc failing issue

* page resonse added for console

* added reference

* paginations res added for commands

* Fix auth cli tests

Co-authored-by: SaReN <[email protected]>
Co-authored-by: Federico Kunze <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 7, 2020
1 parent ceba0cb commit 3322e26
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 36 deletions.
32 changes: 16 additions & 16 deletions x/auth/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), val1.Address)
s.Require().NoError(err)

var coins sdk.Coins
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
var balRes banktypes.QueryAllBalancesResponse
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
startTokens := coins.AmountOf(s.cfg.BondDenom)
startTokens := balRes.Balances.AmountOf(s.cfg.BondDenom)

// Test generate sendTx, estimate gas
finalGeneratedTx, err := bankcli.MsgSendExec(
Expand Down Expand Up @@ -284,9 +284,9 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), val1.Address)
s.Require().NoError(err)

err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
s.Require().Equal(startTokens, coins.AmountOf(s.cfg.BondDenom))
s.Require().Equal(startTokens, balRes.Balances.AmountOf(s.cfg.BondDenom))

// Test broadcast

Expand All @@ -307,15 +307,15 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), account.GetAddress())
s.Require().NoError(err)

err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
s.Require().Equal(sendTokens.Amount, coins.AmountOf(s.cfg.BondDenom))
s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom))

// Ensure origin account state
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), val1.Address)
s.Require().NoError(err)

err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
}

Expand Down Expand Up @@ -451,10 +451,10 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), multisigInfo.GetAddress())
s.Require().NoError(err)

var coins sdk.Coins
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
var balRes banktypes.QueryAllBalancesResponse
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
intialCoins := coins
intialCoins := balRes.Balances

// Send coins from validator to multisig.
sendTokens := sdk.NewInt64Coin(s.cfg.BondDenom, 10)
Expand All @@ -475,9 +475,9 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
resp, err = bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), multisigInfo.GetAddress())
s.Require().NoError(err)

err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
diff, _ := coins.SafeSub(intialCoins)
diff, _ := balRes.Balances.SafeSub(intialCoins)
s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom))

// Generate multisig transaction.
Expand Down Expand Up @@ -567,10 +567,10 @@ func (s *IntegrationTestSuite) TestCLIMultisign() {
resp, err := bankcli.QueryBalancesExec(val1.ClientCtx.WithOutputFormat("json"), multisigInfo.GetAddress())
s.Require().NoError(err)

var coins sdk.Coins
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &coins)
var balRes banktypes.QueryAllBalancesResponse
err = val1.ClientCtx.JSONMarshaler.UnmarshalJSON(resp.Bytes(), &balRes)
s.Require().NoError(err)
s.Require().Equal(sendTokens.Amount, coins.AmountOf(s.cfg.BondDenom))
s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom))

// Generate multisig transaction.
multiGeneratedTx, err := bankcli.MsgSendExec(
Expand Down
15 changes: 10 additions & 5 deletions x/bank/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/cosmos/cosmos-sdk/testutil/network"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/bank/client/cli"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/client/testutil"
"github.com/cosmos/cosmos-sdk/x/bank/types"
)

type IntegrationTestSuite struct {
Expand Down Expand Up @@ -62,11 +64,14 @@ func (s *IntegrationTestSuite) TestGetBalancesCmd() {
fmt.Sprintf("--%s=1", flags.FlagHeight),
},
false,
&sdk.Coins{},
sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
),
&types.QueryAllBalancesResponse{},
&types.QueryAllBalancesResponse{
Balances: sdk.NewCoins(
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
),
Pagination: &query.PageResponse{},
},
},
{
"total account balance of a specific denom",
Expand Down
2 changes: 1 addition & 1 deletion x/bank/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Example:
if err != nil {
return err
}
return clientCtx.PrintOutput(res.Balances)
return clientCtx.PrintOutput(res)
}

params := types.NewQueryBalanceRequest(addr, denom)
Expand Down
4 changes: 2 additions & 2 deletions x/distribution/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorSlashes() {
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
false,
"null",
"{\"slashes\":null,\"pagination\":{}}",
},
{
"text output",
Expand All @@ -309,7 +309,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryValidatorSlashes() {
sdk.ValAddress(val.Address).String(), "1", "3",
},
false,
"null",
"pagination: {}\nslashes: null",
},
}

Expand Down
2 changes: 1 addition & 1 deletion x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ $ %s query distribution slashes cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmq
return err
}

return clientCtx.PrintOutput(res.GetSlashes())
return clientCtx.PrintOutput(res)
},
}

Expand Down
10 changes: 6 additions & 4 deletions x/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ $ %s query gov proposals --page=2 --limit=100
}

if len(res.GetProposals()) == 0 {
return fmt.Errorf("no matching proposals found")
return fmt.Errorf("no proposals found")
}

return clientCtx.PrintOutput(res.GetProposals())
return clientCtx.PrintOutput(res)
},
}

Expand Down Expand Up @@ -311,11 +311,12 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
context.Background(),
&types.QueryVotesRequest{ProposalId: proposalID, Pagination: pageReq},
)

if err != nil {
return err
}

return clientCtx.PrintOutput(res.GetVotes())
return clientCtx.PrintOutput(res)

},
}
Expand Down Expand Up @@ -458,11 +459,12 @@ $ %s query gov deposits 1
context.Background(),
&types.QueryDepositsRequest{ProposalId: proposalID, Pagination: pageReq},
)

if err != nil {
return err
}

return clientCtx.PrintOutput(res.GetDeposits())
return clientCtx.PrintOutput(res)
},
}

Expand Down
2 changes: 1 addition & 1 deletion x/slashing/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ $ <appcli> query slashing signing-infos
return err
}

return clientCtx.PrintOutput(res.Info)
return clientCtx.PrintOutput(res)
},
}

Expand Down
12 changes: 6 additions & 6 deletions x/staking/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ $ %s query staking unbonding-delegations-from cosmosvaloper1gghjut3ccd8ay0zduzj6
return err
}

return clientCtx.PrintOutput(res.UnbondingResponses)
return clientCtx.PrintOutput(res)
},
}

Expand Down Expand Up @@ -234,7 +234,7 @@ $ %s query staking redelegations-from cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
return err
}

return clientCtx.PrintOutput(res.RedelegationResponses)
return clientCtx.PrintOutput(res)
},
}

Expand Down Expand Up @@ -342,7 +342,7 @@ $ %s query staking delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
return err
}

return clientCtx.PrintOutput(res.DelegationResponses)
return clientCtx.PrintOutput(res)
},
}

Expand Down Expand Up @@ -397,7 +397,7 @@ $ %s query staking delegations-to cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ld
return err
}

return clientCtx.PrintOutput(res.DelegationResponses)
return clientCtx.PrintOutput(res)
},
}

Expand Down Expand Up @@ -506,7 +506,7 @@ $ %s query staking unbonding-delegations cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld
return err
}

return clientCtx.PrintOutput(res.UnbondingResponses)
return clientCtx.PrintOutput(res)
},
}

Expand Down Expand Up @@ -621,7 +621,7 @@ $ %s query staking redelegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
return err
}

return clientCtx.PrintOutput(res.RedelegationResponses)
return clientCtx.PrintOutput(res)
},
}

Expand Down

0 comments on commit 3322e26

Please sign in to comment.