2014-10-14 13:11:54 -07:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
2014-10-15 20:15:38 -07:00
|
|
|
. "github.com/tendermint/tendermint/blocks"
|
2014-10-14 13:11:54 -07:00
|
|
|
. "github.com/tendermint/tendermint/state"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func makeValidator(id uint64, votingPower uint64) (*Validator, *PrivAccount) {
|
|
|
|
privAccount := GenPrivAccount()
|
|
|
|
privAccount.Id = id
|
|
|
|
return &Validator{
|
|
|
|
Account: privAccount.Account,
|
|
|
|
VotingPower: votingPower,
|
|
|
|
}, privAccount
|
|
|
|
}
|
|
|
|
|
2014-10-15 20:15:38 -07:00
|
|
|
func makeVoteSet(numValidators int, votingPower uint64) (*VoteSet, *ValidatorSet, []*PrivAccount) {
|
|
|
|
vals := make([]*Validator, numValidators)
|
|
|
|
privAccounts := make([]*PrivAccount, numValidators)
|
|
|
|
for i := 0; i < numValidators; i++ {
|
|
|
|
val, privAccount := makeValidator(uint64(i), votingPower)
|
|
|
|
vals[i] = val
|
|
|
|
privAccounts[i] = privAccount
|
|
|
|
}
|
|
|
|
valSet := NewValidatorSet(vals)
|
|
|
|
return NewVoteSet(0, 0, VoteTypeBare, valSet), valSet, privAccounts
|
|
|
|
}
|
|
|
|
|
2014-10-14 13:11:54 -07:00
|
|
|
func TestAddVote(t *testing.T) {
|
2014-10-15 20:15:38 -07:00
|
|
|
voteSet, valSet, privAccounts := makeVoteSet(10, 1)
|
|
|
|
vote := &Vote{Height: 0, Round: 0, Type: VoteTypeBare, BlockHash: nil}
|
|
|
|
|
|
|
|
t.Logf(">> %v", voteSet)
|
|
|
|
t.Logf(">> %v", valSet)
|
|
|
|
t.Logf(">> %v", privAccounts)
|
|
|
|
|
|
|
|
privAccounts[0].Sign(vote)
|
|
|
|
voteSet.Add(vote)
|
|
|
|
|
|
|
|
t.Logf(">> %v", voteSet)
|
|
|
|
t.Logf(">> %v", valSet)
|
|
|
|
t.Logf(">> %v", privAccounts)
|
|
|
|
|
2014-10-14 13:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test2_3Majority(t *testing.T) {
|
|
|
|
// XXX
|
|
|
|
}
|