github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/types/test_util.go (about)

     1  package types
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"time"
     7  
     8  	tmproto "github.com/ari-anchor/sei-tendermint/proto/tendermint/types"
     9  )
    10  
    11  func makeExtCommit(ctx context.Context, blockID BlockID, height int64, round int32,
    12  	voteSet *VoteSet, validators []PrivValidator, now time.Time) (*ExtendedCommit, error) {
    13  
    14  	// all sign
    15  	for i := 0; i < len(validators); i++ {
    16  		pubKey, err := validators[i].GetPubKey(ctx)
    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(ctx, validators[i], vote, voteSet)
    31  		if err != nil {
    32  			return nil, err
    33  		}
    34  	}
    35  
    36  	return voteSet.MakeExtendedCommit(), nil
    37  }
    38  
    39  func signAddVote(ctx context.Context, privVal PrivValidator, vote *Vote, voteSet *VoteSet) (signed bool, err error) {
    40  	v := vote.ToProto()
    41  	err = privVal.SignVote(ctx, voteSet.ChainID(), v)
    42  	if err != nil {
    43  		return false, err
    44  	}
    45  	vote.Signature = v.Signature
    46  	vote.ExtensionSignature = v.ExtensionSignature
    47  	return voteSet.AddVote(vote)
    48  }