forked from sei-protocol/sei-tendermint
/
test_util.go
48 lines (41 loc) · 1.18 KB
/
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
40
41
42
43
44
45
46
47
48
package types
import (
"context"
"fmt"
"time"
tmproto "github.com/badrootd/sei-tendermint/proto/tendermint/types"
)
func makeExtCommit(ctx context.Context, blockID BlockID, height int64, round int32,
voteSet *VoteSet, validators []PrivValidator, now time.Time) (*ExtendedCommit, error) {
// all sign
for i := 0; i < len(validators); i++ {
pubKey, err := validators[i].GetPubKey(ctx)
if err != nil {
return nil, fmt.Errorf("can't get pubkey: %w", err)
}
vote := &Vote{
ValidatorAddress: pubKey.Address(),
ValidatorIndex: int32(i),
Height: height,
Round: round,
Type: tmproto.PrecommitType,
BlockID: blockID,
Timestamp: now,
}
_, err = signAddVote(ctx, validators[i], vote, voteSet)
if err != nil {
return nil, err
}
}
return voteSet.MakeExtendedCommit(), nil
}
func signAddVote(ctx context.Context, privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) {
v := vote.ToProto()
err = privVal.SignVote(ctx, voteSet.ChainID(), v)
if err != nil {
return false, err
}
vote.Signature = v.Signature
vote.ExtensionSignature = v.ExtensionSignature
return voteSet.AddVote(vote)
}