github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/internal/test/factory/commit.go (about)

     1  package factory
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	tmproto "github.com/ari-anchor/sei-tendermint/proto/tendermint/types"
     8  	"github.com/ari-anchor/sei-tendermint/types"
     9  )
    10  
    11  func MakeExtendedCommit(ctx context.Context, blockID types.BlockID, height int64, round int32, voteSet *types.VoteSet, validators []types.PrivValidator, now time.Time) (*types.ExtendedCommit, error) {
    12  	// all sign
    13  	for i := 0; i < len(validators); i++ {
    14  		pubKey, err := validators[i].GetPubKey(ctx)
    15  		if err != nil {
    16  			return nil, err
    17  		}
    18  		vote := &types.Vote{
    19  			ValidatorAddress: pubKey.Address(),
    20  			ValidatorIndex:   int32(i),
    21  			Height:           height,
    22  			Round:            round,
    23  			Type:             tmproto.PrecommitType,
    24  			BlockID:          blockID,
    25  			Timestamp:        now,
    26  		}
    27  
    28  		v := vote.ToProto()
    29  
    30  		if err := validators[i].SignVote(ctx, voteSet.ChainID(), v); err != nil {
    31  			return nil, err
    32  		}
    33  		vote.Signature = v.Signature
    34  		vote.ExtensionSignature = v.ExtensionSignature
    35  		if _, err := voteSet.AddVote(vote); err != nil {
    36  			return nil, err
    37  		}
    38  	}
    39  
    40  	return voteSet.MakeExtendedCommit(), nil
    41  }