From b5857da87780ccac8cd6c8e7d56bb19ebd8053b7 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 21 Dec 2017 02:20:32 -0500 Subject: [PATCH] forgot file --- types/test_util.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 types/test_util.go diff --git a/types/test_util.go b/types/test_util.go new file mode 100644 index 00000000..d13de04e --- /dev/null +++ b/types/test_util.go @@ -0,0 +1,37 @@ +package types + +import "time" + +func MakeCommit(blockID BlockID, height int64, round int, + voteSet *VoteSet, + validators []*PrivValidatorFS) (*Commit, error) { + + // all sign + for i := 0; i < len(validators); i++ { + + vote := &Vote{ + ValidatorAddress: validators[i].GetAddress(), + ValidatorIndex: i, + Height: height, + Round: round, + Type: VoteTypePrecommit, + BlockID: blockID, + Timestamp: time.Now().UTC(), + } + + _, err := signAddVote(validators[i], vote, voteSet) + if err != nil { + return nil, err + } + } + + return voteSet.MakeCommit(), nil +} + +func signAddVote(privVal *PrivValidatorFS, vote *Vote, voteSet *VoteSet) (signed bool, err error) { + vote.Signature, err = privVal.Signer.Sign(SignBytes(voteSet.ChainID(), vote)) + if err != nil { + return false, err + } + return voteSet.AddVote(vote) +}