Adjust for redelegation and unbonding changes
This commit is contained in:
parent
73efc3c5d0
commit
206566f043
|
@ -433,7 +433,7 @@ func TestValidatorQuery(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBonding(t *testing.T) {
|
||||
addr, seed := CreateAddr(t, name1, pw, GetKeyBase(t))
|
||||
addr, _ := CreateAddr(t, name1, pw, GetKeyBase(t))
|
||||
|
||||
cleanup, valPubKeys, operAddrs, port := InitializeTestLCD(t, 2, []sdk.AccAddress{addr})
|
||||
defer cleanup()
|
||||
|
@ -445,7 +445,7 @@ func TestBonding(t *testing.T) {
|
|||
validator := getValidator(t, port, operAddrs[0])
|
||||
|
||||
// create bond TX
|
||||
resultTx := doDelegate(t, port, seed, name1, pw, addr, operAddrs[0], 60)
|
||||
resultTx := doDelegate(t, port, name1, pw, addr, operAddrs[0], 60)
|
||||
tests.WaitForHeight(resultTx.Height+1, port)
|
||||
|
||||
require.Equal(t, uint32(0), resultTx.CheckTx.Code)
|
||||
|
@ -485,7 +485,7 @@ func TestBonding(t *testing.T) {
|
|||
require.Equal(t, operAddrs[0], bondedValidator.OperatorAddr)
|
||||
|
||||
// testing unbonding
|
||||
resultTx = doBeginUnbonding(t, port, seed, name1, pw, addr, operAddrs[0], 30)
|
||||
resultTx = doBeginUnbonding(t, port, name1, pw, addr, operAddrs[0], 30)
|
||||
tests.WaitForHeight(resultTx.Height+1, port)
|
||||
|
||||
require.Equal(t, uint32(0), resultTx.CheckTx.Code)
|
||||
|
@ -508,7 +508,7 @@ func TestBonding(t *testing.T) {
|
|||
require.Equal(t, "30", unbonding.Balance.Amount.String())
|
||||
|
||||
// test redelegation
|
||||
resultTx = doBeginRedelegation(t, port, seed, name1, pw, addr, operAddrs[0], operAddrs[1], 30)
|
||||
resultTx = doBeginRedelegation(t, port, name1, pw, addr, operAddrs[0], operAddrs[1], 30)
|
||||
tests.WaitForHeight(resultTx.Height+1, port)
|
||||
|
||||
require.Equal(t, uint32(0), resultTx.CheckTx.Code)
|
||||
|
@ -670,7 +670,7 @@ func TestVote(t *testing.T) {
|
|||
require.Equal(t, sdk.ZeroDec(), tally.Yes, "tally should be 0 as the address is not bonded")
|
||||
|
||||
// create bond TX
|
||||
resultTx = doDelegate(t, port, seed, name1, pw, addr, operAddrs[0], 60)
|
||||
resultTx = doDelegate(t, port, name1, pw, addr, operAddrs[0], 60)
|
||||
tests.WaitForHeight(resultTx.Height+1, port)
|
||||
|
||||
// vote
|
||||
|
@ -814,4 +814,4 @@ func TestProposalsQuery(t *testing.T) {
|
|||
require.Len(t, votes, 2)
|
||||
require.True(t, addrs[0].String() == votes[0].Voter.String() || addrs[0].String() == votes[1].Voter.String())
|
||||
require.True(t, addrs[1].String() == votes[0].Voter.String() || addrs[1].String() == votes[1].Voter.String())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -647,14 +647,14 @@ type editDelegationsReq struct {
|
|||
}
|
||||
|
||||
// POST /stake/delegators/{delegatorAddr}/delegations Submit delegation
|
||||
func doDelegate(t *testing.T, port, seed, name, password string,
|
||||
func doDelegate(t *testing.T, port, name, password string,
|
||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
|
||||
acc := getAccount(t, port, delAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
sequence := acc.GetSequence()
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
ed := editDelegationsReq{
|
||||
ed := msgDelegationsInput{
|
||||
BaseReq: utils.BaseReq{
|
||||
Name: name,
|
||||
Password: password,
|
||||
|
@ -662,40 +662,36 @@ func doDelegate(t *testing.T, port, seed, name, password string,
|
|||
AccountNumber: accnum,
|
||||
Sequence: sequence,
|
||||
},
|
||||
Delegations: []msgDelegationsInput{msgDelegationsInput{
|
||||
DelegatorAddr: delAddr.String(),
|
||||
ValidatorAddr: valAddr.String(),
|
||||
Delegation: sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, amount),
|
||||
}},
|
||||
DelegatorAddr: delAddr,
|
||||
ValidatorAddr: valAddr,
|
||||
Delegation: sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, amount),
|
||||
}
|
||||
req, err := cdc.MarshalJSON(ed)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), req)
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr.String()), req)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var results []ctypes.ResultBroadcastTxCommit
|
||||
var results ctypes.ResultBroadcastTxCommit
|
||||
err = cdc.UnmarshalJSON([]byte(body), &results)
|
||||
require.Nil(t, err)
|
||||
|
||||
return results[0]
|
||||
return results
|
||||
}
|
||||
|
||||
type msgDelegationsInput struct {
|
||||
DelegatorAddr string `json:"delegator_addr"` // in bech32
|
||||
ValidatorAddr string `json:"validator_addr"` // in bech32
|
||||
Delegation sdk.Coin `json:"delegation"`
|
||||
BaseReq utils.BaseReq `json:"base_req"`
|
||||
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
|
||||
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
|
||||
Delegation sdk.Coin `json:"delegation"`
|
||||
}
|
||||
|
||||
// POST /stake/delegators/{delegatorAddr}/delegations Submit delegation
|
||||
func doBeginUnbonding(t *testing.T, port, seed, name, password string,
|
||||
func doBeginUnbonding(t *testing.T, port, name, password string,
|
||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
|
||||
acc := getAccount(t, port, delAddr)
|
||||
accnum := acc.GetAccountNumber()
|
||||
sequence := acc.GetSequence()
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
ed := editDelegationsReq{
|
||||
ed := msgBeginUnbondingInput{
|
||||
BaseReq: utils.BaseReq{
|
||||
Name: name,
|
||||
Password: password,
|
||||
|
@ -703,33 +699,32 @@ func doBeginUnbonding(t *testing.T, port, seed, name, password string,
|
|||
AccountNumber: accnum,
|
||||
Sequence: sequence,
|
||||
},
|
||||
BeginUnbondings: []msgBeginUnbondingInput{msgBeginUnbondingInput{
|
||||
DelegatorAddr: delAddr.String(),
|
||||
ValidatorAddr: valAddr.String(),
|
||||
SharesAmount: fmt.Sprintf("%d", amount),
|
||||
}},
|
||||
DelegatorAddr: delAddr,
|
||||
ValidatorAddr: valAddr,
|
||||
SharesAmount: sdk.NewDec(amount),
|
||||
}
|
||||
req, err := cdc.MarshalJSON(ed)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), req)
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/unbonding_delegations", delAddr), req)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var results []ctypes.ResultBroadcastTxCommit
|
||||
var results ctypes.ResultBroadcastTxCommit
|
||||
err = cdc.UnmarshalJSON([]byte(body), &results)
|
||||
require.Nil(t, err)
|
||||
|
||||
return results[0]
|
||||
return results
|
||||
}
|
||||
|
||||
type msgBeginUnbondingInput struct {
|
||||
DelegatorAddr string `json:"delegator_addr"` // in bech32
|
||||
ValidatorAddr string `json:"validator_addr"` // in bech32
|
||||
SharesAmount string `json:"shares"`
|
||||
BaseReq utils.BaseReq `json:"base_req"`
|
||||
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
|
||||
ValidatorAddr sdk.ValAddress `json:"validator_addr"` // in bech32
|
||||
SharesAmount sdk.Dec `json:"shares"`
|
||||
}
|
||||
|
||||
// POST /stake/delegators/{delegatorAddr}/delegations Submit delegation
|
||||
func doBeginRedelegation(t *testing.T, port, seed, name, password string,
|
||||
func doBeginRedelegation(t *testing.T, port, name, password string,
|
||||
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount int64) (resultTx ctypes.ResultBroadcastTxCommit) {
|
||||
|
||||
acc := getAccount(t, port, delAddr)
|
||||
|
@ -737,7 +732,7 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string,
|
|||
sequence := acc.GetSequence()
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
ed := editDelegationsReq{
|
||||
ed := msgBeginRedelegateInput{
|
||||
BaseReq: utils.BaseReq{
|
||||
Name: name,
|
||||
Password: password,
|
||||
|
@ -745,31 +740,30 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string,
|
|||
AccountNumber: accnum,
|
||||
Sequence: sequence,
|
||||
},
|
||||
BeginRedelegates: []msgBeginRedelegateInput{msgBeginRedelegateInput{
|
||||
DelegatorAddr: delAddr.String(),
|
||||
ValidatorSrcAddr: valSrcAddr.String(),
|
||||
ValidatorDstAddr: valDstAddr.String(),
|
||||
SharesAmount: fmt.Sprintf("%d", amount),
|
||||
}},
|
||||
DelegatorAddr: delAddr,
|
||||
ValidatorSrcAddr: valSrcAddr,
|
||||
ValidatorDstAddr: valDstAddr,
|
||||
SharesAmount: sdk.NewDec(amount),
|
||||
}
|
||||
req, err := cdc.MarshalJSON(ed)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/delegations", delAddr), req)
|
||||
res, body := Request(t, port, "POST", fmt.Sprintf("/stake/delegators/%s/redelegations", delAddr), req)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||
|
||||
var results []ctypes.ResultBroadcastTxCommit
|
||||
var results ctypes.ResultBroadcastTxCommit
|
||||
err = cdc.UnmarshalJSON([]byte(body), &results)
|
||||
require.Nil(t, err)
|
||||
|
||||
return results[0]
|
||||
return results
|
||||
}
|
||||
|
||||
type msgBeginRedelegateInput struct {
|
||||
DelegatorAddr string `json:"delegator_addr"` // in bech32
|
||||
ValidatorSrcAddr string `json:"validator_src_addr"` // in bech32
|
||||
ValidatorDstAddr string `json:"validator_dst_addr"` // in bech32
|
||||
SharesAmount string `json:"shares"`
|
||||
BaseReq utils.BaseReq `json:"base_req"`
|
||||
DelegatorAddr sdk.AccAddress `json:"delegator_addr"` // in bech32
|
||||
ValidatorSrcAddr sdk.ValAddress `json:"validator_src_addr"` // in bech32
|
||||
ValidatorDstAddr sdk.ValAddress `json:"validator_dst_addr"` // in bech32
|
||||
SharesAmount sdk.Dec `json:"shares"`
|
||||
}
|
||||
|
||||
// GET /stake/delegators/{delegatorAddr}/delegations Get all delegations from a delegator
|
||||
|
|
Loading…
Reference in New Issue