-
Notifications
You must be signed in to change notification settings - Fork 175
/
fixtures.go
94 lines (80 loc) · 2.98 KB
/
fixtures.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package unittest
import (
"context"
"testing"
"github.com/onflow/crypto"
"github.com/stretchr/testify/require"
"github.com/onflow/flow-go/engine/execution"
"github.com/onflow/flow-go/fvm/meter"
"github.com/onflow/flow-go/fvm/storage/snapshot"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/executiondatasync/execution_data"
"github.com/onflow/flow-go/module/mempool/entity"
"github.com/onflow/flow-go/utils/unittest"
)
func StateInteractionsFixture() *snapshot.ExecutionSnapshot {
return &snapshot.ExecutionSnapshot{
Meter: meter.NewMeter(meter.DefaultParameters()),
}
}
func ComputationResultFixture(
t *testing.T,
parentBlockExecutionResultID flow.Identifier,
collectionsSignerIDs [][]flow.Identifier,
) *execution.ComputationResult {
startState := unittest.StateCommitmentFixture()
block := unittest.ExecutableBlockFixture(collectionsSignerIDs, &startState)
return ComputationResultForBlockFixture(t,
parentBlockExecutionResultID,
block)
}
func ComputationResultForBlockFixture(
t *testing.T,
parentBlockExecutionResultID flow.Identifier,
completeBlock *entity.ExecutableBlock,
) *execution.ComputationResult {
collections := completeBlock.Collections()
computationResult := execution.NewEmptyComputationResult(completeBlock)
numberOfChunks := len(collections) + 1
ceds := make([]*execution_data.ChunkExecutionData, numberOfChunks)
startState := *completeBlock.StartState
for i := 0; i < numberOfChunks; i++ {
ceds[i] = unittest.ChunkExecutionDataFixture(t, 1024)
endState := unittest.StateCommitmentFixture()
computationResult.CollectionExecutionResultAt(i).UpdateExecutionSnapshot(StateInteractionsFixture())
computationResult.AppendCollectionAttestationResult(
startState,
endState,
nil,
unittest.IdentifierFixture(),
ceds[i],
)
startState = endState
}
bed := unittest.BlockExecutionDataFixture(
unittest.WithBlockExecutionDataBlockID(completeBlock.Block.ID()),
unittest.WithChunkExecutionDatas(ceds...),
)
executionDataID, err := execution_data.CalculateID(context.Background(), bed, execution_data.DefaultSerializer)
require.NoError(t, err)
_, serviceEventEpochCommitProtocol := unittest.EpochCommitFixtureByChainID(flow.Localnet)
_, serviceEventEpochSetupProtocol := unittest.EpochSetupFixtureByChainID(flow.Localnet)
_, serviceEventVersionBeaconProtocol := unittest.VersionBeaconFixtureByChainID(flow.Localnet)
convertedServiceEvents := flow.ServiceEventList{
serviceEventEpochCommitProtocol.ServiceEvent(),
serviceEventEpochSetupProtocol.ServiceEvent(),
serviceEventVersionBeaconProtocol.ServiceEvent(),
}
executionResult := flow.NewExecutionResult(
parentBlockExecutionResultID,
completeBlock.ID(),
computationResult.AllChunks(),
convertedServiceEvents,
executionDataID)
computationResult.ExecutionReceipt = &flow.ExecutionReceipt{
ExecutionResult: *executionResult,
Spocks: make([]crypto.Signature, numberOfChunks),
ExecutorSignature: crypto.Signature{},
}
return computationResult
}