forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_util.go
39 lines (33 loc) · 891 Bytes
/
test_util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package types
import (
tmtime "github.com/tendermint/tendermint/types/time"
)
func MakeCommit(blockID BlockID, height int64, round int,
voteSet *VoteSet,
validators []PrivValidator) (*Commit, error) {
// all sign
for i := 0; i < len(validators); i++ {
addr := validators[i].GetPubKey().Address()
vote := &Vote{
ValidatorAddress: addr,
ValidatorIndex: i,
Height: height,
Round: round,
Type: PrecommitType,
BlockID: blockID,
Timestamp: tmtime.Now(),
}
_, err := signAddVote(validators[i], vote, voteSet)
if err != nil {
return nil, err
}
}
return voteSet.MakeCommit(), nil
}
func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) {
err = privVal.SignVote(voteSet.ChainID(), vote)
if err != nil {
return false, err
}
return voteSet.AddVote(vote)
}