-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathmock_f3.go
More file actions
162 lines (123 loc) · 3.55 KB
/
Copy pathmock_f3.go
File metadata and controls
162 lines (123 loc) · 3.55 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package mock
import (
"context"
"sync"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-f3/certs"
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/manifest"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/lf3"
"github.com/filecoin-project/lotus/chain/types"
)
type MockF3API struct {
lk sync.Mutex
latestCert *certs.FinalityCertificate
manifest *manifest.Manifest
enabled bool
running bool
}
func (m *MockF3API) GetOrRenewParticipationTicket(ctx context.Context, minerID uint64, previous api.F3ParticipationTicket, instances uint64) (api.F3ParticipationTicket, error) {
if !m.IsEnabled() {
return api.F3ParticipationTicket{}, api.ErrF3Disabled
}
return api.F3ParticipationTicket{}, nil
}
func (m *MockF3API) Participate(ctx context.Context, ticket api.F3ParticipationTicket) (api.F3ParticipationLease, error) {
if !m.IsEnabled() {
return api.F3ParticipationLease{}, api.ErrF3Disabled
}
return api.F3ParticipationLease{}, nil
}
func (m *MockF3API) GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error) {
if !m.IsEnabled() {
return nil, api.ErrF3Disabled
}
return nil, nil
}
// SetLatestCert sets the latest certificate to be returned by GetLatestCert. If GetLatestCert is
// called before this method, it will return an error.
func (m *MockF3API) SetLatestCert(cert *certs.FinalityCertificate) {
m.lk.Lock()
defer m.lk.Unlock()
m.latestCert = cert
}
func (m *MockF3API) GetLatestCert(ctx context.Context) (*certs.FinalityCertificate, error) {
m.lk.Lock()
defer m.lk.Unlock()
if !m.enabled {
return nil, api.ErrF3Disabled
}
if m.latestCert == nil {
return nil, xerrors.Errorf("no latest cert set in test, did you mean to?")
}
return m.latestCert, nil
}
// SetManifest sets the manifest to be returned by GetManifest. If GetManifest is called before this
// method, it will return an error.
//
// Use manifest.LocalDevnetManifest() for a convenient manifest to use in tests.
func (m *MockF3API) SetManifest(manifest *manifest.Manifest) {
m.lk.Lock()
defer m.lk.Unlock()
m.manifest = manifest
}
func (m *MockF3API) GetManifest(ctx context.Context) (*manifest.Manifest, error) {
m.lk.Lock()
defer m.lk.Unlock()
if !m.enabled {
return nil, api.ErrF3Disabled
}
if m.manifest == nil {
return nil, xerrors.Errorf("no manifest set in test, did you mean to?")
}
return m.manifest, nil
}
func (m *MockF3API) GetPowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error) {
if !m.IsEnabled() {
return nil, api.ErrF3Disabled
}
return nil, nil
}
func (m *MockF3API) GetF3PowerTable(ctx context.Context, tsk types.TipSetKey) (gpbft.PowerEntries, error) {
if !m.IsEnabled() {
return nil, api.ErrF3Disabled
}
return nil, nil
}
func (m *MockF3API) SetEnabled(enabled bool) {
m.lk.Lock()
defer m.lk.Unlock()
m.enabled = enabled
}
func (m *MockF3API) IsEnabled() bool {
m.lk.Lock()
defer m.lk.Unlock()
return m.enabled
}
func (m *MockF3API) SetRunning(running bool) {
m.lk.Lock()
defer m.lk.Unlock()
m.running = running
}
func (m *MockF3API) IsRunning() (bool, error) {
m.lk.Lock()
defer m.lk.Unlock()
if !m.enabled {
return false, api.ErrF3Disabled
}
return m.running, nil
}
func (m *MockF3API) Progress() (gpbft.Instant, error) {
if !m.IsEnabled() {
return gpbft.Instant{}, api.ErrF3Disabled
}
return gpbft.Instant{}, nil
}
func (m *MockF3API) ListParticipants() ([]api.F3Participant, error) {
if !m.IsEnabled() {
return nil, api.ErrF3Disabled
}
return nil, nil
}
var _ lf3.F3API = (*MockF3API)(nil)