generated privValidator for testing uses tmp files

PrivValidator.Sign*() and .Save() lock on a mutex
This commit is contained in:
Jae Kwon
2014-12-22 18:49:37 -08:00
parent 383335d93c
commit 403d24a4b2
5 changed files with 43 additions and 29 deletions
+7 -7
View File
@@ -23,7 +23,7 @@ func signAddPOLVoteSignature(val *state.PrivValidator, valSet *state.ValidatorSe
func TestVerifyVotes(t *testing.T) {
height, round := uint(1), uint(0)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with -2/3 votes.
blockHash := RandBytes(32)
@@ -54,7 +54,7 @@ func TestVerifyVotes(t *testing.T) {
func TestVerifyInvalidVote(t *testing.T) {
height, round := uint(1), uint(0)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with +2/3 votes with the wrong signature.
blockHash := RandBytes(32)
@@ -78,7 +78,7 @@ func TestVerifyInvalidVote(t *testing.T) {
func TestVerifyCommits(t *testing.T) {
height, round := uint(1), uint(2)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with +2/3 votes.
blockHash := RandBytes(32)
@@ -101,7 +101,7 @@ func TestVerifyCommits(t *testing.T) {
func TestVerifyInvalidCommits(t *testing.T) {
height, round := uint(1), uint(2)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with +2/3 votes with the wrong signature.
blockHash := RandBytes(32)
@@ -125,7 +125,7 @@ func TestVerifyInvalidCommits(t *testing.T) {
func TestVerifyInvalidCommitRounds(t *testing.T) {
height, round := uint(1), uint(2)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with +2/3 commits for the current round.
blockHash := RandBytes(32)
@@ -148,7 +148,7 @@ func TestVerifyInvalidCommitRounds(t *testing.T) {
func TestVerifyInvalidCommitRounds2(t *testing.T) {
height, round := uint(1), uint(2)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with +2/3 commits for future round.
blockHash := RandBytes(32)
@@ -172,7 +172,7 @@ func TestVerifyInvalidCommitRounds2(t *testing.T) {
func TestReadWrite(t *testing.T) {
height, round := uint(1), uint(2)
_, valSet, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
_, valSet, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// Make a POL with +2/3 votes.
blockHash := RandBytes(32)
+4 -4
View File
@@ -8,7 +8,7 @@ import (
)
func TestSetupRound(t *testing.T) {
cs, privValidators := makeConsensusState()
cs, privValidators := randConsensusState()
val0 := privValidators[0]
// Add a vote, precommit, and commit by val0.
@@ -50,7 +50,7 @@ func TestSetupRound(t *testing.T) {
}
func TestRunActionProposeNoPrivValidator(t *testing.T) {
cs, _ := makeConsensusState()
cs, _ := randConsensusState()
cs.RunActionPropose(1, 0)
rs := cs.GetRoundState()
if rs.Proposal != nil {
@@ -59,7 +59,7 @@ func TestRunActionProposeNoPrivValidator(t *testing.T) {
}
func TestRunActionPropose(t *testing.T) {
cs, privValidators := makeConsensusState()
cs, privValidators := randConsensusState()
val0 := privValidators[0]
cs.SetPrivValidator(val0)
@@ -92,7 +92,7 @@ func checkRoundState(t *testing.T, rs *RoundState,
}
func TestRunActionPrecommitCommitFinalize(t *testing.T) {
cs, privValidators := makeConsensusState()
cs, privValidators := randConsensusState()
val0 := privValidators[0]
cs.SetPrivValidator(val0)
+9 -9
View File
@@ -11,24 +11,24 @@ import (
// Common test methods
func makeValidator(votingPower uint64) (*state.Validator, *state.PrivValidator) {
privValidator := state.GenPrivValidator()
func makeValidator(valInfo *state.ValidatorInfo) *state.Validator {
return &state.Validator{
Address: privValidator.Address,
PubKey: privValidator.PubKey,
Address: valInfo.Address,
PubKey: valInfo.PubKey,
BondHeight: 0,
UnbondHeight: 0,
LastCommitHeight: 0,
VotingPower: votingPower,
VotingPower: valInfo.FirstBondAmount,
Accum: 0,
}, privValidator
}
}
func makeVoteSet(height uint, round uint, type_ byte, numValidators int, votingPower uint64) (*VoteSet, *state.ValidatorSet, []*state.PrivValidator) {
func randVoteSet(height uint, round uint, type_ byte, numValidators int, votingPower uint64) (*VoteSet, *state.ValidatorSet, []*state.PrivValidator) {
vals := make([]*state.Validator, numValidators)
privValidators := make([]*state.PrivValidator, numValidators)
for i := 0; i < numValidators; i++ {
val, privValidator := makeValidator(votingPower)
valInfo, privValidator := state.RandValidator(false, votingPower)
val := makeValidator(valInfo)
vals[i] = val
privValidators[i] = privValidator
}
@@ -37,7 +37,7 @@ func makeVoteSet(height uint, round uint, type_ byte, numValidators int, votingP
return NewVoteSet(height, round, type_, valSet), valSet, privValidators
}
func makeConsensusState() (*ConsensusState, []*state.PrivValidator) {
func randConsensusState() (*ConsensusState, []*state.PrivValidator) {
state, _, privValidators := state.RandGenesisState(20, false, 1000, 10, false, 1000)
blockStore := NewBlockStore(db_.NewMemDB())
mempool := mempool_.NewMempool(state)
+6 -6
View File
@@ -14,7 +14,7 @@ import (
func TestAddVote(t *testing.T) {
height, round := uint(1), uint(0)
voteSet, _, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
val0 := privValidators[0]
// t.Logf(">> %v", voteSet)
@@ -48,7 +48,7 @@ func TestAddVote(t *testing.T) {
func Test2_3Majority(t *testing.T) {
height, round := uint(1), uint(0)
voteSet, _, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// 6 out of 10 voted for nil.
voteProto := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
@@ -89,7 +89,7 @@ func Test2_3Majority(t *testing.T) {
func Test2_3MajorityRedux(t *testing.T) {
height, round := uint(1), uint(0)
voteSet, _, privValidators := makeVoteSet(height, round, VoteTypePrevote, 100, 1)
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 100, 1)
blockHash := CRandBytes(32)
blockPartsTotal := uint(123)
@@ -165,7 +165,7 @@ func Test2_3MajorityRedux(t *testing.T) {
func TestBadVotes(t *testing.T) {
height, round := uint(1), uint(0)
voteSet, _, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// val0 votes for nil.
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
@@ -210,7 +210,7 @@ func TestBadVotes(t *testing.T) {
func TestAddCommitsToPrevoteVotes(t *testing.T) {
height, round := uint(2), uint(5)
voteSet, _, privValidators := makeVoteSet(height, round, VoteTypePrevote, 10, 1)
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
// val0, val1, val2, val3, val4, val5 vote for nil.
voteProto := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
@@ -274,7 +274,7 @@ func TestAddCommitsToPrevoteVotes(t *testing.T) {
func TestMakeValidation(t *testing.T) {
height, round := uint(1), uint(0)
voteSet, _, privValidators := makeVoteSet(height, round, VoteTypeCommit, 10, 1)
voteSet, _, privValidators := randVoteSet(height, round, VoteTypeCommit, 10, 1)
blockHash, blockParts := CRandBytes(32), PartSetHeader{123, CRandBytes(32)}
// 6 out of 10 voted for some block.