Added a condition in querier
This commit is contained in:
parent
9f383c0031
commit
7c3251fa26
|
@ -139,8 +139,6 @@ func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) {
|
|||
res, err := ctx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if len(res) == 4 && string(res) == "null" {
|
||||
return nil, ErrInvalidAccount(addr)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
|
|
@ -44,6 +44,9 @@ func queryAccount(ctx sdk.Context, req abci.RequestQuery, keeper AccountKeeper)
|
|||
}
|
||||
|
||||
account := keeper.GetAccount(ctx, params.Address)
|
||||
if account == nil {
|
||||
return nil, sdk.ErrUnknownAddress(fmt.Sprintf("account %s does not exist", params.Address))
|
||||
}
|
||||
|
||||
bz, err := codec.MarshalJSONIndent(keeper.cdc, account)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,19 +21,19 @@ func Test_queryAccount(t *testing.T) {
|
|||
|
||||
req.Data = input.cdc.MustMarshalJSON(NewQueryAccountParams([]byte("")))
|
||||
res, err = queryAccount(input.ctx, req, input.ak)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, res, []byte("null"))
|
||||
require.NotNil(t, err)
|
||||
require.Nil(t, res)
|
||||
|
||||
_, _, addr := keyPubAddr()
|
||||
req.Data = input.cdc.MustMarshalJSON(NewQueryAccountParams(addr))
|
||||
res, err = queryAccount(input.ctx, req, input.ak)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, res, []byte("null"))
|
||||
require.NotNil(t, err)
|
||||
require.Nil(t, res)
|
||||
|
||||
input.ak.SetAccount(input.ctx, input.ak.NewAccountWithAddress(input.ctx, addr))
|
||||
res, err = queryAccount(input.ctx, req, input.ak)
|
||||
require.Nil(t, err)
|
||||
require.NotEqual(t, res, []byte("null"))
|
||||
require.NotNil(t, res)
|
||||
|
||||
var account Account
|
||||
err2 := input.cdc.UnmarshalJSON(res, &account)
|
||||
|
|
Loading…
Reference in New Issue