github.com/koko1123/flow-go-1@v0.29.6/utils/unittest/seals.go (about) 1 package unittest 2 3 import "github.com/koko1123/flow-go-1/model/flow" 4 5 var Seal sealFactory 6 7 type sealFactory struct{} 8 9 func (f *sealFactory) Fixture(opts ...func(*flow.Seal)) *flow.Seal { 10 seal := &flow.Seal{ 11 BlockID: IdentifierFixture(), 12 ResultID: IdentifierFixture(), 13 FinalState: StateCommitmentFixture(), 14 AggregatedApprovalSigs: Seal.AggregatedSignatureFixtures(3), // 3 chunks 15 } 16 for _, apply := range opts { 17 apply(seal) 18 } 19 return seal 20 } 21 22 func (f *sealFactory) Fixtures(n int) []*flow.Seal { 23 seals := make([]*flow.Seal, 0, n) 24 for i := 0; i < n; i++ { 25 seal := Seal.Fixture() 26 seals = append(seals, seal) 27 } 28 return seals 29 } 30 31 func (f *sealFactory) WithResult(result *flow.ExecutionResult) func(*flow.Seal) { 32 return func(seal *flow.Seal) { 33 finalState, err := result.FinalStateCommitment() 34 if err != nil { 35 panic("missing first execution result's final state commitment") 36 } 37 seal.ResultID = result.ID() 38 seal.BlockID = result.BlockID 39 seal.FinalState = finalState 40 seal.AggregatedApprovalSigs = Seal.AggregatedSignatureFixtures(len(result.Chunks)) 41 } 42 } 43 44 func (f *sealFactory) WithBlockID(blockID flow.Identifier) func(*flow.Seal) { 45 return func(seal *flow.Seal) { 46 seal.BlockID = blockID 47 } 48 } 49 50 func (f *sealFactory) WithBlock(block *flow.Header) func(*flow.Seal) { 51 return func(seal *flow.Seal) { 52 seal.BlockID = block.ID() 53 } 54 } 55 56 func (f *sealFactory) AggregatedSignatureFixtures(number int) []flow.AggregatedSignature { 57 sigs := make([]flow.AggregatedSignature, 0, number) 58 for ; number > 0; number-- { 59 sigs = append(sigs, Seal.AggregatedSignatureFixture()) 60 } 61 return sigs 62 } 63 64 func (f *sealFactory) AggregatedSignatureFixture() flow.AggregatedSignature { 65 return flow.AggregatedSignature{ 66 VerifierSignatures: SignaturesFixture(7), 67 SignerIDs: IdentifierListFixture(7), 68 } 69 }