From 55602b9be669982b2ccdcafb79be9d703a5cb078 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 5 Mar 2017 15:05:36 -0500 Subject: [PATCH] failing ProposerSelection test --- types/validator_set_test.go | 49 ++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 9107e77e5..76a32f46c 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -1,23 +1,23 @@ package types import ( - . "github.com/tendermint/go-common" - "github.com/tendermint/go-crypto" - "bytes" "strings" "testing" + + cmn "github.com/tendermint/go-common" + "github.com/tendermint/go-crypto" ) func randPubKey() crypto.PubKeyEd25519 { var pubKey [32]byte - copy(pubKey[:], RandBytes(32)) + copy(pubKey[:], cmn.RandBytes(32)) return crypto.PubKeyEd25519(pubKey) } func randValidator_() *Validator { - val := NewValidator(randPubKey(), RandInt64()) - val.Accum = RandInt64() + val := NewValidator(randPubKey(), cmn.RandInt64()) + val.Accum = cmn.RandInt64() return val } @@ -138,6 +138,43 @@ func TestProposerSelection2(t *testing.T) { } } +func TestProposerSelection3(t *testing.T) { + vset := NewValidatorSet([]*Validator{ + newValidator([]byte("a"), 1), + newValidator([]byte("b"), 1), + newValidator([]byte("c"), 1), + newValidator([]byte("d"), 1), + }) + + proposerOrder := make([]*Validator, 4) + for i := 0; i < 4; i++ { + proposerOrder[i] = vset.Proposer() + vset.IncrementAccum(1) + } + + // i for the loop + // j for the times + // we should go in order for ever, despite occasional IncrementAccums with times > 1 + var i, j int + for ; i < 1000; i++ { + got := vset.Proposer().Address + expected := proposerOrder[j%4].Address + if !bytes.Equal(got, expected) { + t.Fatalf(cmn.Fmt("vset.Proposer (%X) does not match expected proposer (%X) for (%d, %d)", got, expected, i, j)) + } + + // times is usually 1 + times := 1 + if cmn.RandInt()%2 > 0 { + // sometimes its up to 5 + times = cmn.RandInt() % 5 + } + vset.IncrementAccum(times) + + j += times + } +} + func BenchmarkValidatorSetCopy(b *testing.B) { b.StopTimer() vset := NewValidatorSet([]*Validator{})