github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/execution/state/unittest/fixtures.go (about) 1 package unittest 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/onflow/crypto" 8 "github.com/stretchr/testify/require" 9 10 "github.com/onflow/flow-go/engine/execution" 11 "github.com/onflow/flow-go/fvm/meter" 12 "github.com/onflow/flow-go/fvm/storage/snapshot" 13 "github.com/onflow/flow-go/model/flow" 14 "github.com/onflow/flow-go/module/executiondatasync/execution_data" 15 "github.com/onflow/flow-go/module/mempool/entity" 16 "github.com/onflow/flow-go/utils/unittest" 17 ) 18 19 func StateInteractionsFixture() *snapshot.ExecutionSnapshot { 20 return &snapshot.ExecutionSnapshot{ 21 Meter: meter.NewMeter(meter.DefaultParameters()), 22 } 23 } 24 25 func ComputationResultFixture( 26 t *testing.T, 27 parentBlockExecutionResultID flow.Identifier, 28 collectionsSignerIDs [][]flow.Identifier, 29 ) *execution.ComputationResult { 30 31 startState := unittest.StateCommitmentFixture() 32 block := unittest.ExecutableBlockFixture(collectionsSignerIDs, &startState) 33 34 return ComputationResultForBlockFixture(t, 35 parentBlockExecutionResultID, 36 block) 37 } 38 39 func ComputationResultForBlockFixture( 40 t *testing.T, 41 parentBlockExecutionResultID flow.Identifier, 42 completeBlock *entity.ExecutableBlock, 43 ) *execution.ComputationResult { 44 collections := completeBlock.Collections() 45 computationResult := execution.NewEmptyComputationResult(completeBlock) 46 47 numberOfChunks := len(collections) + 1 48 ceds := make([]*execution_data.ChunkExecutionData, numberOfChunks) 49 startState := *completeBlock.StartState 50 for i := 0; i < numberOfChunks; i++ { 51 ceds[i] = unittest.ChunkExecutionDataFixture(t, 1024) 52 endState := unittest.StateCommitmentFixture() 53 computationResult.CollectionExecutionResultAt(i).UpdateExecutionSnapshot(StateInteractionsFixture()) 54 computationResult.AppendCollectionAttestationResult( 55 startState, 56 endState, 57 nil, 58 unittest.IdentifierFixture(), 59 ceds[i], 60 ) 61 startState = endState 62 } 63 bed := unittest.BlockExecutionDataFixture( 64 unittest.WithBlockExecutionDataBlockID(completeBlock.Block.ID()), 65 unittest.WithChunkExecutionDatas(ceds...), 66 ) 67 executionDataID, err := execution_data.CalculateID(context.Background(), bed, execution_data.DefaultSerializer) 68 require.NoError(t, err) 69 70 _, serviceEventEpochCommitProtocol := unittest.EpochCommitFixtureByChainID(flow.Localnet) 71 _, serviceEventEpochSetupProtocol := unittest.EpochSetupFixtureByChainID(flow.Localnet) 72 _, serviceEventVersionBeaconProtocol := unittest.VersionBeaconFixtureByChainID(flow.Localnet) 73 74 convertedServiceEvents := flow.ServiceEventList{ 75 serviceEventEpochCommitProtocol.ServiceEvent(), 76 serviceEventEpochSetupProtocol.ServiceEvent(), 77 serviceEventVersionBeaconProtocol.ServiceEvent(), 78 } 79 80 executionResult := flow.NewExecutionResult( 81 parentBlockExecutionResultID, 82 completeBlock.ID(), 83 computationResult.AllChunks(), 84 convertedServiceEvents, 85 executionDataID) 86 87 computationResult.ExecutionReceipt = &flow.ExecutionReceipt{ 88 ExecutionResult: *executionResult, 89 Spocks: make([]crypto.Signature, numberOfChunks), 90 ExecutorSignature: crypto.Signature{}, 91 } 92 93 return computationResult 94 }