@onekeyfe/hd-core 1.2.2-alpha.0 → 1.2.2-alpha.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +4 -20
  2. package/__tests__/DeviceCommands.test.ts +0 -13
  3. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +2 -0
  4. package/__tests__/check-firmware-release-protocol-v2.test.ts +2 -0
  5. package/__tests__/device-lifecycle-events.test.ts +0 -19
  6. package/__tests__/deviceUploadNft.test.ts +0 -41
  7. package/__tests__/evmSignTypedData.test.ts +0 -42
  8. package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -524
  9. package/__tests__/open-wallet-session.test.ts +1 -127
  10. package/__tests__/protocol-v2-resources.test.ts +4 -7
  11. package/__tests__/protocol-v2-unlock-policy.test.ts +1 -35
  12. package/__tests__/protocol-v2.test.ts +27 -673
  13. package/dist/api/FirmwareUpdateV4.d.ts +0 -3
  14. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  15. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  16. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  17. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  18. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -2
  19. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  20. package/dist/api/firmware/getBinary.d.ts +2 -2
  21. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  22. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  23. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  24. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  25. package/dist/core/index.d.ts +0 -1
  26. package/dist/core/index.d.ts.map +1 -1
  27. package/dist/device/Device.d.ts +1 -1
  28. package/dist/device/Device.d.ts.map +1 -1
  29. package/dist/device/DeviceConnector.d.ts +1 -1
  30. package/dist/device/DeviceConnector.d.ts.map +1 -1
  31. package/dist/events/ui-request.d.ts +0 -3
  32. package/dist/events/ui-request.d.ts.map +1 -1
  33. package/dist/index.d.ts +5 -10
  34. package/dist/index.js +398 -1116
  35. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  36. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -2
  37. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
  38. package/dist/protocols/protocol-v2/walletSession.d.ts +0 -3
  39. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  40. package/dist/types/settings.d.ts +2 -2
  41. package/dist/types/settings.d.ts.map +1 -1
  42. package/dist/utils/deviceFeaturesUtils.d.ts +0 -3
  43. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  44. package/dist/utils/patch.d.ts +1 -1
  45. package/dist/utils/patch.d.ts.map +1 -1
  46. package/package.json +4 -4
  47. package/src/api/FirmwareUpdateV4.ts +75 -416
  48. package/src/api/OpenWalletSession.ts +9 -39
  49. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +1 -2
  50. package/src/api/evm/EVMSignTypedData.ts +0 -1
  51. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -9
  52. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +1 -7
  53. package/src/api/protocol-v2/DeviceUploadNft.ts +8 -28
  54. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -19
  55. package/src/api/protocol-v2/helpers.ts +0 -8
  56. package/src/core/index.ts +10 -121
  57. package/src/data/messages/messages-protocol-v2.json +1 -111
  58. package/src/device/Device.ts +1 -3
  59. package/src/device/DeviceConnector.ts +3 -7
  60. package/src/events/ui-request.ts +0 -3
  61. package/src/protocols/protocol-v2/resources.ts +1 -9
  62. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -8
  63. package/src/protocols/protocol-v2/walletSession.ts +22 -65
  64. package/src/types/settings.ts +2 -4
  65. package/src/utils/deviceFeaturesUtils.ts +0 -4
  66. package/__tests__/pro2HostAssetPackage.test.ts +0 -58
  67. package/dist/utils/pro2HostAssetPackage.d.ts +0 -8
  68. package/dist/utils/pro2HostAssetPackage.d.ts.map +0 -1
  69. package/src/utils/pro2HostAssetPackage.ts +0 -315
@@ -14,39 +14,18 @@ describe('FirmwareUpdateV4 install polling', () => {
14
14
  jest.restoreAllMocks();
15
15
  });
16
16
 
