Skip to content

Commit

Permalink
chore: added new field account-id with uint64 in `AccountAddressByI…
Browse files Browse the repository at this point in the history
…D` (#13780)

* add changes

* Update CHANGELOG.md

* Update CHANGELOG.md

* review changes

* add test

* fix static check

* fix lint

* fix lint

* fix lint

* review changes

* review changes

* review changes

* review changes

* fix tests

* Update CHANGELOG.md

Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>

* Update proto/cosmos/auth/v1beta1/query.proto

Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>

* review changes

* lint

* review changes

Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>
  • Loading branch information
atheeshp and likhita-809 authored Nov 21, 2022
1 parent 385bff5 commit 42597ee
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 212 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/gov) [#12771](https://github.com/cosmos/cosmos-sdk/pull/12771) Initial deposit requirement for proposals at submission time.
* (x/staking) [#12967](https://github.com/cosmos/cosmos-sdk/pull/12967) `unbond` now creates only one unbonding delegation entry when multiple unbondings exist at a single height (e.g. through multiple messages in a transaction).
* (x/auth/vesting) [#13502](https://github.com/cosmos/cosmos-sdk/pull/13502) Add Amino Msg registration for `MsgCreatePeriodicVestingAccount`.
* (x/auth)[#13780](https://github.com/cosmos/cosmos-sdk/pull/13780) `id` (type of int64) in `AccountAddressByID` grpc query is now deprecated, update to account-id(type of uint64) to use `AccountAddressByID`.
* (x/group) [#13876](https://github.com/cosmos/cosmos-sdk/pull/13876) Fix group MinExecutionPeriod that is checked on execution now, instead of voting period end.

### API Breaking Changes

Expand Down Expand Up @@ -168,6 +170,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#13794](https://github.com/cosmos/cosmos-sdk/pull/13794) Most methods on `types/module.AppModule` have been moved to
extension interfaces. `module.Manager.Modules` is now of type `map[string]interface{}` to support in parallel the new
`cosmossdk.io/core/appmodule.AppModule` API.
* (x/group) [#13876](https://github.com/cosmos/cosmos-sdk/pull/13876) Add `GetMinExecutionPeriod` method on DecisionPolicy interface.
* (x/auth)[#13780](https://github.com/cosmos/cosmos-sdk/pull/13780) Querying with `id` (type of int64) in `AccountAddressByID` grpc query now throws error, use account-id(type of uint64) instead.

### CLI Breaking Changes

Expand Down
325 changes: 194 additions & 131 deletions api/cosmos/auth/v1beta1/query.pulsar.go

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion proto/cosmos/auth/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,17 @@ message AddressStringToBytesResponse {
//
// Since: cosmos-sdk 0.46.2
message QueryAccountAddressByIDRequest {
// Deprecated, use account_id instead
//
// id is the account number of the address to be queried. This field
// should have been an uint64 (like all account numbers), and will be
// updated to uint64 in a future version of the auth query.
int64 id = 1;
int64 id = 1 [deprecated = true];

// account_id is the account number of the address to be queried.
//
// Since: cosmos-sdk 0.47
uint64 account_id = 2;
}

// QueryAccountAddressByIDResponse is the response type for AccountAddressByID rpc method
Expand Down
6 changes: 4 additions & 2 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ func GetAccountAddressByIDCmd() *cobra.Command {
return err
}

accNum, err := strconv.ParseInt(args[0], 10, 64)
accNum, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.AccountAddressByID(cmd.Context(), &types.QueryAccountAddressByIDRequest{Id: accNum})
res, err := queryClient.AccountAddressByID(cmd.Context(), &types.QueryAccountAddressByIDRequest{
AccountId: accNum,
})
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions x/auth/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,24 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccountAddressByID() {
pub := pubkeyGenerator(t).Draw(t, "pubkey")
addr := sdk.AccAddress(pub.Address())

accNum := rapid.Int64Min(0).Draw(t, "account-number")
accNum := rapid.Uint64().Draw(t, "account-number")
seq := rapid.Uint64().Draw(t, "sequence")

acc1 := types.NewBaseAccount(addr, &pub, uint64(accNum), seq)
acc1 := types.NewBaseAccount(addr, &pub, accNum, seq)
suite.accountKeeper.SetAccount(suite.ctx, acc1)

req := &types.QueryAccountAddressByIDRequest{Id: accNum}
req := &types.QueryAccountAddressByIDRequest{AccountId: accNum}
testdata.DeterministicIterations(suite.ctx, suite.Require(), req, suite.queryClient.AccountAddressByID, 0, true)
})

// Regression test
accNum := int64(10087)
accNum := uint64(10087)
seq := uint64(0)

acc1 := types.NewBaseAccount(addr, &secp256k1.PubKey{Key: pub}, uint64(accNum), seq)
acc1 := types.NewBaseAccount(addr, &secp256k1.PubKey{Key: pub}, accNum, seq)

suite.accountKeeper.SetAccount(suite.ctx, acc1)
req := &types.QueryAccountAddressByIDRequest{Id: accNum}
req := &types.QueryAccountAddressByIDRequest{AccountId: accNum}
testdata.DeterministicIterations(suite.ctx, suite.Require(), req, suite.queryClient.AccountAddressByID, 1123, false)
}

Expand Down
8 changes: 5 additions & 3 deletions x/auth/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ func (ak AccountKeeper) AccountAddressByID(c context.Context, req *types.QueryAc
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

if req.Id < 0 {
return nil, status.Error(codes.InvalidArgument, "invalid account number")
if req.Id != 0 { // ignoring `0` case since it is default value.
return nil, status.Error(codes.InvalidArgument, "requesting with id isn't supported, try to request using account-id")
}

accId := req.AccountId

ctx := sdk.UnwrapSDKContext(c)
address := ak.GetAccountAddressByID(ctx, uint64(req.GetId()))
address := ak.GetAccountAddressByID(ctx, accId)
if len(address) == 0 {
return nil, status.Errorf(codes.NotFound, "account address not found with account number %d", req.Id)
}
Expand Down
14 changes: 12 additions & 2 deletions x/auth/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,27 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccountAddressByID() {
func(res *types.QueryAccountAddressByIDResponse) {},
},
{
"valid request",
"valid account-id",
func() {
account := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)
suite.accountKeeper.SetAccount(suite.ctx, account)
req = &types.QueryAccountAddressByIDRequest{Id: int64(account.GetAccountNumber())}
req = &types.QueryAccountAddressByIDRequest{AccountId: account.GetAccountNumber()}
},
true,
func(res *types.QueryAccountAddressByIDResponse) {
suite.Require().NotNil(res.AccountAddress)
},
},
{
"invalid request",
func() {
account := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)
suite.accountKeeper.SetAccount(suite.ctx, account)
req = &types.QueryAccountAddressByIDRequest{Id: 1}
},
false,
func(res *types.QueryAccountAddressByIDResponse) {},
},
}

for _, tc := range testCases {
Expand Down
Loading

0 comments on commit 42597ee

Please sign in to comment.