-
Notifications
You must be signed in to change notification settings - Fork 179
/
seals.go
69 lines (59 loc) · 1.8 KB
/
seals.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package unittest
import "github.com/onflow/flow-go/model/flow"
var Seal sealFactory
type sealFactory struct{}
func (f *sealFactory) Fixture(opts ...func(*flow.Seal)) *flow.Seal {
seal := &flow.Seal{
BlockID: IdentifierFixture(),
ResultID: IdentifierFixture(),
FinalState: StateCommitmentFixture(),
AggregatedApprovalSigs: Seal.AggregatedSignatureFixtures(3), // 3 chunks
}
for _, apply := range opts {
apply(seal)
}
return seal
}
func (f *sealFactory) Fixtures(n int) []*flow.Seal {
seals := make([]*flow.Seal, 0, n)
for i := 0; i < n; i++ {
seal := Seal.Fixture()
seals = append(seals, seal)
}
return seals
}
func (f *sealFactory) WithResult(result *flow.ExecutionResult) func(*flow.Seal) {
return func(seal *flow.Seal) {
finalState, ok := result.FinalStateCommitment()
if !ok {
panic("missing first execution result's final state commitment")
}
seal.ResultID = result.ID()
seal.BlockID = result.BlockID
seal.FinalState = finalState
seal.AggregatedApprovalSigs = Seal.AggregatedSignatureFixtures(len(result.Chunks))
}
}
func (f *sealFactory) WithBlockID(blockID flow.Identifier) func(*flow.Seal) {
return func(seal *flow.Seal) {
seal.BlockID = blockID
}
}
func (f *sealFactory) WithBlock(block *flow.Header) func(*flow.Seal) {
return func(seal *flow.Seal) {
seal.BlockID = block.ID()
}
}
func (f *sealFactory) AggregatedSignatureFixtures(number int) []flow.AggregatedSignature {
sigs := make([]flow.AggregatedSignature, 0, number)
for ; number > 0; number-- {
sigs = append(sigs, Seal.AggregatedSignatureFixture())
}
return sigs
}
func (f *sealFactory) AggregatedSignatureFixture() flow.AggregatedSignature {
return flow.AggregatedSignature{
VerifierSignatures: SignaturesFixture(7),
SignerIDs: IdentifierListFixture(7),
}
}