17
- test('writes the USB Request before polling current install status', async () => {
17
+ test('uses Stage, an empty write-only Request, then status polling', async () => {
18
18
  const method = new FirmwareUpdateV4({
19
19
  id: 1,
20
20
  payload: {
21
21
  method: 'firmwareUpdateV4',
22
- connectId: 'pro2-usb',
22
+ connectId: 'pro2-ble',
23
23
  },
24
24
  });
25
25
  const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
26
26
  const typedCall = jest
27
27
  .fn()
28
28
  .mockResolvedValueOnce({ type: 'Success', message: {} })
29
- .mockResolvedValueOnce({
30
- type: 'DeviceFirmwareUpdateStatus',
31
- message: { records: [] },
32
- })
33
- .mockResolvedValueOnce({
34
- type: 'DeviceFirmwareUpdateStatus',
35
- message: {
36
- records: [
37
- {
38
- target_id: 4,
39
- status: 'FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS',
40
- progress_percent: 42,
41
- phase_info: {
42
- phase: 'FW_MGMT_UPDATER_PHASE_INSTALL',
43
- progress_percent: 60,
44
- },
45
- path: 'vol0:/application_p1.bin',
46
- },
47
- ],
48
- },
49
- })
50
29
  .mockResolvedValueOnce({
51
30
  type: 'DeviceFirmwareUpdateStatus',
52
31
  message: {
@@ -59,17 +38,13 @@ describe('FirmwareUpdateV4 install polling', () => {
59
38
  ],
60
39
  },
61
40
  });
62
- const call = jest.fn().mockResolvedValue({
63
- type: 'WriteCompleted',
64
- message: {},
65
- });
66
- const setCancelableAction = jest.fn();
41
+ const call = jest.fn().mockResolvedValue({ type: 'WriteCompleted', message: {} });
67
42
 
68
43
  method.device = {
69
- getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
44
+ getCommands: () => ({ typedCall, call }),
70
45
  createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
71
- toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-usb' }),
72
- setCancelableAction,
46
+ toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-ble' }),
47
+ setCancelableAction: jest.fn(),
73
48
  clearCancelableAction: jest.fn(),
74
49
  } as unknown as Device;
75
50
  method.postMessage = jest.fn();
@@ -78,458 +53,24 @@ describe('FirmwareUpdateV4 install polling', () => {
78
53
 
79
54
  const firmwareUpdate = method as unknown as {
80
55
  protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
81
- waitForProtocolV2FirmwareUpdateComplete: (
82
- value: typeof targets,
83
- requireCurrentInstallStatus: boolean
84
- ) => Promise<void>;
56
+ waitForProtocolV2FirmwareUpdateComplete: (value: typeof targets) => Promise<void>;
85
57
  reconnectProtocolV2Device: () => Promise<void>;
86
58
  verifyProtocolV2ReconnectIdentity: () => Promise<Record<string, never>>;
87
59
  };
88
60
  firmwareUpdate.reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
89
61
  firmwareUpdate.verifyProtocolV2ReconnectIdentity = jest.fn().mockResolvedValue({});
90
- (method as any).isBleReconnect = jest.fn(() => false);
91
62
 
92
63
  await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
64
+ await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets);
93
65
 
94
66
  expect(typedCall.mock.calls[0]).toEqual(['DeviceFirmwareUpdateStage', 'Success', { targets }]);
95
67
  expect(call).toHaveBeenCalledWith(
96
68
  'DeviceFirmwareUpdateRequest',
97
69
  {},
98
- expect.objectContaining({
99
- returnAfterWrite: true,
100
- expectedTypes: ['Success'],
101
- onResponseAfterWrite: expect.any(Function),
102
- })
70
+ { returnAfterWrite: true }
103
71
  );
104
- expect(method.postProgressMessage).not.toHaveBeenCalled();
105
-
106
- await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
107
-
108
72
  expect(typedCall.mock.calls[1]?.[0]).toBe('DeviceFirmwareUpdateStatusGet');
109
- expect(typedCall.mock.calls[1]?.[2]).toEqual({
110
- fields: {
111
- status: true,
112
- progress_percent: true,
113
- phase_info: true,
114
- payload_version: true,
115
- path: true,
116
- },
117
- });
118
- expect(method.postProgressMessage).toHaveBeenCalledWith(42, 'installingFirmware', {
119
- installTargetId: 4,
120
- installPhase: 'install',
121
- installPhaseProgress: 60,
122
- });
123
- expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
124
73
  expect(call.mock.invocationCallOrder[0]).toBeLessThan(typedCall.mock.invocationCallOrder[1]);
125
- expect(setCancelableAction).toHaveBeenCalledTimes(2);
126
- });
127
-
128
- test('accepts path-less finished USB status after the Request terminal Success arrives', async () => {
129
- const method = new FirmwareUpdateV4({
130
- id: 1,
131
- payload: {
132
- method: 'firmwareUpdateV4',
133
- connectId: 'pro2-usb',
134
- },
135
- });
136
- const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
137
- const typedCall = jest
138
- .fn()
139
- .mockResolvedValueOnce({ type: 'Success', message: {} })
140
- .mockResolvedValueOnce({
141
- type: 'DeviceFirmwareUpdateStatus',
142
- message: {
143
- records: [
144
- {
145
- target_id: 4,
146
- status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
147
- },
148
- ],
149
- },
150
- });
151
- const call = jest.fn().mockResolvedValue({
152
- type: 'WriteCompleted',
153
- message: {},
154
- });
155
-
156
- method.device = {
157
- getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
158
- createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
159
- toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-usb' }),
160
- setCancelableAction: jest.fn(),
161
- clearCancelableAction: jest.fn(),
162
- } as unknown as Device;
163
- method.postMessage = jest.fn();
164
- method.postProgressMessage = jest.fn();
165
-
166
- const firmwareUpdate = method as unknown as {
167
- protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
168
- waitForProtocolV2FirmwareUpdateComplete: (
169
- value: typeof targets,
170
- requireCurrentInstallStatus: boolean
171
- ) => Promise<void>;
172
- };
173
-
174
- await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
175
- const requestOptions = call.mock.calls[0]?.[2] as {
176
- onResponseAfterWrite: (response: { type: 'Success'; message: Record<string, never> }) => void;
177
- };
178
- requestOptions.onResponseAfterWrite({ type: 'Success', message: {} });
179
- await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
180
-
181
- expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
182
- });
183
-
184
- test('reconnects USB when the link is released while writing the Request', async () => {
185
- const method = new FirmwareUpdateV4({
186
- id: 1,
187
- payload: {
188
- method: 'firmwareUpdateV4',
189
- connectId: 'pro2-usb',
190
- },
191
- });
192
- const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
193
- const typedCall = jest
194
- .fn()
195
- .mockResolvedValueOnce({ type: 'Success', message: {} })
196
- .mockResolvedValueOnce({
197
- type: 'DeviceFirmwareUpdateStatus',
198
- message: {
199
- records: [
200
- {
201
- target_id: 4,
202
- status: 'FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS',
203
- path: 'vol0:/application_p1.bin',
204
- },
205
- ],
206
- },
207
- })
208
- .mockResolvedValueOnce({
209
- type: 'DeviceFirmwareUpdateStatus',
210
- message: {
211
- records: [
212
- {
213
- target_id: 4,
214
- status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
215
- path: 'vol0:/application_p1.bin',
216
- },
217
- ],
218
- },
219
- });
220
- const call = jest.fn().mockRejectedValue(new Error('device was disconnected'));
221
-
222
- method.device = {
223
- getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
224
- createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
225
- toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-usb' }),
226
- setCancelableAction: jest.fn(),
227
- clearCancelableAction: jest.fn(),
228
- } as unknown as Device;
229
- method.postMessage = jest.fn();
230
- method.postProgressMessage = jest.fn();
231
-
232
- const firmwareUpdate = method as unknown as {
233
- protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
234
- waitForProtocolV2FirmwareUpdateComplete: (
235
- value: typeof targets,
236
- requireCurrentInstallStatus: boolean
237
- ) => Promise<void>;
238
- reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
239
- verifyProtocolV2ReconnectIdentity: () => Promise<Record<string, never>>;
240
- };
241
- firmwareUpdate.reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
242
- firmwareUpdate.verifyProtocolV2ReconnectIdentity = jest.fn().mockResolvedValue({});
243
- (method as any).isBleReconnect = jest.fn(() => false);
244
-
245
- await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
246
- await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
247
-
248
- expect(firmwareUpdate.reconnectProtocolV2Device).toHaveBeenCalledWith({
249
- skipProtocolProbe: true,
250
- });
251
- expect(firmwareUpdate.verifyProtocolV2ReconnectIdentity).toHaveBeenCalledTimes(1);
252
- expect(method.postProgressMessage).toHaveBeenCalledWith(1, 'installingFirmware');
253
- expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
254
- });
255
-
256
- test('writes the BLE Request and completes only from target status polling', async () => {
257
- const method = new FirmwareUpdateV4({
258
- id: 1,
259
- payload: {
260
- method: 'firmwareUpdateV4',
261
- connectId: 'pro2-ble',
262
- },
263
- });
264
- const targets = [{ target_id: 6, path: 'vol0:/coprocessor.bin' }];
265
- const typedCall = jest
266
- .fn()
267
- .mockResolvedValueOnce({ type: 'Success', message: {} })
268
- .mockResolvedValueOnce({
269
- type: 'DeviceFirmwareUpdateStatus',
270
- message: {
271
- records: [
272
- {
273
- target_id: 6,
274
- status: 'FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS',
275
- path: 'vol0:/coprocessor.bin',
276
- },
277
- ],
278
- },
279
- })
280
- .mockResolvedValueOnce({
281
- type: 'DeviceFirmwareUpdateStatus',
282
- message: {
283
- records: [
284
- {
285
- target_id: 6,
286
- status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
287
- path: 'vol0:/coprocessor.bin',
288
- },
289
- ],
290
- },
291
- });
292
- const call = jest.fn().mockResolvedValue({
293
- type: 'WriteCompleted',
294
- message: {},
295
- });
296
-
297
- method.device = {
298
- getCommands: () => ({ typedCall, call }),
299
- createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
300
- toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-ble' }),
301
- setCancelableAction: jest.fn(),
302
- clearCancelableAction: jest.fn(),
303
- } as unknown as Device;
304
- method.postMessage = jest.fn();
305
- method.postProgressMessage = jest.fn();
306
- (method as any).isBleReconnect = jest.fn(() => true);
307
-
308
- const firmwareUpdate = method as unknown as {
309
- protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
310
- waitForProtocolV2FirmwareUpdateComplete: (
311
- value: typeof targets,
312
- requireCurrentInstallStatus: boolean
313
- ) => Promise<void>;
314
- };
315
-
316
- await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
317
-
318
- expect(typedCall).toHaveBeenCalledTimes(1);
319
- expect(typedCall).toHaveBeenCalledWith('DeviceFirmwareUpdateStage', 'Success', { targets });
320
- expect(call).toHaveBeenCalledWith(
321
- 'DeviceFirmwareUpdateRequest',
322
- {},
323
- expect.objectContaining({
324
- returnAfterWrite: true,
325
- expectedTypes: ['Success'],
326
- onResponseAfterWrite: expect.any(Function),
327
- })
328
- );
329
- expect(method.postProgressMessage).not.toHaveBeenCalled();
330
-
331
- await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
332
-
333
- expect(typedCall.mock.calls[1]?.[0]).toBe('DeviceFirmwareUpdateStatusGet');
334
- expect(typedCall.mock.calls[1]?.[1]).toBe('DeviceFirmwareUpdateStatus');
335
- expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
336
- });
337
-
338
- test('accepts stable finished BLE status after an actual install disconnect hides in-progress', async () => {
339
- const method = new FirmwareUpdateV4({
340
- id: 1,
341
- payload: {
342
- method: 'firmwareUpdateV4',
343
- connectId: 'pro2-ble',
344
- },
345
- });
346
- const targets = [{ target_id: 6, path: 'vol0:/coprocessor.bin' }];
347
- const finishedStatus = {
348
- type: 'DeviceFirmwareUpdateStatus',
349
- message: {
350
- records: [
351
- {
352
- target_id: 6,
353
- status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
354
- payload_version: 65_556,
355
- path: 'vol0:/coprocessor.bin',
356
- },
357
- ],
358
- },
359
- };
360
- const typedCall = jest
361
- .fn()
362
- .mockResolvedValueOnce(finishedStatus)
363
- .mockImplementationOnce(() => {
364
- expect(method.postProgressMessage).not.toHaveBeenCalled();
365
- throw new Error('device was disconnected');
366
- })
367
- .mockResolvedValueOnce(finishedStatus)
368
- .mockImplementationOnce(() => {
369
- expect(method.postProgressMessage).toHaveBeenCalledTimes(1);
370
- expect(method.postProgressMessage).toHaveBeenCalledWith(1, 'installingFirmware');
371
- return finishedStatus;
372
- })
373
- .mockResolvedValueOnce(finishedStatus)
374
- .mockResolvedValueOnce(finishedStatus)
375
- .mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
376
- const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
377
-
378
- (method as any).params = {
379
- expectedTargetVersions: { coprocessor: '1.0.20' },
380
- };
381
-
382
- method.device = {
383
- getCommands: () => ({ typedCall }),
384
- setCancelableAction: jest.fn(),
385
- } as unknown as Device;
386
- method.postProgressMessage = jest.fn();
387
-
388
- const firmwareUpdate = method as unknown as {
389
- waitForProtocolV2FirmwareUpdateComplete: (
390
- value: typeof targets,
391
- requireCurrentInstallStatus: boolean
392
- ) => Promise<void>;
393
- reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
394
- };
395
- firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
396
- (method as any).isBleReconnect = jest.fn(() => true);
397
-
398
- await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
399
-
400
- expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
401
- expect(typedCall).toHaveBeenCalledTimes(6);
402
- expect(method.postProgressMessage).toHaveBeenNthCalledWith(1, 1, 'installingFirmware');
403
- expect(method.postProgressMessage).toHaveBeenNthCalledWith(2, 100, 'installingFirmware');
404
- expect(method.postProgressMessage).toHaveBeenCalledTimes(2);
405
- }, 10_000);
406
-
407
- test('rejects stable stale finished BLE status after a status response timeout', async () => {
408
- const method = new FirmwareUpdateV4({
409
- id: 1,
410
- payload: {
411
- method: 'firmwareUpdateV4',
412
- connectId: 'pro2-ble',
413
- },
414
- });
415
- const targets = [{ target_id: 6, path: 'vol0:/coprocessor.bin' }];
416
- const finishedStatus = {
417
- type: 'DeviceFirmwareUpdateStatus',
418
- message: {
419
- records: [
420
- {
421
- target_id: 6,
422
- status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
423
- payload_version: 65_556,
424
- path: 'vol0:/coprocessor.bin',
425
- },
426
- ],
427
- },
428
- };
429
- const typedCall = jest
430
- .fn()
431
- .mockResolvedValueOnce(finishedStatus)
432
- .mockRejectedValueOnce(
433
- ERRORS.TypedError(
434
- HardwareErrorCode.BleTimeoutError,
435
- 'Lowlevel response timeout after 15000ms for DeviceFirmwareUpdateStatusGet'
436
- )
437
- )
438
- .mockResolvedValueOnce(finishedStatus)
439
- .mockResolvedValueOnce(finishedStatus)
440
- .mockResolvedValueOnce(finishedStatus)
441
- .mockResolvedValueOnce(finishedStatus)
442
- .mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
443
- const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
444
-
445
- (method as any).params = {
446
- expectedTargetVersions: { coprocessor: '1.0.20' },
447
- };
448
- method.device = {
449
- getCommands: () => ({ typedCall }),
450
- setCancelableAction: jest.fn(),
451
- } as unknown as Device;
452
- method.postProgressMessage = jest.fn();
453
-
454
- const firmwareUpdate = method as unknown as {
455
- waitForProtocolV2FirmwareUpdateComplete: (
456
- value: typeof targets,
457
- requireCurrentInstallStatus: boolean
458
- ) => Promise<void>;
459
- reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
460
- };
461
- firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
462
- (method as any).isBleReconnect = jest.fn(() => true);
463
-
464
- await expect(
465
- firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
466
- ).rejects.toMatchObject({
467
- errorCode: HardwareErrorCode.ActionCancelled,
468
- });
469
-
470
- expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
471
- expect(method.postProgressMessage).not.toHaveBeenCalled();
472
- }, 10_000);
473
-
474
- test('confirms App mode when BLE status becomes empty after current install progress', async () => {
475
- const method = new FirmwareUpdateV4({
476
- id: 1,
477
- payload: {
478
- method: 'firmwareUpdateV4',
479
- connectId: 'pro2-ble',
480
- },
481
- });
482
- const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
483
- const typedCall = jest
484
- .fn()
485
- .mockResolvedValueOnce({
486
- type: 'DeviceFirmwareUpdateStatus',
487
- message: {
488
- records: [
489
- {
490
- target_id: 4,
491
- status: 'FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS',
492
- path: 'vol0:/application_p1.bin',
493
- },
494
- ],
495
- },
496
- })
497
- .mockResolvedValueOnce({
498
- type: 'DeviceFirmwareUpdateStatus',
499
- message: { records: [] },
500
- });
501
- const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
502
- const deviceInfo = {};
503
- const verifyProtocolV2ReconnectIdentity = jest.fn().mockResolvedValue(deviceInfo);
504
- const probeProtocolV2NormalMode = jest.fn().mockResolvedValue(true);
505
-
506
- method.device = {
507
- getCommands: () => ({ typedCall }),
508
- } as unknown as Device;
509
- method.postProgressMessage = jest.fn();
510
-
511
- const firmwareUpdate = method as unknown as {
512
- protocolV2InstallNeedsReconnect: boolean;
513
- waitForProtocolV2FirmwareUpdateComplete: (
514
- value: typeof targets,
515
- requireCurrentInstallStatus: boolean
516
- ) => Promise<void>;
517
- reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
518
- verifyProtocolV2ReconnectIdentity: () => Promise<typeof deviceInfo>;
519
- probeProtocolV2NormalMode: (value: typeof deviceInfo) => Promise<boolean>;
520
- };
521
- firmwareUpdate.protocolV2InstallNeedsReconnect = true;
522
- firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
523
- firmwareUpdate.verifyProtocolV2ReconnectIdentity = verifyProtocolV2ReconnectIdentity;
524
- firmwareUpdate.probeProtocolV2NormalMode = probeProtocolV2NormalMode;
525
- (method as any).isBleReconnect = jest.fn(() => true);
526
-
527
- await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
528
-
529
- expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
530
- expect(verifyProtocolV2ReconnectIdentity).toHaveBeenCalledTimes(1);
531
- expect(probeProtocolV2NormalMode).toHaveBeenCalledWith(deviceInfo);
532
- expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
533
74
  });
534
75
 
535
76
  test('does not send Request when Stage is rejected', async () => {
@@ -542,9 +83,10 @@ describe('FirmwareUpdateV4 install polling', () => {
542
83
  });
543
84
  const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
544
85
  const typedCall = jest.fn().mockRejectedValue(new Error('stage rejected'));
86
+ const call = jest.fn();
545
87
 
546
88
  method.device = {
547
- getCommands: () => ({ typedCall }),
89
+ getCommands: () => ({ typedCall, call }),
548
90
  } as unknown as Device;
549
91
 
550
92
  await expect(
@@ -555,61 +97,7 @@ describe('FirmwareUpdateV4 install polling', () => {
555
97
  ).protocolV2StartFirmwareUpdate({ targets })
556
98
  ).rejects.toThrow('stage rejected');
557
99
 
558
- expect(typedCall).toHaveBeenCalledTimes(1);
559
- });
560
-
561
- test('does not enter install state when the device cancels the Request', async () => {
562
- const method = new FirmwareUpdateV4({
563
- id: 1,
564
- payload: {
565
- method: 'firmwareUpdateV4',
566
- connectId: 'pro2-usb',
567
- },
568
- });
569
- const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
570
- const actionCancelledError = ERRORS.TypedError(HardwareErrorCode.ActionCancelled);
571
- const typedCall = jest.fn().mockImplementation((type: string) => {
572
- if (type === 'DeviceFirmwareUpdateStatusGet') {
573
- return Promise.reject(actionCancelledError);
574
- }
575
- return Promise.resolve({ type: 'Success', message: {} });
576
- });
577
- const call = jest.fn().mockResolvedValue({
578
- type: 'WriteCompleted',
579
- message: {},
580
- });
581
-
582
- method.device = {
583
- getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
584
- createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
585
- toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-usb' }),
586
- setCancelableAction: jest.fn(),
587
- clearCancelableAction: jest.fn(),
588
- } as unknown as Device;
589
- method.postMessage = jest.fn();
590
- method.postProgressMessage = jest.fn();
591
-
592
- const firmwareUpdate = method as unknown as {
593
- protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
594
- waitForProtocolV2FirmwareUpdateComplete: (
595
- value: typeof targets,
596
- requireCurrentInstallStatus: boolean
597
- ) => Promise<void>;
598
- };
599
-
600
- await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
601
- await expect(
602
- firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
603
- ).rejects.toMatchObject({
604
- errorCode: HardwareErrorCode.ActionCancelled,
605
- });
606
-
607
- expect(call).toHaveBeenCalledWith(
608
- 'DeviceFirmwareUpdateRequest',
609
- {},
610
- expect.objectContaining({ returnAfterWrite: true })
611
- );
612
- expect(method.postProgressMessage).not.toHaveBeenCalled();
100
+ expect(call).not.toHaveBeenCalled();
613
101
  });
614
102
 
615
103
  test('does not hide an explicit workflow cancellation during status polling', async () => {