-
Notifications
You must be signed in to change notification settings - Fork 179
/
version_beacon.go
60 lines (46 loc) · 1.68 KB
/
version_beacon.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
package unittest
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
)
// AddVersionBeacon adds blocks sequence with given VersionBeacon so this
// service events takes effect in Flow protocol.
// This means execution result where event was emitted is sealed, and the seal is
// finalized by a valid block.
// This assumes state is bootstrapped with a root block, as it does NOT produce
// results for final block of the state
// Root <- A <- B(result(A(VB))) <- C(seal(B))
func AddVersionBeacon(t *testing.T, beacon *flow.VersionBeacon, state protocol.FollowerState) {
final, err := state.Final().Head()
require.NoError(t, err)
A := BlockWithParentFixture(final)
A.SetPayload(flow.Payload{})
addToState(t, state, A, true)
receiptA := ReceiptForBlockFixture(A)
receiptA.ExecutionResult.ServiceEvents = []flow.ServiceEvent{beacon.ServiceEvent()}
B := BlockWithParentFixture(A.Header)
B.SetPayload(flow.Payload{
Receipts: []*flow.ExecutionReceiptMeta{receiptA.Meta()},
Results: []*flow.ExecutionResult{&receiptA.ExecutionResult},
})
addToState(t, state, B, true)
sealsForB := []*flow.Seal{
Seal.Fixture(Seal.WithResult(&receiptA.ExecutionResult)),
}
C := BlockWithParentFixture(B.Header)
C.SetPayload(flow.Payload{
Seals: sealsForB,
})
addToState(t, state, C, true)
}
func addToState(t *testing.T, state protocol.FollowerState, block *flow.Block, finalize bool) {
err := state.ExtendCertified(context.Background(), block, CertifyBlock(block.Header))
require.NoError(t, err)
if finalize {
err = state.Finalize(context.Background(), block.ID())
require.NoError(t, err)
}
}