-
Notifications
You must be signed in to change notification settings - Fork 4
/
helpers_test.go
115 lines (103 loc) · 2.16 KB
/
helpers_test.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package dbft
import (
"testing"
"github.com/stretchr/testify/require"
)
// Structures used for type-specific dBFT/payloads implementation to avoid cyclic
// dependency.
type (
hash struct{}
payloadStub struct {
height uint32
typ MessageType
validatorIndex uint16
}
)
func (hash) String() string {
return ""
}
func (p payloadStub) ViewNumber() byte {
panic("TODO")
}
func (p payloadStub) SetViewNumber(byte) {
panic("TODO")
}
func (p payloadStub) Type() MessageType {
return p.typ
}
func (p payloadStub) SetType(MessageType) {
panic("TODO")
}
func (p payloadStub) Payload() any {
panic("TODO")
}
func (p payloadStub) SetPayload(any) {
panic("TODO")
}
func (p payloadStub) GetChangeView() ChangeView {
panic("TODO")
}
func (p payloadStub) GetPrepareRequest() PrepareRequest[hash] {
panic("TODO")
}
func (p payloadStub) GetPrepareResponse() PrepareResponse[hash] {
panic("TODO")
}
func (p payloadStub) GetCommit() Commit {
panic("TODO")
}
func (p payloadStub) GetPreCommit() PreCommit { panic("TODO") }
func (p payloadStub) GetRecoveryRequest() RecoveryRequest {
panic("TODO")
}
func (p payloadStub) GetRecoveryMessage() RecoveryMessage[hash] {
panic("TODO")
}
func (p payloadStub) ValidatorIndex() uint16 {
return p.validatorIndex
}
func (p payloadStub) SetValidatorIndex(uint16) {
panic("TODO")
}
func (p payloadStub) Height() uint32 {
return p.height
}
func (p payloadStub) SetHeight(uint32) {
panic("TODO")
}
func (p payloadStub) Hash() hash {
panic("TODO")
}
func TestMessageCache(t *testing.T) {
c := newCache[hash]()
p1 := payloadStub{
height: 3,
typ: PrepareRequestType,
}
c.addMessage(p1)
p2 := payloadStub{
height: 4,
typ: ChangeViewType,
}
c.addMessage(p2)
p3 := payloadStub{
height: 4,
typ: CommitType,
}
c.addMessage(p3)
p4 := payloadStub{
height: 3,
typ: PreCommitType,
}
c.addMessage(p4)
box := c.getHeight(3)
require.Len(t, box.chViews, 0)
require.Len(t, box.prepare, 1)
require.Len(t, box.preCommit, 1)
require.Len(t, box.commit, 0)
box = c.getHeight(4)
require.Len(t, box.chViews, 1)
require.Len(t, box.prepare, 0)
require.Len(t, box.preCommit, 0)
require.Len(t, box.commit, 1)
}