-
Notifications
You must be signed in to change notification settings - Fork 985
/
mock.go
226 lines (183 loc) · 5.92 KB
/
mock.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package mock
import (
"context"
"errors"
"strings"
"sync"
"time"
validatorserviceconfig "github.com/prysmaticlabs/prysm/v4/config/validator/service"
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/validator/accounts/iface"
iface2 "github.com/prysmaticlabs/prysm/v4/validator/client/iface"
"github.com/prysmaticlabs/prysm/v4/validator/keymanager"
)
// Wallet contains an in-memory, simulated wallet implementation.
type Wallet struct {
InnerAccountsDir string
Directories []string
Files map[string]map[string][]byte
EncryptedSeedFile []byte
AccountPasswords map[string]string
WalletPassword string
UnlockAccounts bool
lock sync.RWMutex
HasWriteFileError bool
}
// AccountNames --
func (w *Wallet) AccountNames() ([]string, error) {
w.lock.RLock()
defer w.lock.RUnlock()
names := make([]string, 0)
for name := range w.AccountPasswords {
names = append(names, name)
}
return names, nil
}
// AccountsDir --
func (w *Wallet) AccountsDir() string {
return w.InnerAccountsDir
}
// Exists --
func (w *Wallet) Exists() (bool, error) {
return len(w.Directories) > 0, nil
}
// Password --
func (w *Wallet) Password() string {
return w.WalletPassword
}
// WriteFileAtPath --
func (w *Wallet) WriteFileAtPath(_ context.Context, pathName, fileName string, data []byte) (bool, error) {
w.lock.Lock()
defer w.lock.Unlock()
if w.HasWriteFileError {
// reset the flag to not contaminate other tests
w.HasWriteFileError = false
return false, errors.New("could not write keystore file for accounts")
}
if w.Files[pathName] == nil {
w.Files[pathName] = make(map[string][]byte)
}
w.Files[pathName][fileName] = data
return true, nil
}
// ReadFileAtPath --
func (w *Wallet) ReadFileAtPath(_ context.Context, pathName, fileName string) ([]byte, error) {
w.lock.RLock()
defer w.lock.RUnlock()
for f, v := range w.Files[pathName] {
if strings.Contains(fileName, f) {
return v, nil
}
}
return nil, errors.New("no files found")
}
// InitializeKeymanager --
func (_ *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerConfig) (keymanager.IKeymanager, error) {
return nil, nil
}
type Validator struct {
Km keymanager.IKeymanager
proposerSettings *validatorserviceconfig.ProposerSettings
}
func (_ *Validator) LogSyncCommitteeMessagesSubmitted() {}
func (_ *Validator) Done() {
panic("implement me")
}
func (_ *Validator) WaitForChainStart(_ context.Context) error {
panic("implement me")
}
func (_ *Validator) WaitForSync(_ context.Context) error {
panic("implement me")
}
func (_ *Validator) WaitForActivation(_ context.Context, _ chan [][48]byte) error {
panic("implement me")
}
func (_ *Validator) CanonicalHeadSlot(_ context.Context) (primitives.Slot, error) {
panic("implement me")
}
func (_ *Validator) NextSlot() <-chan primitives.Slot {
panic("implement me")
}
func (_ *Validator) SlotDeadline(_ primitives.Slot) time.Time {
panic("implement me")
}
func (_ *Validator) LogValidatorGainsAndLosses(_ context.Context, _ primitives.Slot) error {
panic("implement me")
}
func (_ *Validator) UpdateDuties(_ context.Context, _ primitives.Slot) error {
panic("implement me")
}
func (_ *Validator) RolesAt(_ context.Context, _ primitives.Slot) (map[[48]byte][]iface2.ValidatorRole, error) {
panic("implement me")
}
func (_ *Validator) SubmitAttestation(_ context.Context, _ primitives.Slot, _ [48]byte) {
panic("implement me")
}
func (_ *Validator) ProposeBlock(_ context.Context, _ primitives.Slot, _ [48]byte) {
panic("implement me")
}
func (_ *Validator) SubmitAggregateAndProof(_ context.Context, _ primitives.Slot, _ [48]byte) {
panic("implement me")
}
func (_ *Validator) SubmitSyncCommitteeMessage(_ context.Context, _ primitives.Slot, _ [48]byte) {
panic("implement me")
}
func (_ *Validator) SubmitSignedContributionAndProof(_ context.Context, _ primitives.Slot, _ [48]byte) {
panic("implement me")
}
func (_ *Validator) LogAttestationsSubmitted() {
panic("implement me")
}
func (_ *Validator) UpdateDomainDataCaches(_ context.Context, _ primitives.Slot) {
panic("implement me")
}
func (_ *Validator) WaitForKeymanagerInitialization(_ context.Context) error {
panic("implement me")
}
func (m *Validator) Keymanager() (keymanager.IKeymanager, error) {
return m.Km, nil
}
func (_ *Validator) ReceiveSlots(_ context.Context, _ chan<- error) {
panic("implement me")
}
func (_ *Validator) HandleKeyReload(_ context.Context, _ [][48]byte) (bool, error) {
panic("implement me")
}
func (_ *Validator) CheckDoppelGanger(_ context.Context) error {
panic("implement me")
}
// HasProposerSettings for mocking
func (*Validator) HasProposerSettings() bool {
panic("implement me")
}
// PushProposerSettings for mocking
func (_ *Validator) PushProposerSettings(_ context.Context, _ keymanager.IKeymanager, _ primitives.Slot, _ time.Time) error {
panic("implement me")
}
// SetPubKeyToValidatorIndexMap for mocking
func (_ *Validator) SetPubKeyToValidatorIndexMap(_ context.Context, _ keymanager.IKeymanager) error {
panic("implement me")
}
// SignValidatorRegistrationRequest for mocking
func (_ *Validator) SignValidatorRegistrationRequest(_ context.Context, _ iface2.SigningFunc, _ *ethpb.ValidatorRegistrationV1) (*ethpb.SignedValidatorRegistrationV1, error) {
panic("implement me")
}
// ProposerSettings for mocking
func (m *Validator) ProposerSettings() *validatorserviceconfig.ProposerSettings {
return m.proposerSettings
}
// SetProposerSettings for mocking
func (m *Validator) SetProposerSettings(_ context.Context, settings *validatorserviceconfig.ProposerSettings) error {
m.proposerSettings = settings
return nil
}
func (_ *Validator) StartEventStream(_ context.Context) error {
panic("implement me")
}
func (_ *Validator) EventStreamIsRunning() bool {
panic("implement me")
}
func (_ *Validator) NodeIsHealthy(ctx context.Context) bool {
panic("implement me")
}