IncrementAccum upon RPC /validators; Sanity checks and comments (#2808)

This commit is contained in:
Jae Kwon
2018-11-21 10:43:02 +04:00
committed by Anton Kaliaev
parent 1610a05cbd
commit 42592d9ae0
6 changed files with 60 additions and 10 deletions
+4
View File
@@ -62,7 +62,11 @@ func (vals *ValidatorSet) CopyIncrementAccum(times int) *ValidatorSet {
// IncrementAccum increments accum of each validator and updates the
// proposer. Panics if validator set is empty.
// `times` must be positive.
func (vals *ValidatorSet) IncrementAccum(times int) {
if times <= 0 {
panic("Cannot call IncrementAccum with non-positive times")
}
// Add VotingPower * times to each validator and order into heap.
validatorsHeap := cmn.NewHeap()
+14 -1
View File
@@ -86,6 +86,19 @@ func TestCopy(t *testing.T) {
}
}
// Test that IncrementAccum requires positive times.
func TestIncrementAccumPositiveTimes(t *testing.T) {
vset := NewValidatorSet([]*Validator{
newValidator([]byte("foo"), 1000),
newValidator([]byte("bar"), 300),
newValidator([]byte("baz"), 330),
})
assert.Panics(t, func() { vset.IncrementAccum(-1) })
assert.Panics(t, func() { vset.IncrementAccum(0) })
vset.IncrementAccum(1)
}
func BenchmarkValidatorSetCopy(b *testing.B) {
b.StopTimer()
vset := NewValidatorSet([]*Validator{})
@@ -239,7 +252,7 @@ func TestProposerSelection3(t *testing.T) {
mod := (cmn.RandInt() % 5) + 1
if cmn.RandInt()%mod > 0 {
// sometimes its up to 5
times = cmn.RandInt() % 5
times = (cmn.RandInt() % 4) + 1
}
vset.IncrementAccum(times)