-
Notifications
You must be signed in to change notification settings - Fork 175
/
protocol_state.go
53 lines (48 loc) · 1.26 KB
/
protocol_state.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
package unittest
import (
"github.com/stretchr/testify/mock"
"github.com/onflow/flow-go/model/flow"
protint "github.com/onflow/flow-go/state/protocol"
protocol "github.com/onflow/flow-go/state/protocol/mock"
)
// FinalizedProtocolStateWithParticipants returns a protocol state with finalized participants
func FinalizedProtocolStateWithParticipants(participants flow.IdentityList) (
*flow.Block, *protocol.Snapshot, *protocol.State) {
block := BlockFixture()
head := block.Header
// set up protocol snapshot mock
snapshot := &protocol.Snapshot{}
snapshot.On("Identities", mock.Anything).Return(
func(filter flow.IdentityFilter) flow.IdentityList {
return participants.Filter(filter)
},
nil,
)
snapshot.On("Identity", mock.Anything).Return(func(id flow.Identifier) *flow.Identity {
for _, n := range participants {
if n.ID() == id {
return n
}
}
return nil
}, nil)
snapshot.On("Head").Return(
func() *flow.Header {
return head
},
nil,
)
// set up protocol state mock
state := &protocol.State{}
state.On("Final").Return(
func() protint.Snapshot {
return snapshot
},
)
state.On("AtBlockID", mock.Anything).Return(
func(blockID flow.Identifier) protint.Snapshot {
return snapshot
},
)
return &block, snapshot, state
}