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
3 changes: 2 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
BREAKING CHANGES

* Gaia REST API (`gaiacli advanced rest-server`)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
* [\#3056](https://github.com/cosmos/cosmos-sdk/pull/3056) `generate_only` and `simulate` have moved from query arguments to POST requests body.
* [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-lite] [\#3056](https://github.com/cosmos/cosmos-sdk/pull/3056) `generate_only` and `simulate` have moved from query arguments to POST requests body.

* Gaia CLI (`gaiacli`)

Expand Down
16 changes: 14 additions & 2 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type CLIContext struct {
JSON bool
PrintResponse bool
Verifier tmlite.Verifier
DryRun bool
Simulate bool
GenerateOnly bool
fromAddress types.AccAddress
fromName string
Expand Down Expand Up @@ -85,7 +85,7 @@ func NewCLIContext() CLIContext {
JSON: viper.GetBool(client.FlagJson),
PrintResponse: viper.GetBool(client.FlagPrintResponse),
Verifier: verifier,
DryRun: viper.GetBool(client.FlagDryRun),
Simulate: viper.GetBool(client.FlagDryRun),
GenerateOnly: viper.GetBool(client.FlagGenerateOnly),
fromAddress: fromAddress,
fromName: fromName,
Expand Down Expand Up @@ -244,3 +244,15 @@ func (ctx CLIContext) WithVerifier(verifier tmlite.Verifier) CLIContext {
ctx.Verifier = verifier
return ctx
}

// WithGenerateOnly returns a copy of the context with updated GenerateOnly value
func (ctx CLIContext) WithGenerateOnly(generateOnly bool) CLIContext {
ctx.GenerateOnly = generateOnly
return ctx
}

// WithSimulation returns a copy of the context with updated Simulate value
func (ctx CLIContext) WithSimulation(simulate bool) CLIContext {
ctx.Simulate = simulate
return ctx
}
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, false, true)
res, body, _ := doSendWithGas(t, port, seed, name, "", addr, "simulate", 0, false, 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 @@ -1176,15 +1176,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 @@ -1197,11 +1191,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 @@ -1213,15 +1206,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 @@ -1231,14 +1218,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 @@ -1251,16 +1237,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 @@ -1270,14 +1250,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