-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Unbonding, Redelegation #1119
Unbonding, Redelegation #1119
Changes from 72 commits
3d0e7ff
43a0ed9
a49f9cb
f972cab
752f084
5a77d7d
26681a8
8e677e8
43429ef
482a3c5
fd1eb5f
63a0dcc
7eaa715
3fac834
d69d179
0efb0a4
2153e0d
f6b9893
e460c06
8639f91
9ee70ea
bd41980
40ad0a5
4be5e41
03c6804
98dad7d
4601bd5
fc6ee07
ffc8cc4
6a5bc2d
436f32d
37190aa
ed7b90e
af4fd6e
1d7d4d4
d427af7
a0ac5e9
b72a219
8860fa3
24395fd
258834f
9ce6759
1ae48da
bc2e0d7
ad73cd1
60158d5
b1cb149
3cd8478
a3e04ce
782afbb
ad9da64
071d47b
5dc163c
6e2c66c
f004c6c
ceb8856
9f99a17
32b75c5
85c3639
177ab4c
3f4e528
40b9faf
a500931
c916f21
82f3529
d5ab2f3
b8571b6
2511ef1
a029cb9
9cddb06
7170bd9
74e0fb8
5329d73
1a945a2
ffaefec
0012a46
6f2c29b
637b275
4908504
34e46ac
f499b88
bcace44
de77006
791ad9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ import ( | |
func TestKeys(t *testing.T) { | ||
name, password := "test", "1234567890" | ||
addr, seed := CreateAddr(t, "test", password, GetKB(t)) | ||
cleanup, _, port := InitializeTestLCD(t, 2, []sdk.Address{addr}) | ||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr}) | ||
defer cleanup() | ||
|
||
// get seed | ||
|
@@ -218,7 +218,7 @@ func TestValidators(t *testing.T) { | |
func TestCoinSend(t *testing.T) { | ||
name, password := "test", "1234567890" | ||
addr, seed := CreateAddr(t, "test", password, GetKB(t)) | ||
cleanup, _, port := InitializeTestLCD(t, 2, []sdk.Address{addr}) | ||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr}) | ||
defer cleanup() | ||
|
||
bz, err := hex.DecodeString("8FA6AB57AD6870F6B5B2E57735F38F2F30E73CB6") | ||
|
@@ -260,7 +260,7 @@ func TestCoinSend(t *testing.T) { | |
func TestIBCTransfer(t *testing.T) { | ||
name, password := "test", "1234567890" | ||
addr, seed := CreateAddr(t, "test", password, GetKB(t)) | ||
cleanup, _, port := InitializeTestLCD(t, 2, []sdk.Address{addr}) | ||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr}) | ||
defer cleanup() | ||
|
||
acc := getAccount(t, port, addr) | ||
|
@@ -289,7 +289,7 @@ func TestIBCTransfer(t *testing.T) { | |
func TestTxs(t *testing.T) { | ||
name, password := "test", "1234567890" | ||
addr, seed := CreateAddr(t, "test", password, GetKB(t)) | ||
cleanup, _, port := InitializeTestLCD(t, 2, []sdk.Address{addr}) | ||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.Address{addr}) | ||
defer cleanup() | ||
|
||
// query wrong | ||
|
@@ -378,13 +378,13 @@ func TestValidatorsQuery(t *testing.T) { | |
func TestBonding(t *testing.T) { | ||
name, password, denom := "test", "1234567890", "steak" | ||
addr, seed := CreateAddr(t, "test", password, GetKB(t)) | ||
cleanup, pks, port := InitializeTestLCD(t, 2, []sdk.Address{addr}) | ||
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.Address{addr}) | ||
defer cleanup() | ||
|
||
validator1Owner := pks[0].Address() | ||
|
||
// create bond TX | ||
resultTx := doBond(t, port, seed, name, password, addr, validator1Owner) | ||
resultTx := doDelegate(t, port, seed, name, password, addr, validator1Owner) | ||
tests.WaitForHeight(resultTx.Height+1, port) | ||
|
||
// check if tx was committed | ||
|
@@ -405,7 +405,7 @@ func TestBonding(t *testing.T) { | |
// testing unbonding | ||
|
||
// create unbond TX | ||
resultTx = doUnbond(t, port, seed, name, password, addr, validator1Owner) | ||
resultTx = doBeginUnbonding(t, port, seed, name, password, addr, validator1Owner) | ||
tests.WaitForHeight(resultTx.Height+1, port) | ||
|
||
// query validator | ||
|
@@ -416,12 +416,13 @@ func TestBonding(t *testing.T) { | |
assert.Equal(t, uint32(0), resultTx.CheckTx.Code) | ||
assert.Equal(t, uint32(0), resultTx.DeliverTx.Code) | ||
|
||
// TODO fix shares fn in staking | ||
// should the sender should have not received any coins as the unbonding has only just begun | ||
// query sender | ||
//acc := getAccount(t, sendAddr) | ||
//coins := acc.GetCoins() | ||
//assert.Equal(t, int64(98), coins.AmountOf(coinDenom)) | ||
acc = getAccount(t, port, addr) | ||
coins = acc.GetCoins() | ||
assert.Equal(t, int64(40), coins.AmountOf("steak").Int64()) | ||
|
||
// TODO add redelegation, need more complex capabilities such to mock context and | ||
} | ||
|
||
func TestSubmitProposal(t *testing.T) { | ||
|
@@ -606,15 +607,15 @@ func getDelegation(t *testing.T, port string, delegatorAddr, validatorAddr sdk.A | |
validatorAddrBech := sdk.MustBech32ifyVal(validatorAddr) | ||
|
||
// get the account to get the sequence | ||
res, body := Request(t, port, "GET", "/stake/"+delegatorAddrBech+"/bonding_status/"+validatorAddrBech, nil) | ||
res, body := Request(t, port, "GET", "/stake/"+delegatorAddrBech+"/delegation/"+validatorAddrBech, nil) | ||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
var bond stake.Delegation | ||
err := cdc.UnmarshalJSON([]byte(body), &bond) | ||
require.Nil(t, err) | ||
return bond | ||
} | ||
|
||
func doBond(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) { | ||
func doDelegate(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) { | ||
// get the account to get the sequence | ||
acc := getAccount(t, port, delegatorAddr) | ||
accnum := acc.GetAccountNumber() | ||
|
@@ -630,14 +631,17 @@ func doBond(t *testing.T, port, seed, name, password string, delegatorAddr, vali | |
"account_number": %d, | ||
"sequence": %d, | ||
"gas": 10000, | ||
"delegate": [ | ||
"delegations": [ | ||
{ | ||
"delegator_addr": "%s", | ||
"validator_addr": "%s", | ||
"bond": { "denom": "%s", "amount": 60 } | ||
} | ||
], | ||
"unbond": [] | ||
"begin_unbondings": [], | ||
"complete_unbondings": [], | ||
"begin_redelegates": [], | ||
"complete_redelegates": [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added, using viper to receive in the test (which needs to be changed), I think that'll be my next PR, refactor out viper usage, pretty much the same as using global variables |
||
}`, name, password, accnum, sequence, delegatorAddrBech, validatorAddrBech, "steak")) | ||
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr) | ||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
|
@@ -649,7 +653,9 @@ func doBond(t *testing.T, port, seed, name, password string, delegatorAddr, vali | |
return results[0] | ||
} | ||
|
||
func doUnbond(t *testing.T, port, seed, name, password string, delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) { | ||
func doBeginUnbonding(t *testing.T, port, seed, name, password string, | ||
delegatorAddr, validatorAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) { | ||
|
||
// get the account to get the sequence | ||
acc := getAccount(t, port, delegatorAddr) | ||
accnum := acc.GetAccountNumber() | ||
|
@@ -665,14 +671,17 @@ func doUnbond(t *testing.T, port, seed, name, password string, delegatorAddr, va | |
"account_number": %d, | ||
"sequence": %d, | ||
"gas": 10000, | ||
"delegate": [], | ||
"unbond": [ | ||
"delegations": [], | ||
"begin_unbondings": [ | ||
{ | ||
"delegator_addr": "%s", | ||
"validator_addr": "%s", | ||
"shares": "30" | ||
} | ||
] | ||
], | ||
"complete_unbondings": [], | ||
"begin_redelegates": [], | ||
"complete_redelegates": [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
}`, name, password, accnum, sequence, delegatorAddrBech, validatorAddrBech)) | ||
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr) | ||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
|
@@ -684,6 +693,48 @@ func doUnbond(t *testing.T, port, seed, name, password string, delegatorAddr, va | |
return results[0] | ||
} | ||
|
||
func doBeginRedelegation(t *testing.T, port, seed, name, password string, | ||
delegatorAddr, validatorSrcAddr, validatorDstAddr sdk.Address) (resultTx ctypes.ResultBroadcastTxCommit) { | ||
|
||
// get the account to get the sequence | ||
acc := getAccount(t, port, delegatorAddr) | ||
accnum := acc.GetAccountNumber() | ||
sequence := acc.GetSequence() | ||
|
||
delegatorAddrBech := sdk.MustBech32ifyAcc(delegatorAddr) | ||
validatorSrcAddrBech := sdk.MustBech32ifyVal(validatorSrcAddr) | ||
validatorDstAddrBech := sdk.MustBech32ifyVal(validatorDstAddr) | ||
|
||
// send | ||
jsonStr := []byte(fmt.Sprintf(`{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here might be where you want to pass |
||
"name": "%s", | ||
"password": "%s", | ||
"account_number": %d, | ||
"sequence": %d, | ||
"gas": 10000, | ||
"delegations": [], | ||
"begin_unbondings": [], | ||
"complete_unbondings": [], | ||
"begin_redelegates": [ | ||
{ | ||
"delegator_addr": "%s", | ||
"validator_src_addr": "%s", | ||
"validator_dst_addr": "%s", | ||
"shares": "30" | ||
} | ||
], | ||
"complete_redelegates": [] | ||
}`, name, password, accnum, sequence, delegatorAddrBech, validatorSrcAddrBech, validatorDstAddrBech)) | ||
res, body := Request(t, port, "POST", "/stake/delegations", jsonStr) | ||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
|
||
var results []ctypes.ResultBroadcastTxCommit | ||
err := cdc.UnmarshalJSON([]byte(body), &results) | ||
require.Nil(t, err) | ||
|
||
return results[0] | ||
} | ||
|
||
func getValidators(t *testing.T, port string) []stakerest.StakeValidatorOutput { | ||
// get the account to get the sequence | ||
res, body := Request(t, port, "GET", "/stake/validators", nil) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that happen in this PR? Some of these changelog entries look unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah not sure how that got in there, removed the duplicate lines