Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bank): autocli query support #16899

Merged
merged 8 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The testutil `QueryAccountExec` has been removed from auth as it was using the CLI.
* (testutil) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) The *cli testutil* `QueryBalancesExec` has been removed. Use the gRPC or REST query instead.
* (x/auth) [#16650](https://github.com/cosmos/cosmos-sdk/pull/16650) The *cli testutil* `QueryAccountExec` has been removed. Use the gRPC or REST query instead.
* (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16798) Remove aliases in `types/math.go` (part 2).
* (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`:
* remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`.
Expand All @@ -71,6 +72,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16795) `DelegationToDelegationResponse`, `DelegationsToDelegationResponses`, `RedelegationsToRedelegationResponses` are no longer exported.
* [#16441](https://github.com/cosmos/cosmos-sdk/pull/16441) Params state is migrated to collections. `GetParams` has been removed

## CLI Breaking Changes

* (x/bank) [#16899](https://github.com/cosmos/cosmos-sdk/pull/16899) With the migration to AutoCLI some bank commands have been split in two:
* Use `denoms-metadata` for querying all denom metadata and `denom-metadata` for querying a specific denom metadata.
* Use `total-supply` (or `total`) for querying the total supply and `total-supply-of` for querying the supply of a specific denom.

## [v0.50.0-alpha.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.1) - 2023-06-30

### Features
Expand Down
43 changes: 21 additions & 22 deletions tests/e2e/auth/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {
s.Require().NoError(err)
s.Require().Equal(0, len(sigs))

resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos"))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, val1.Address))
s.Require().NoError(err)

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

Expand Down Expand Up @@ -679,10 +679,9 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {
s.Require().NoError(s.network.WaitForNextBlock())

// Ensure foo has right amount of funds
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos"))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, val1.Address))
s.Require().NoError(err)

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

Expand All @@ -701,20 +700,20 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {

// Ensure destiny account state
err = s.network.RetryForBlocks(func() error {
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr))
s.Require().NoError(err)
return err
}, 3)
s.Require().NoError(err)

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

// Ensure origin account state
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos"))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, val1.Address))
s.Require().NoError(err)

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

Expand Down Expand Up @@ -833,11 +832,11 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() {

addr, err := multisigRecord.GetAddress()
s.Require().NoError(err)
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr))
s.Require().NoError(err)

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

Expand All @@ -851,10 +850,9 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() {
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())

resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
resp, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr))
s.Require().NoError(err)

err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
err = val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes)
s.Require().NoError(err)
diff, _ := balRes.Balances.SafeSub(intialCoins...)
s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom))
Expand Down Expand Up @@ -993,11 +991,12 @@ func (s *E2ETestSuite) TestCLIMultisign() {

var balRes banktypes.QueryAllBalancesResponse
err = s.network.RetryForBlocks(func() error {
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val1.APIAddress, addr))
s.Require().NoError(err)
if err != nil {
return err
}
return val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
return val1.ClientCtx.Codec.UnmarshalJSON(resp, &balRes)
}, 3)
s.Require().NoError(err)
s.Require().True(sendTokens.Amount.Equal(balRes.Balances.AmountOf(s.cfg.BondDenom)))
Expand Down Expand Up @@ -1393,10 +1392,10 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() {
require.Equal(uint32(0), txRes.Code, txRes.RawLog)

// Make sure the addr1's balance got funded.
queryResJSON, err := clitestutil.QueryBalancesExec(val0.ClientCtx, addr1, addresscodec.NewBech32Codec("cosmos"))
require.NoError(err)
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s", val0.APIAddress, addr1))
s.Require().NoError(err)
var queryRes banktypes.QueryAllBalancesResponse
err = val0.ClientCtx.Codec.UnmarshalJSON(queryResJSON.Bytes(), &queryRes)
err = val0.ClientCtx.Codec.UnmarshalJSON(resp, &queryRes)
require.NoError(err)
require.Equal(sdk.NewCoins(val0Coin, val1Coin), queryRes.Balances)
}
Expand Down Expand Up @@ -1729,11 +1728,11 @@ func (s *E2ETestSuite) createBankMsg(val *network.Validator, toAddr sdk.AccAddre
}

func (s *E2ETestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int {
resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
resp, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/bank/v1beta1/balances/%s/by_denom?denom=%s", s.cfg.APIAddress, addr.String(), denom))
s.Require().NoError(err)

var balRes banktypes.QueryAllBalancesResponse
err = clientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
err = clientCtx.Codec.UnmarshalJSON(resp, &balRes)
s.Require().NoError(err)
startTokens := balRes.Balances.AmountOf(denom)
return startTokens
Expand Down
Loading
Loading