github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/helper/quorum_certificate.go (about)

     1  package helper
     2  
     3  import (
     4  	"math/rand"
     5  
     6  	"github.com/koko1123/flow-go-1/consensus/hotstuff/model"
     7  	"github.com/koko1123/flow-go-1/model/flow"
     8  	"github.com/koko1123/flow-go-1/utils/unittest"
     9  )
    10  
    11  func MakeQC(options ...func(*flow.QuorumCertificate)) *flow.QuorumCertificate {
    12  	qc := flow.QuorumCertificate{
    13  		View:          rand.Uint64(),
    14  		BlockID:       unittest.IdentifierFixture(),
    15  		SignerIndices: unittest.SignerIndicesFixture(3),
    16  		SigData:       unittest.SignatureFixture(),
    17  	}
    18  	for _, option := range options {
    19  		option(&qc)
    20  	}
    21  	return &qc
    22  }
    23  
    24  func WithQCBlock(block *model.Block) func(*flow.QuorumCertificate) {
    25  	return func(qc *flow.QuorumCertificate) {
    26  		qc.View = block.View
    27  		qc.BlockID = block.BlockID
    28  	}
    29  }
    30  
    31  func WithQCSigners(signerIndices []byte) func(*flow.QuorumCertificate) {
    32  	return func(qc *flow.QuorumCertificate) {
    33  		qc.SignerIndices = signerIndices
    34  	}
    35  }
    36  
    37  func WithQCView(view uint64) func(*flow.QuorumCertificate) {
    38  	return func(qc *flow.QuorumCertificate) {
    39  		qc.View = view
    40  	}
    41  }