bitbucket.org/number571/tendermint@v0.8.14/types/test_util.go (about) 1 package types 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 tmproto "bitbucket.org/number571/tendermint/proto/tendermint/types" 9 ) 10 11 func makeCommit(blockID BlockID, height int64, round int32, 12 voteSet *VoteSet, validators []PrivValidator, now time.Time) (*Commit, error) { 13 14 // all sign 15 for i := 0; i < len(validators); i++ { 16 pubKey, err := validators[i].GetPubKey(context.Background()) 17 if err != nil { 18 return nil, fmt.Errorf("can't get pubkey: %w", err) 19 } 20 vote := &Vote{ 21 ValidatorAddress: pubKey.Address(), 22 ValidatorIndex: int32(i), 23 Height: height, 24 Round: round, 25 Type: tmproto.PrecommitType, 26 BlockID: blockID, 27 Timestamp: now, 28 } 29 30 _, err = signAddVote(validators[i], vote, voteSet) 31 if err != nil { 32 return nil, err 33 } 34 } 35 36 return voteSet.MakeCommit(), nil 37 } 38 39 func signAddVote(privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) { 40 v := vote.ToProto() 41 err = privVal.SignVote(context.Background(), voteSet.ChainID(), v) 42 if err != nil { 43 return false, err 44 } 45 vote.Signature = v.Signature 46 return voteSet.AddVote(vote) 47 }