From 166711742e0694d7e8fa24e2fed89a9f8769b6a7 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 12 Apr 2018 11:52:54 +0200 Subject: [PATCH] Rebase, test fix --- x/stake/keeper.go | 8 +++++--- x/stake/keeper_test.go | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x/stake/keeper.go b/x/stake/keeper.go index f6aa01c63..8cce331cf 100644 --- a/x/stake/keeper.go +++ b/x/stake/keeper.go @@ -94,12 +94,14 @@ func (k Keeper) setCandidate(ctx sdk.Context, candidate Candidate) { // update the list ordered by voting power 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)) + } else { + // update the validator block height + candidate.ValidatorHeight = ctx.BlockHeight() } - // update the validator block height - candidate.ValidatorHeight = ctx.BlockHeight() - // update the candidate record bz, err = k.cdc.MarshalBinary(candidate) if err != nil { diff --git a/x/stake/keeper_test.go b/x/stake/keeper_test.go index baaa2ec8c..85b2d72ba 100644 --- a/x/stake/keeper_test.go +++ b/x/stake/keeper_test.go @@ -254,7 +254,7 @@ func TestGetValidators(t *testing.T) { 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, 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 ctx = ctx.WithBlockHeight(20) @@ -274,8 +274,8 @@ func TestGetValidators(t *testing.T) { keeper.setCandidate(ctx, candidates[4]) validators = keeper.GetValidators(ctx) 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[1].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) // reset assets / heights candidates[3].Assets = sdk.NewRat(300)