From 152b3bd67b38042de90ea689688325120c2a383a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 20 Oct 2018 22:25:50 +0200 Subject: [PATCH 01/10] Split delegator summary endpoint --- client/lcd/lcd_test.go | 56 +++++++++++++++++-------- x/stake/client/rest/query.go | 32 +++++++++++--- x/stake/querier/queryable.go | 70 +++++++++++++++++++++++-------- x/stake/querier/queryable_test.go | 31 ++++++++++---- x/stake/stake.go | 12 ------ 5 files changed, 141 insertions(+), 60 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index d4d038016ea7..6d2eecdea50f 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -543,11 +543,9 @@ func TestBonding(t *testing.T) { bond := getDelegation(t, port, addr, operAddrs[0]) require.Equal(t, amt, bond.Shares) - summary := getDelegationSummary(t, port, addr) - - require.Len(t, summary.Delegations, 1, "Delegation summary holds all delegations") - require.Equal(t, amt, summary.Delegations[0].Shares) - require.Len(t, summary.UnbondingDelegations, 0, "Delegation summary holds all unbonding-delegations") + delegatorDels := getDelegatorDelegations(t, port, addr) + require.Len(t, delegatorDels, 1) + require.Equal(t, amt, delegatorDels[0].Shares) bondedValidators := getDelegatorValidators(t, port, addr) require.Len(t, bondedValidators, 1) @@ -575,11 +573,12 @@ func TestBonding(t *testing.T) { unbonding := getUndelegation(t, port, addr, operAddrs[0]) require.Equal(t, "60", unbonding.Balance.Amount.String()) - summary = getDelegationSummary(t, port, addr) + delegatorDels = getDelegatorDelegations(t, port, addr) + require.Len(t, delegatorDels, 0) - require.Len(t, summary.Delegations, 0, "Delegation summary holds all delegations") - require.Len(t, summary.UnbondingDelegations, 1, "Delegation summary holds all unbonding-delegations") - require.Equal(t, "60", summary.UnbondingDelegations[0].Balance.Amount.String()) + delegatorUbds := getDelegatorUnbondingDelegations(t, port, addr) + require.Len(t, delegatorUbds, 1) + require.Equal(t, "60", delegatorUbds[0].Balance.Amount.String()) bondedValidators = getDelegatorValidators(t, port, addr) require.Len(t, bondedValidators, 0, "There's no delegation as the user withdraw all funds") @@ -587,9 +586,8 @@ func TestBonding(t *testing.T) { // TODO Undonding status not currently implemented // require.Equal(t, sdk.Unbonding, bondedValidators[0].Status) - // TODO add redelegation, need more complex capabilities such to mock context and - // TODO check summary for redelegation - // assert.Len(t, summary.Redelegations, 1, "Delegation summary holds all redelegations") + delegatorReds := getDelegatorRedelegations(t, port, addr) + require.Len(t, delegatorReds, 0) // query txs txs := getBondingTxs(t, port, addr, "") @@ -981,16 +979,40 @@ func getUndelegation(t *testing.T, port string, delegatorAddr sdk.AccAddress, va return unbondings } -func getDelegationSummary(t *testing.T, port string, delegatorAddr sdk.AccAddress) stake.DelegationSummary { - res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s", delegatorAddr), nil) +func getDelegatorDelegations(t *testing.T, port string, delegatorAddr sdk.AccAddress) []stake.Delegation { + res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/delegations", delegatorAddr), nil) + require.Equal(t, http.StatusOK, res.StatusCode, body) + + var dels []stake.Delegation + + err := cdc.UnmarshalJSON([]byte(body), &dels) + require.Nil(t, err) + + return dels +} + +func getDelegatorUnbondingDelegations(t *testing.T, port string, delegatorAddr sdk.AccAddress) []stake.UnbondingDelegation { + res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/unbonding_delegations", delegatorAddr), nil) + require.Equal(t, http.StatusOK, res.StatusCode, body) + + var ubds []stake.UnbondingDelegation + + err := cdc.UnmarshalJSON([]byte(body), &ubds) + require.Nil(t, err) + + return ubds +} + +func getDelegatorRedelegations(t *testing.T, port string, delegatorAddr sdk.AccAddress) []stake.Redelegation { + res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/redelegations", delegatorAddr), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) - var summary stake.DelegationSummary + var reds []stake.Redelegation - err := cdc.UnmarshalJSON([]byte(body), &summary) + err := cdc.UnmarshalJSON([]byte(body), &reds) require.Nil(t, err) - return summary + return reds } func getBondingTxs(t *testing.T, port string, delegatorAddr sdk.AccAddress, query string) []tx.Info { diff --git a/x/stake/client/rest/query.go b/x/stake/client/rest/query.go index 0398119d8264..e9a894a5b691 100644 --- a/x/stake/client/rest/query.go +++ b/x/stake/client/rest/query.go @@ -19,10 +19,22 @@ const storeName = "stake" func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) { - // Get all delegations (delegation, undelegation and redelegation) from a delegator + // Get all delegations from a delegator r.HandleFunc( - "/stake/delegators/{delegatorAddr}", - delegatorHandlerFn(cliCtx, cdc), + "/stake/delegators/{delegatorAddr}/delegations", + delegatorDelegationsHandlerFn(cliCtx, cdc), + ).Methods("GET") + + // Get all unbonding delegations from a delegator + r.HandleFunc( + "/stake/delegators/{delegatorAddr}/unbonding_delegations", + delegatorUnbondingDelegationsHandlerFn(cliCtx, cdc), + ).Methods("GET") + + // Get all redelegations from a delegator + r.HandleFunc( + "/stake/delegators/{delegatorAddr}/redelegations", + delegatorRedelegationsHandlerFn(cliCtx, cdc), ).Methods("GET") // Get all staking txs (i.e msgs) from a delegator @@ -82,8 +94,18 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Co } // HTTP request handler to query a delegator delegations -func delegatorHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { - return queryDelegator(cliCtx, cdc, "custom/stake/delegator") +func delegatorDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { + return queryDelegator(cliCtx, cdc, "custom/stake/delegatorDelegations") +} + +// HTTP request handler to query a delegator unbonding delegations +func delegatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { + return queryDelegator(cliCtx, cdc, "custom/stake/delegatorUnbondingDelegations") +} + +// HTTP request handler to query a delegator redelegations +func delegatorRedelegationsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.HandlerFunc { + return queryDelegator(cliCtx, cdc, "custom/stake/delegatorRedelegations") } // HTTP request handler to query all staking txs (msgs) from a delegator diff --git a/x/stake/querier/queryable.go b/x/stake/querier/queryable.go index 7cf01d0d3f50..46adc68ec988 100644 --- a/x/stake/querier/queryable.go +++ b/x/stake/querier/queryable.go @@ -10,15 +10,17 @@ import ( // query endpoints supported by the staking Querier const ( - QueryValidators = "validators" - QueryValidator = "validator" - QueryDelegator = "delegator" - QueryDelegation = "delegation" - QueryUnbondingDelegation = "unbondingDelegation" - QueryDelegatorValidators = "delegatorValidators" - QueryDelegatorValidator = "delegatorValidator" - QueryPool = "pool" - QueryParameters = "parameters" + QueryValidators = "validators" + QueryValidator = "validator" + QueryDelegatorDelegations = "delegatorDelegations" + QueryDelegatorUnbondingDelegations = "delegatorUnbondingDelegations" + QueryDelegatorRedelegations = "delegatorRedelegations" + QueryDelegation = "delegation" + QueryUnbondingDelegation = "unbondingDelegation" + QueryDelegatorValidators = "delegatorValidators" + QueryDelegatorValidator = "delegatorValidator" + QueryPool = "pool" + QueryParameters = "parameters" ) // creates a querier for staking REST endpoints @@ -29,8 +31,12 @@ func NewQuerier(k keep.Keeper, cdc *codec.Codec) sdk.Querier { return queryValidators(ctx, cdc, k) case QueryValidator: return queryValidator(ctx, cdc, req, k) - case QueryDelegator: - return queryDelegator(ctx, cdc, req, k) + case QueryDelegatorDelegations: + return queryDelegatorDelegations(ctx, cdc, req, k) + case QueryDelegatorUnbondingDelegations: + return queryDelegatorUnbondingDelegations(ctx, cdc, req, k) + case QueryDelegatorRedelegations: + return queryDelegatorRedelegations(ctx, cdc, req, k) case QueryDelegation: return queryDelegation(ctx, cdc, req, k) case QueryUnbondingDelegation: @@ -102,23 +108,51 @@ func queryValidator(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k return res, nil } -func queryDelegator(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) { +func queryDelegatorDelegations(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) { var params QueryDelegatorParams + errRes := cdc.UnmarshalJSON(req.Data, ¶ms) if errRes != nil { return []byte{}, sdk.ErrUnknownAddress("") } + delegations := k.GetAllDelegatorDelegations(ctx, params.DelegatorAddr) + + res, errRes = codec.MarshalJSONIndent(cdc, delegations) + if errRes != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", errRes.Error())) + } + return res, nil +} + +func queryDelegatorUnbondingDelegations(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) { + var params QueryDelegatorParams + + errRes := cdc.UnmarshalJSON(req.Data, ¶ms) + if errRes != nil { + return []byte{}, sdk.ErrUnknownAddress("") + } + unbondingDelegations := k.GetAllUnbondingDelegations(ctx, params.DelegatorAddr) - redelegations := k.GetAllRedelegations(ctx, params.DelegatorAddr) - summary := types.DelegationSummary{ - Delegations: delegations, - UnbondingDelegations: unbondingDelegations, - Redelegations: redelegations, + res, errRes = codec.MarshalJSONIndent(cdc, unbondingDelegations) + if errRes != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", errRes.Error())) } + return res, nil +} + +func queryDelegatorRedelegations(ctx sdk.Context, cdc *codec.Codec, req abci.RequestQuery, k keep.Keeper) (res []byte, err sdk.Error) { + var params QueryDelegatorParams + + errRes := cdc.UnmarshalJSON(req.Data, ¶ms) + if errRes != nil { + return []byte{}, sdk.ErrUnknownAddress("") + } + + redelegations := k.GetAllRedelegations(ctx, params.DelegatorAddr) - res, errRes = codec.MarshalJSONIndent(cdc, summary) + res, errRes = codec.MarshalJSONIndent(cdc, redelegations) if errRes != nil { return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", errRes.Error())) } diff --git a/x/stake/querier/queryable_test.go b/x/stake/querier/queryable_test.go index 1d76da90d710..649f5ff59cee 100644 --- a/x/stake/querier/queryable_test.go +++ b/x/stake/querier/queryable_test.go @@ -241,6 +241,22 @@ func TestQueryDelegation(t *testing.T) { require.Equal(t, delegation, delegationRes) + // Query Delegator Delegations + + query = abci.RequestQuery{ + Path: "/custom/stake/delegatorDelegations", + Data: bz, + } + + res, err = queryDelegatorDelegations(ctx, cdc, query, keeper) + require.Nil(t, err) + + var delegatorDelegations []types.Delegation + errRes = cdc.UnmarshalJSON(res, &delegatorDelegations) + require.Nil(t, errRes) + require.Len(t, delegatorDelegations, 1) + require.Equal(t, delegation, delegatorDelegations[0]) + // error unknown request query.Data = bz[:len(bz)-1] @@ -273,25 +289,24 @@ func TestQueryDelegation(t *testing.T) { _, err = queryUnbondingDelegation(ctx, cdc, query, keeper) require.NotNil(t, err) - // Query Delegator Summary + // Query Delegator Delegations query = abci.RequestQuery{ - Path: "/custom/stake/delegator", + Path: "/custom/stake/delegatorUnbondingDelegations", Data: bz, } - res, err = queryDelegator(ctx, cdc, query, keeper) + res, err = queryDelegatorUnbondingDelegations(ctx, cdc, query, keeper) require.Nil(t, err) - var summary types.DelegationSummary - errRes = cdc.UnmarshalJSON(res, &summary) + var delegatorUbds []types.UnbondingDelegation + errRes = cdc.UnmarshalJSON(res, &delegatorUbds) require.Nil(t, errRes) - - require.Equal(t, unbond, summary.UnbondingDelegations[0]) + require.Equal(t, unbond, delegatorUbds[0]) // error unknown request query.Data = bz[:len(bz)-1] - _, err = queryDelegator(ctx, cdc, query, keeper) + _, err = queryDelegatorUnbondingDelegations(ctx, cdc, query, keeper) require.NotNil(t, err) } diff --git a/x/stake/stake.go b/x/stake/stake.go index c4aa547022d8..a7e2cda41d1a 100644 --- a/x/stake/stake.go +++ b/x/stake/stake.go @@ -84,18 +84,6 @@ var ( NewQuerier = querier.NewQuerier ) -const ( - QueryValidators = querier.QueryValidators - QueryValidator = querier.QueryValidator - QueryDelegator = querier.QueryDelegator - QueryDelegation = querier.QueryDelegation - QueryUnbondingDelegation = querier.QueryUnbondingDelegation - QueryDelegatorValidators = querier.QueryDelegatorValidators - QueryDelegatorValidator = querier.QueryDelegatorValidator - QueryPool = querier.QueryPool - QueryParameters = querier.QueryParameters -) - const ( DefaultCodespace = types.DefaultCodespace CodeInvalidValidator = types.CodeInvalidValidator From fea21ac44628148c707526e067ea2a9e8d4a033e Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 20 Oct 2018 22:28:23 +0200 Subject: [PATCH 02/10] PENDING --- PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PENDING.md b/PENDING.md index 3a92041c333a..27cf631d65f2 100644 --- a/PENDING.md +++ b/PENDING.md @@ -5,6 +5,7 @@ BREAKING CHANGES * Gaia REST API (`gaiacli advanced rest-server`) * [x/stake] Validator.Owner renamed to Validator.Operator * [\#595](https://github.com/cosmos/cosmos-sdk/issues/595) Connections to the REST server are now secured using Transport Layer Security by default. The --insecure flag is provided to switch back to insecure HTTP. + * [gaia-lite] [\#2258](https://github.com/cosmos/cosmos-sdk/issues/2258) Split `GET stake/delegators/{delegatorAddr}` into `GET stake/delegators/{delegatorAddr}/delegations`, `GET stake/delegators/{delegatorAddr}/unbonding_delegations` and `GET stake/delegators/{delegatorAddr}/redelegations` * Gaia CLI (`gaiacli`) * [x/stake] Validator.Owner renamed to Validator.Operator From debed9cd38a69f944004c416440b1b267bb1bfe9 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 20 Oct 2018 22:31:26 +0200 Subject: [PATCH 03/10] Fixed exported queriers --- x/stake/stake.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/stake/stake.go b/x/stake/stake.go index a7e2cda41d1a..495a0b037840 100644 --- a/x/stake/stake.go +++ b/x/stake/stake.go @@ -84,6 +84,20 @@ var ( NewQuerier = querier.NewQuerier ) +const ( + QueryValidators = querier.QueryValidators + QueryValidator = querier.QueryValidator + QueryDelegatorDelegations = querier.QueryDelegatorDelegations + QueryDelegatorUnbondingDelegations = querier.QueryDelegatorUnbondingDelegations + QueryDelegatorRedelegations = querier.QueryDelegatorRedelegations + QueryDelegation = querier.QueryDelegation + QueryUnbondingDelegation = querier.QueryUnbondingDelegation + QueryDelegatorValidators = querier.QueryDelegatorValidators + QueryDelegatorValidator = querier.QueryDelegatorValidator + QueryPool = querier.QueryPool + QueryParameters = querier.QueryParameters +) + const ( DefaultCodespace = types.DefaultCodespace CodeInvalidValidator = types.CodeInvalidValidator From 3af2a09c3dc7d709061da6f9574231d4d39cb633 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 20 Oct 2018 22:39:03 +0200 Subject: [PATCH 04/10] Delete Delegation --- x/stake/stake.go | 1 - x/stake/types/delegation.go | 7 ------- 2 files changed, 8 deletions(-) diff --git a/x/stake/stake.go b/x/stake/stake.go index 495a0b037840..7e0e2f1f16f3 100644 --- a/x/stake/stake.go +++ b/x/stake/stake.go @@ -14,7 +14,6 @@ type ( Description = types.Description Commission = types.Commission Delegation = types.Delegation - DelegationSummary = types.DelegationSummary UnbondingDelegation = types.UnbondingDelegation Redelegation = types.Redelegation Params = types.Params diff --git a/x/stake/types/delegation.go b/x/stake/types/delegation.go index 1b51e00acf19..3158b89fa54b 100644 --- a/x/stake/types/delegation.go +++ b/x/stake/types/delegation.go @@ -41,13 +41,6 @@ type delegationValue struct { Height int64 } -// aggregates of all delegations, unbondings and redelegations -type DelegationSummary struct { - Delegations []Delegation `json:"delegations"` - UnbondingDelegations []UnbondingDelegation `json:"unbonding_delegations"` - Redelegations []Redelegation `json:"redelegations"` -} - // return the delegation without fields contained within the key for the store func MustMarshalDelegation(cdc *codec.Codec, delegation Delegation) []byte { val := delegationValue{ From 77d7fb0ba5bfb2e5ab70b238ffd21c1389cf8322 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sat, 20 Oct 2018 22:42:22 +0200 Subject: [PATCH 05/10] add comment --- x/stake/querier/queryable.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/stake/querier/queryable.go b/x/stake/querier/queryable.go index 46adc68ec988..1aef2e2d185c 100644 --- a/x/stake/querier/queryable.go +++ b/x/stake/querier/queryable.go @@ -57,6 +57,9 @@ func NewQuerier(k keep.Keeper, cdc *codec.Codec) sdk.Querier { // defines the params for the following queries: // - 'custom/stake/delegator' +// - 'custom/stake/delegatorDelegations' +// - 'custom/stake/delegatorUnbondingDelegations' +// - 'custom/stake/delegatorRedelegations' // - 'custom/stake/delegatorValidators' type QueryDelegatorParams struct { DelegatorAddr sdk.AccAddress From 4ed4c99141a862a19195cc6a14fe54d1548aa702 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 22 Oct 2018 11:59:06 +0200 Subject: [PATCH 06/10] More redelegation unit tests --- x/stake/querier/queryable_test.go | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/x/stake/querier/queryable_test.go b/x/stake/querier/queryable_test.go index 6bc4417ce024..c8bd499b413f 100644 --- a/x/stake/querier/queryable_test.go +++ b/x/stake/querier/queryable_test.go @@ -316,3 +316,60 @@ func TestQueryDelegation(t *testing.T) { _, err = queryDelegatorUnbondingDelegations(ctx, cdc, query, keeper) require.NotNil(t, err) } + +func TestQueryRedelegations(t *testing.T) { + cdc := codec.New() + ctx, _, keeper := keep.CreateTestInput(t, false, 10000) + + // Create Validators and Delegation + val1 := types.NewValidator(addrVal1, pk1, types.Description{}) + val2 := types.NewValidator(addrVal2, pk2, types.Description{}) + keeper.SetValidator(ctx, val1) + keeper.SetValidator(ctx, val2) + + keeper.Delegate(ctx, addrAcc2, sdk.NewCoin("steak", sdk.NewInt(100)), val1, true) + keeper.ApplyAndReturnValidatorSetUpdates(ctx) + + keeper.BeginRedelegation(ctx, addrAcc2, val1.GetOperator(), val2.GetOperator(), sdk.NewDec(20)) + keeper.ApplyAndReturnValidatorSetUpdates(ctx) + + redelegation, found := keeper.GetRedelegation(ctx, addrAcc2, val1.OperatorAddr, val2.OperatorAddr) + require.True(t, found) + + // delegator redelegations + queryDelegatorParams := newTestDelegatorQuery(addrAcc2) + bz, errRes := cdc.MarshalJSON(queryDelegatorParams) + require.Nil(t, errRes) + + query := abci.RequestQuery{ + Path: "/custom/stake/delegatorRedelegations", + Data: bz, + } + + res, err := queryDelegatorRedelegations(ctx, cdc, query, keeper) + require.Nil(t, err) + + var redsRes []types.Redelegation + errRes = cdc.UnmarshalJSON(res, &redsRes) + require.Nil(t, errRes) + + require.Equal(t, redelegation, redsRes[0]) + + // validator redelegations + queryValidatorParams := newTestValidatorQuery(val1.GetOperator()) + bz, errRes = cdc.MarshalJSON(queryValidatorParams) + require.Nil(t, errRes) + + query = abci.RequestQuery{ + Path: "/custom/stake/validatorRedelegations", + Data: bz, + } + + res, err = queryValidatorRedelegations(ctx, cdc, query, keeper) + require.Nil(t, err) + + errRes = cdc.UnmarshalJSON(res, &redsRes) + require.Nil(t, errRes) + + require.Equal(t, redelegation, redsRes[0]) +} From 06d0198392d690a3085c594304205edb5b1b72c8 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 22 Oct 2018 12:03:10 +0200 Subject: [PATCH 07/10] Added querier tests --- x/stake/querier/queryable_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/x/stake/querier/queryable_test.go b/x/stake/querier/queryable_test.go index c8bd499b413f..973e2376ff9c 100644 --- a/x/stake/querier/queryable_test.go +++ b/x/stake/querier/queryable_test.go @@ -72,8 +72,8 @@ func TestNewQuerier(t *testing.T) { _, err = querier(ctx, []string{"parameters"}, query) require.Nil(t, err) - queryParams := newTestValidatorQuery(addrVal1) - bz, errRes := cdc.MarshalJSON(queryParams) + queryValParams := newTestValidatorQuery(addrVal1) + bz, errRes := cdc.MarshalJSON(queryValParams) require.Nil(t, errRes) query.Path = "/custom/stake/validator" @@ -87,6 +87,25 @@ func TestNewQuerier(t *testing.T) { _, err = querier(ctx, []string{"validatorRedelegations"}, query) require.Nil(t, err) + + queryDelParams := newTestDelegatorQuery(addrAcc2) + bz, errRes = cdc.MarshalJSON(queryDelParams) + require.Nil(t, errRes) + + query.Path = "/custom/stake/validator" + query.Data = bz + + _, err = querier(ctx, []string{"delegatorDelegations"}, query) + require.Nil(t, err) + + _, err = querier(ctx, []string{"delegatorUnbondingDelegations"}, query) + require.Nil(t, err) + + _, err = querier(ctx, []string{"delegatorRedelegations"}, query) + require.Nil(t, err) + + _, err = querier(ctx, []string{"delegatorValidators"}, query) + require.Nil(t, err) } func TestQueryParametersPool(t *testing.T) { From 8415d8056fe5a20a229f924f3347b08f6378896b Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 22 Oct 2018 12:12:05 +0200 Subject: [PATCH 08/10] export validator unds and reds queriers --- x/stake/stake.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x/stake/stake.go b/x/stake/stake.go index 7e0e2f1f16f3..179f8b72119f 100644 --- a/x/stake/stake.go +++ b/x/stake/stake.go @@ -86,11 +86,13 @@ var ( const ( QueryValidators = querier.QueryValidators QueryValidator = querier.QueryValidator + QueryValidatorUnbondingDelegations = querier.QueryValidatorUnbondingDelegations + QueryValidatorRedelegations = querier.QueryValidatorRedelegations + QueryDelegation = querier.QueryDelegation + QueryUnbondingDelegation = querier.QueryUnbondingDelegation QueryDelegatorDelegations = querier.QueryDelegatorDelegations QueryDelegatorUnbondingDelegations = querier.QueryDelegatorUnbondingDelegations QueryDelegatorRedelegations = querier.QueryDelegatorRedelegations - QueryDelegation = querier.QueryDelegation - QueryUnbondingDelegation = querier.QueryUnbondingDelegation QueryDelegatorValidators = querier.QueryDelegatorValidators QueryDelegatorValidator = querier.QueryDelegatorValidator QueryPool = querier.QueryPool From 301fdf4a405b25b8a42f4ea77801af95ddd4e945 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 22 Oct 2018 14:21:53 +0200 Subject: [PATCH 09/10] test cleanup --- client/lcd/lcd_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 5f8e4bc6f5c9..d25dedee7742 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -555,8 +555,6 @@ func TestBonding(t *testing.T) { require.Equal(t, operAddrs[0], bondedValidator.OperatorAddr) // testing unbonding - - // create unbond TX resultTx = doBeginUnbonding(t, port, seed, name, password, addr, operAddrs[0], 30) tests.WaitForHeight(resultTx.Height+1, port) @@ -578,6 +576,7 @@ func TestBonding(t *testing.T) { require.Equal(t, uint32(0), resultTx.CheckTx.Code) require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + // query delegations, unbondings and redelegations from validator and delegator delegatorDels = getDelegatorDelegations(t, port, addr) require.Len(t, delegatorDels, 1) require.Equal(t, "30.0000000000", delegatorDels[0].GetShares().String()) @@ -598,9 +597,6 @@ func TestBonding(t *testing.T) { require.Len(t, validatorReds, 1) require.Equal(t, "30", validatorReds[0].Balance.Amount.String()) - bondedValidators = getDelegatorValidators(t, port, addr) - require.Len(t, bondedValidators, 1, "There's a delegation as the user only withdraw half of the funds") - // TODO Undonding status not currently implemented // require.Equal(t, sdk.Unbonding, bondedValidators[0].Status) From 64f2235f593b8b4316fbb0f5a378f7db1fc93337 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Mon, 22 Oct 2018 22:55:47 +0200 Subject: [PATCH 10/10] Delete comment --- x/stake/querier/queryable.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/stake/querier/queryable.go b/x/stake/querier/queryable.go index d3d15bc8f67f..bacc8d6aecc4 100644 --- a/x/stake/querier/queryable.go +++ b/x/stake/querier/queryable.go @@ -63,7 +63,6 @@ func NewQuerier(k keep.Keeper, cdc *codec.Codec) sdk.Querier { } // defines the params for the following queries: -// - 'custom/stake/delegator' // - 'custom/stake/delegatorDelegations' // - 'custom/stake/delegatorUnbondingDelegations' // - 'custom/stake/delegatorRedelegations'