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

R4R: split POST delegations endpoint #2997

Merged
merged 17 commits into from
Dec 11, 2018
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BREAKING CHANGES

* Gaia REST API (`gaiacli advanced rest-server`)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
* [gaia-lite] [\#2191](https://github.com/cosmos/cosmos-sdk/issues/2191) Split `POST /stake/delegators/{delegatorAddr}/delegations` into `POST /stake/delegators/{delegatorAddr}/delegations`, `POST /stake/delegators/{delegatorAddr}/unbonding_delegations` and `POST /stake/delegators/{delegatorAddr}/redelegations`

* Gaia CLI (`gaiacli`)
* [cli] [\#2595](https://github.com/cosmos/cosmos-sdk/issues/2595) Remove `keys new` in favor of `keys add` incorporating existing functionality with addition of key recovery functionality.
Expand Down
59 changes: 19 additions & 40 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {
acc := getAccount(t, port, addr)

// generate TX
res, body, _ := doSendWithGas(t, port, seed, name, password, addr, "simulate", 0, "?generate_only=true")
res, body, _ := doSendWithGas(t, port, seed, name, "", addr, "simulate", 0, "?generate_only=true")
require.Equal(t, http.StatusOK, res.StatusCode, body)
var msg auth.StdTx
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &msg))
Expand Down Expand Up @@ -1172,15 +1172,9 @@ func doDelegate(t *testing.T, port, seed, name, password string,
chainID := viper.GetString(client.FlagChainID)

jsonStr := []byte(fmt.Sprintf(`{
"delegations": [
{
"delegator_addr": "%s",
"validator_addr": "%s",
"delegation": { "denom": "%s", "amount": "%d" }
}
],
"begin_unbondings": [],
"begin_redelegates": [],
"delegator_addr": "%s",
"validator_addr": "%s",
"delegation": { "denom": "%s", "amount": "%d" },
"base_req": {
"name": "%s",
"password": "%s",
Expand All @@ -1193,11 +1187,10 @@ func doDelegate(t *testing.T, port, seed, name, password string,
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), jsonStr)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var results []ctypes.ResultBroadcastTxCommit
err := cdc.UnmarshalJSON([]byte(body), &results)
err := cdc.UnmarshalJSON([]byte(body), &resultTx)
require.Nil(t, err)

return results[0]
return
}

func doBeginUnbonding(t *testing.T, port, seed, name, password string,
Expand All @@ -1209,15 +1202,9 @@ func doBeginUnbonding(t *testing.T, port, seed, name, password string,
chainID := viper.GetString(client.FlagChainID)

jsonStr := []byte(fmt.Sprintf(`{
"delegations": [],
"begin_unbondings": [
{
"delegator_addr": "%s",
"validator_addr": "%s",
"shares": "%d"
}
],
"begin_redelegates": [],
"delegator_addr": "%s",
"validator_addr": "%s",
"shares": "%d",
"base_req": {
"name": "%s",
"password": "%s",
Expand All @@ -1227,14 +1214,13 @@ func doBeginUnbonding(t *testing.T, port, seed, name, password string,
}
}`, delAddr, valAddr, amount, name, password, chainID, accnum, sequence))

res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), jsonStr)
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/unbonding_delegations", delAddr), jsonStr)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var results []ctypes.ResultBroadcastTxCommit
err := cdc.UnmarshalJSON([]byte(body), &results)
err := cdc.UnmarshalJSON([]byte(body), &resultTx)
require.Nil(t, err)

return results[0]
return
}

func doBeginRedelegation(t *testing.T, port, seed, name, password string,
Expand All @@ -1247,16 +1233,10 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string,
chainID := viper.GetString(client.FlagChainID)

jsonStr := []byte(fmt.Sprintf(`{
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
"delegations": [],
"begin_unbondings": [],
"begin_redelegates": [
{
"delegator_addr": "%s",
"validator_src_addr": "%s",
"validator_dst_addr": "%s",
"shares": "%d"
}
],
"delegator_addr": "%s",
"validator_src_addr": "%s",
"validator_dst_addr": "%s",
"shares": "%d",
"base_req": {
"name": "%s",
"password": "%s",
Expand All @@ -1266,14 +1246,13 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string,
}
}`, delAddr, valSrcAddr, valDstAddr, amount, name, password, chainID, accnum, sequence))

res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), jsonStr)
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/redelegations", delAddr), jsonStr)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var results []ctypes.ResultBroadcastTxCommit
err := cdc.UnmarshalJSON([]byte(body), &results)
err := cdc.UnmarshalJSON([]byte(body), &resultTx)
require.Nil(t, err)

return results[0]
return
}

func getValidators(t *testing.T, port string) []stake.Validator {
Expand Down
Loading