@@ -10,6 +10,7 @@ import { ACCOUNT_STATE_PENDING_INTERVAL } from '../../consts/intervals'
10
10
import { RPCProviders } from '../../interfaces/provider'
11
11
import { SubmittedAccountOp } from '../../libs/accountOp/submittedAccountOp'
12
12
import { KeystoreSigner } from '../../libs/keystoreSigner/keystoreSigner'
13
+ import wait from '../../utils/wait'
13
14
import { MainController } from '../main/main'
14
15
15
16
// Public API key, shared by Socket, for testing purposes only
@@ -103,10 +104,16 @@ const prepareTest = async () => {
103
104
velcroUrl
104
105
} )
105
106
mainCtrl . portfolio . updateSelectedAccount = jest . fn ( ) . mockResolvedValue ( undefined )
106
- mainCtrl . updateSelectedAccountPortfolio = jest . fn ( ) . mockResolvedValue ( undefined )
107
+ mainCtrl . updateSelectedAccountPortfolio = jest . fn ( ) . mockImplementation ( async ( ) => {
108
+ await wait ( 500 )
109
+ } )
107
110
mainCtrl . domains . reverseLookup = jest . fn ( ) . mockResolvedValue ( undefined )
108
- mainCtrl . accounts . updateAccountStates = jest . fn ( ) . mockResolvedValue ( undefined )
109
- mainCtrl . accounts . updateAccountState = jest . fn ( ) . mockResolvedValue ( undefined )
111
+ mainCtrl . accounts . updateAccountStates = jest . fn ( ) . mockImplementation ( async ( ) => {
112
+ await wait ( 500 )
113
+ } )
114
+ mainCtrl . accounts . updateAccountState = jest . fn ( ) . mockImplementation ( async ( ) => {
115
+ await wait ( 500 )
116
+ } )
110
117
mainCtrl . updateAccountsOpsStatuses = jest . fn ( ) . mockResolvedValue ( { newestOpTimestamp : 0 } )
111
118
112
119
return { mainCtrl }
@@ -165,45 +172,30 @@ describe('ContinuousUpdatesController intervals', () => {
165
172
const updateSelectedAccountPortfolioSpy = jest . spyOn ( mainCtrl , 'updateSelectedAccountPortfolio' )
166
173
const initialFnExecutionsCount =
167
174
mainCtrl . continuousUpdates . updatePortfolioInterval . fnExecutionsCount
168
- const { fnExecutionsCount : fnExecutionsCountFirstCall } = await waitForFnToBeCalledAndExecuted (
169
- mainCtrl . continuousUpdates . updatePortfolioInterval
170
- )
175
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . updatePortfolioInterval )
171
176
expect ( mainCtrl . continuousUpdates . updatePortfolioInterval . fnExecutionsCount ) . toBe (
172
- initialFnExecutionsCount + fnExecutionsCountFirstCall
177
+ initialFnExecutionsCount + 1
173
178
)
174
179
const updateSelectedAccountCalledTimes = updateSelectedAccountPortfolioSpy . mock . calls . length
175
180
await mainCtrl . activity . addAccountOp ( submittedAccountOp )
176
181
await jest . advanceTimersByTimeAsync ( 0 )
177
- const { fnExecutionsCount : fnExecutionsCountSecondCall } = await waitForFnToBeCalledAndExecuted (
178
- mainCtrl . continuousUpdates . updatePortfolioInterval
179
- )
182
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . updatePortfolioInterval )
180
183
expect ( mainCtrl . continuousUpdates . updatePortfolioInterval . fnExecutionsCount ) . toBe (
181
- initialFnExecutionsCount + fnExecutionsCountFirstCall + fnExecutionsCountSecondCall
184
+ initialFnExecutionsCount + 2
182
185
)
183
186
expect ( updateSelectedAccountPortfolioSpy ) . toHaveBeenCalledTimes (
184
187
updateSelectedAccountCalledTimes
185
188
) // tests the branching in the updatePortfolio func
186
189
mainCtrl . ui . removeView ( '1' )
187
190
await jest . advanceTimersByTimeAsync ( 0 )
188
191
expect ( mainCtrl . continuousUpdates . updatePortfolioInterval . restart ) . toHaveBeenCalledTimes ( 2 )
189
- const { fnExecutionsCount : fnExecutionsCountThirdCall } = await waitForFnToBeCalledAndExecuted (
190
- mainCtrl . continuousUpdates . updatePortfolioInterval
191
- )
192
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . updatePortfolioInterval )
192
193
expect ( mainCtrl . continuousUpdates . updatePortfolioInterval . fnExecutionsCount ) . toBe (
193
- initialFnExecutionsCount +
194
- fnExecutionsCountFirstCall +
195
- fnExecutionsCountSecondCall +
196
- fnExecutionsCountThirdCall
197
- )
198
- const { fnExecutionsCount : fnExecutionsCountFourthCall } = await waitForFnToBeCalledAndExecuted (
199
- mainCtrl . continuousUpdates . updatePortfolioInterval
194
+ initialFnExecutionsCount + 3
200
195
)
196
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . updatePortfolioInterval )
201
197
expect ( mainCtrl . continuousUpdates . updatePortfolioInterval . fnExecutionsCount ) . toBe (
202
- initialFnExecutionsCount +
203
- fnExecutionsCountFirstCall +
204
- fnExecutionsCountSecondCall +
205
- fnExecutionsCountThirdCall +
206
- fnExecutionsCountFourthCall
198
+ initialFnExecutionsCount + 4
207
199
)
208
200
} )
209
201
@@ -221,17 +213,13 @@ describe('ContinuousUpdatesController intervals', () => {
221
213
mainCtrl . continuousUpdates . accountsOpsStatusesInterval . fnExecutionsCount
222
214
223
215
expect ( mainCtrl . continuousUpdates . accountsOpsStatusesInterval . start ) . toHaveBeenCalled ( )
224
- const { fnExecutionsCount : fnExecutionsCountFirstCall } = await waitForFnToBeCalledAndExecuted (
225
- mainCtrl . continuousUpdates . accountsOpsStatusesInterval
226
- )
216
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . accountsOpsStatusesInterval )
227
217
expect ( mainCtrl . continuousUpdates . accountsOpsStatusesInterval . fnExecutionsCount ) . toBe (
228
- initialFnExecutionsCount + fnExecutionsCountFirstCall
229
- )
230
- const { fnExecutionsCount : fnExecutionsCountSecondCall } = await waitForFnToBeCalledAndExecuted (
231
- mainCtrl . continuousUpdates . accountsOpsStatusesInterval
218
+ initialFnExecutionsCount + 1
232
219
)
220
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . accountsOpsStatusesInterval )
233
221
expect ( mainCtrl . continuousUpdates . accountsOpsStatusesInterval . fnExecutionsCount ) . toBe (
234
- initialFnExecutionsCount + fnExecutionsCountFirstCall + fnExecutionsCountSecondCall
222
+ initialFnExecutionsCount + 2
235
223
)
236
224
jest . spyOn ( mainCtrl . activity , 'broadcastedButNotConfirmed' , 'get' ) . mockReturnValue ( [ ] )
237
225
// @ts -ignore
@@ -257,10 +245,9 @@ describe('ContinuousUpdatesController intervals', () => {
257
245
258
246
expect ( mainCtrl . continuousUpdates . accountStateLatestInterval . running ) . toBe ( true )
259
247
expect ( mainCtrl . continuousUpdates . accountStatePendingInterval . running ) . toBe ( false )
260
- const { fnExecutionsCount : accountStateLatestFnExecutionsCountFirstCall } =
261
- await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . accountStateLatestInterval )
248
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . accountStateLatestInterval )
262
249
expect ( mainCtrl . continuousUpdates . accountStateLatestInterval . fnExecutionsCount ) . toBe (
263
- initialAccountStateLatestFnExecutionsCount + accountStateLatestFnExecutionsCountFirstCall
250
+ initialAccountStateLatestFnExecutionsCount + 1
264
251
)
265
252
mainCtrl . statuses . signAndBroadcastAccountOp = 'SUCCESS'
266
253
// @ts -ignore
@@ -273,10 +260,10 @@ describe('ContinuousUpdatesController intervals', () => {
273
260
expect ( mainCtrl . continuousUpdates . accountStatePendingInterval . currentTimeout ) . toBe (
274
261
ACCOUNT_STATE_PENDING_INTERVAL / 2
275
262
)
276
- const { fnExecutionsCount : accountStatePendingFnExecutionsCountFirstCall } =
277
- await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . accountStatePendingInterval )
263
+
264
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . accountStatePendingInterval )
278
265
expect ( mainCtrl . continuousUpdates . accountStatePendingInterval . fnExecutionsCount ) . toBe (
279
- initialAccountStatePendingFnExecutionsCount + accountStatePendingFnExecutionsCountFirstCall
266
+ initialAccountStatePendingFnExecutionsCount + 1
280
267
)
281
268
expect ( mainCtrl . continuousUpdates . accountStateLatestInterval . restart ) . toHaveBeenCalledTimes ( 2 )
282
269
expect ( mainCtrl . continuousUpdates . accountStatePendingInterval . stop ) . toHaveBeenCalledTimes ( 1 )
@@ -317,17 +304,32 @@ describe('ContinuousUpdatesController intervals', () => {
317
304
expect ( mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout . fnExecutionsCount ) . toBe (
318
305
initialFnExecutionsCount
319
306
)
320
- const { fnExecutionsCount : fnExecutionsCountFirstCall } = await waitForFnToBeCalledAndExecuted (
321
- mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout
322
- )
307
+ // @ts -ignore
308
+ mainCtrl . providers . emitUpdate ( )
309
+ // @ts -ignore
310
+ mainCtrl . providers . emitUpdate ( )
311
+ // @ts -ignore
312
+ mainCtrl . providers . emitUpdate ( )
313
+
314
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout )
315
+ // @ts -ignore
316
+ mainCtrl . providers . emitUpdate ( )
317
+ // @ts -ignore
318
+ mainCtrl . providers . emitUpdate ( )
319
+
323
320
expect ( mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout . fnExecutionsCount ) . toBe (
324
- initialFnExecutionsCount + fnExecutionsCountFirstCall
325
- )
326
- const { fnExecutionsCount : fnExecutionsCountSecondCall } = await waitForFnToBeCalledAndExecuted (
327
- mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout
321
+ initialFnExecutionsCount + 1
328
322
)
323
+ // @ts -ignore
324
+ mainCtrl . providers . emitUpdate ( )
325
+ // @ts -ignore
326
+ mainCtrl . providers . emitUpdate ( )
327
+ // @ts -ignore
328
+ mainCtrl . providers . emitUpdate ( )
329
+
330
+ await waitForFnToBeCalledAndExecuted ( mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout )
329
331
expect ( mainCtrl . continuousUpdates . fastAccountStateReFetchTimeout . fnExecutionsCount ) . toBe (
330
- initialFnExecutionsCount + fnExecutionsCountFirstCall + fnExecutionsCountSecondCall
332
+ initialFnExecutionsCount + 2
331
333
)
332
334
} )
333
335
} )
0 commit comments