/
storageManagerStub.go
220 lines (185 loc) · 6 KB
/
storageManagerStub.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
package testscommon
import (
"github.com/ElrondNetwork/elrond-go/common"
)
// StorageManagerStub -
type StorageManagerStub struct {
PutCalled func([]byte, []byte) error
PutInEpochCalled func([]byte, []byte, uint32) error
PutInEpochWithoutCacheCalled func([]byte, []byte, uint32) error
GetCalled func([]byte) ([]byte, error)
GetFromCurrentEpochCalled func([]byte) ([]byte, error)
TakeSnapshotCalled func([]byte, []byte, []byte, *common.TrieIteratorChannels, chan []byte, common.SnapshotStatisticsHandler, uint32)
SetCheckpointCalled func([]byte, []byte, *common.TrieIteratorChannels, chan []byte, common.SnapshotStatisticsHandler)
GetDbThatContainsHashCalled func([]byte) common.DBWriteCacher
IsPruningEnabledCalled func() bool
IsPruningBlockedCalled func() bool
EnterPruningBufferingModeCalled func()
ExitPruningBufferingModeCalled func()
AddDirtyCheckpointHashesCalled func([]byte, common.ModifiedHashes) bool
RemoveFromCurrentEpochCalled func([]byte) error
RemoveCalled func([]byte) error
IsInterfaceNilCalled func() bool
SetEpochForPutOperationCalled func(uint32)
ShouldTakeSnapshotCalled func() bool
GetLatestStorageEpochCalled func() (uint32, error)
IsClosedCalled func() bool
RemoveFromCheckpointHashesHolderCalled func([]byte)
GetBaseTrieStorageManagerCalled func() common.StorageManager
}
// Put -
func (sms *StorageManagerStub) Put(key []byte, val []byte) error {
if sms.PutCalled != nil {
return sms.PutCalled(key, val)
}
return nil
}
// PutInEpoch -
func (sms *StorageManagerStub) PutInEpoch(key []byte, val []byte, epoch uint32) error {
if sms.PutInEpochCalled != nil {
return sms.PutInEpochCalled(key, val, epoch)
}
return nil
}
// PutInEpochWithoutCache -
func (sms *StorageManagerStub) PutInEpochWithoutCache(key []byte, val []byte, epoch uint32) error {
if sms.PutInEpochWithoutCacheCalled != nil {
return sms.PutInEpochWithoutCacheCalled(key, val, epoch)
}
return nil
}
// Get -
func (sms *StorageManagerStub) Get(key []byte) ([]byte, error) {
if sms.GetCalled != nil {
return sms.GetCalled(key)
}
return nil, nil
}
// GetFromCurrentEpoch -
func (sms *StorageManagerStub) GetFromCurrentEpoch(key []byte) ([]byte, error) {
if sms.GetFromCurrentEpochCalled != nil {
return sms.GetFromCurrentEpochCalled(key)
}
return nil, nil
}
// TakeSnapshot -
func (sms *StorageManagerStub) TakeSnapshot(
address []byte,
rootHash []byte,
mainTrieRootHash []byte,
iteratorChannels *common.TrieIteratorChannels,
missingNodesChan chan []byte,
stats common.SnapshotStatisticsHandler,
epoch uint32,
) {
if sms.TakeSnapshotCalled != nil {
sms.TakeSnapshotCalled(address, rootHash, mainTrieRootHash, iteratorChannels, missingNodesChan, stats, epoch)
}
}
// SetCheckpoint -
func (sms *StorageManagerStub) SetCheckpoint(
rootHash []byte,
mainTrieRootHash []byte,
iteratorChannels *common.TrieIteratorChannels,
missingNodesChan chan []byte,
stats common.SnapshotStatisticsHandler,
) {
if sms.SetCheckpointCalled != nil {
sms.SetCheckpointCalled(rootHash, mainTrieRootHash, iteratorChannels, missingNodesChan, stats)
}
}
// IsPruningEnabled -
func (sms *StorageManagerStub) IsPruningEnabled() bool {
if sms.IsPruningEnabledCalled != nil {
return sms.IsPruningEnabledCalled()
}
return false
}
// IsPruningBlocked -
func (sms *StorageManagerStub) IsPruningBlocked() bool {
if sms.IsPruningBlockedCalled != nil {
return sms.IsPruningBlockedCalled()
}
return false
}
// EnterPruningBufferingMode -
func (sms *StorageManagerStub) EnterPruningBufferingMode() {
if sms.EnterPruningBufferingModeCalled != nil {
sms.EnterPruningBufferingModeCalled()
}
}
// ExitPruningBufferingMode -
func (sms *StorageManagerStub) ExitPruningBufferingMode() {
if sms.ExitPruningBufferingModeCalled != nil {
sms.ExitPruningBufferingModeCalled()
}
}
// AddDirtyCheckpointHashes -
func (sms *StorageManagerStub) AddDirtyCheckpointHashes(rootHash []byte, hashes common.ModifiedHashes) bool {
if sms.AddDirtyCheckpointHashesCalled != nil {
return sms.AddDirtyCheckpointHashesCalled(rootHash, hashes)
}
return false
}
// RemoveFromCurrentEpoch -
func (sms *StorageManagerStub) RemoveFromCurrentEpoch(hash []byte) error {
if sms.RemoveFromCurrentEpochCalled != nil {
return sms.RemoveFromCurrentEpochCalled(hash)
}
return nil
}
// Remove -
func (sms *StorageManagerStub) Remove(hash []byte) error {
if sms.RemoveCalled != nil {
return sms.RemoveCalled(hash)
}
return nil
}
// SetEpochForPutOperation -
func (sms *StorageManagerStub) SetEpochForPutOperation(epoch uint32) {
if sms.SetEpochForPutOperationCalled != nil {
sms.SetEpochForPutOperationCalled(epoch)
}
}
// ShouldTakeSnapshot -
func (sms *StorageManagerStub) ShouldTakeSnapshot() bool {
if sms.ShouldTakeSnapshotCalled != nil {
return sms.ShouldTakeSnapshotCalled()
}
return true
}
// GetLatestStorageEpoch -
func (sms *StorageManagerStub) GetLatestStorageEpoch() (uint32, error) {
if sms.GetLatestStorageEpochCalled != nil {
return sms.GetLatestStorageEpochCalled()
}
return 0, nil
}
// Close -
func (sms *StorageManagerStub) Close() error {
return nil
}
// IsClosed -
func (sms *StorageManagerStub) IsClosed() bool {
if sms.IsClosedCalled != nil {
return sms.IsClosedCalled()
}
return false
}
// RemoveFromCheckpointHashesHolder -
func (sms *StorageManagerStub) RemoveFromCheckpointHashesHolder(hash []byte) {
if sms.RemoveFromCheckpointHashesHolderCalled != nil {
sms.RemoveFromCheckpointHashesHolderCalled(hash)
}
}
// GetBaseTrieStorageManager -
func (sms *StorageManagerStub) GetBaseTrieStorageManager() common.StorageManager {
if sms.GetBaseTrieStorageManagerCalled != nil {
return sms.GetBaseTrieStorageManagerCalled()
}
return nil
}
// IsInterfaceNil -
func (sms *StorageManagerStub) IsInterfaceNil() bool {
return sms == nil
}