-
Notifications
You must be signed in to change notification settings - Fork 178
/
block.go
52 lines (45 loc) · 1.18 KB
/
block.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
49
50
51
52
package helper
import (
"math/rand"
"testing"
"time"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/unittest"
)
func MakeBlock(t *testing.T, options ...func(*model.Block)) *model.Block {
view := rand.Uint64()
block := model.Block{
View: view,
BlockID: unittest.IdentifierFixture(),
PayloadHash: unittest.IdentifierFixture(),
ProposerID: unittest.IdentifierFixture(),
Timestamp: time.Now().UTC(),
QC: MakeQC(t, WithQCView(view-1)),
}
for _, option := range options {
option(&block)
}
return &block
}
func WithBlockView(view uint64) func(*model.Block) {
return func(block *model.Block) {
block.View = view
}
}
func WithBlockProposer(proposerID flow.Identifier) func(*model.Block) {
return func(block *model.Block) {
block.ProposerID = proposerID
}
}
func WithParentBlock(parent *model.Block) func(*model.Block) {
return func(block *model.Block) {
block.QC.BlockID = parent.BlockID
block.QC.View = parent.View
}
}
func WithParentSigners(signerIDs []flow.Identifier) func(*model.Block) {
return func(block *model.Block) {
block.QC.SignerIDs = signerIDs
}
}