Rebase, test fix

This commit is contained in:
Christopher Goes 2018-04-12 11:52:54 +02:00
parent 90d88114d9
commit 166711742e
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
2 changed files with 8 additions and 6 deletions

View File

@ -94,11 +94,13 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) {
// update the list ordered by voting power // update the list ordered by voting power
if oldFound { if oldFound {
// retain the old validator height, even though stake has changed
candidate.ValidatorHeight = oldCandidate.ValidatorHeight
store.Delete(GetValidatorKey(address, oldCandidate.Assets, oldCandidate.ValidatorHeight, k.cdc)) store.Delete(GetValidatorKey(address, oldCandidate.Assets, oldCandidate.ValidatorHeight, k.cdc))
} } else {
// update the validator block height // update the validator block height
candidate.ValidatorHeight = ctx.BlockHeight() candidate.ValidatorHeight = ctx.BlockHeight()
}
// update the candidate record // update the candidate record
bz, err = k.cdc.MarshalBinary(candidate) bz, err = k.cdc.MarshalBinary(candidate)

View File

@ -254,7 +254,7 @@ func TestGetValidators(t *testing.T) {
assert.Equal(t, candidates[4].Address, validators[0].Address, "%v", validators) assert.Equal(t, candidates[4].Address, validators[0].Address, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[1].Address, "%v", validators) assert.Equal(t, candidates[3].Address, validators[1].Address, "%v", validators)
assert.Equal(t, int64(0), validators[0].Height, "%v", validators) assert.Equal(t, int64(0), validators[0].Height, "%v", validators)
assert.Equal(t, int64(10), validators[1].Height, "%v", validators) assert.Equal(t, int64(0), validators[1].Height, "%v", validators)
// no change in voting power - no change in sort // no change in voting power - no change in sort
ctx = ctx.WithBlockHeight(20) ctx = ctx.WithBlockHeight(20)
@ -274,8 +274,8 @@ func TestGetValidators(t *testing.T) {
keeper.setCandidate(ctx, candidates[4]) keeper.setCandidate(ctx, candidates[4])
validators = keeper.GetValidators(ctx) validators = keeper.GetValidators(ctx)
require.Equal(t, len(validators), n, "%v", validators) require.Equal(t, len(validators), n, "%v", validators)
assert.Equal(t, candidates[3].Address, validators[0].Address, "%v", validators) assert.Equal(t, candidates[4].Address, validators[0].Address, "%v", validators)
assert.Equal(t, candidates[4].Address, validators[1].Address, "%v", validators) assert.Equal(t, candidates[3].Address, validators[1].Address, "%v", validators)
// reset assets / heights // reset assets / heights
candidates[3].Assets = sdk.NewRat(300) candidates[3].Assets = sdk.NewRat(300)