github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/internal/test/vote.go (about)

     1  package test
     2  
     3  import (
     4  	"time"
     5  
     6  	cmtproto "github.com/badrootd/nibiru-cometbft/proto/tendermint/types"
     7  	"github.com/badrootd/nibiru-cometbft/types"
     8  )
     9  
    10  func MakeVote(
    11  	val types.PrivValidator,
    12  	chainID string,
    13  	valIndex int32,
    14  	height int64,
    15  	round int32,
    16  	step int,
    17  	blockID types.BlockID,
    18  	time time.Time,
    19  ) (*types.Vote, error) {
    20  	pubKey, err := val.GetPubKey()
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  
    25  	v := &types.Vote{
    26  		ValidatorAddress: pubKey.Address(),
    27  		ValidatorIndex:   valIndex,
    28  		Height:           height,
    29  		Round:            round,
    30  		Type:             cmtproto.SignedMsgType(step),
    31  		BlockID:          blockID,
    32  		Timestamp:        time,
    33  	}
    34  
    35  	vpb := v.ToProto()
    36  	if err := val.SignVote(chainID, vpb); err != nil {
    37  		return nil, err
    38  	}
    39  
    40  	v.Signature = vpb.Signature
    41  	return v, nil
    42  }