@onekeyfe/hd-core 1.2.2-alpha.1 → 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.
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +4 -20
- package/__tests__/DeviceCommands.test.ts +0 -13
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/check-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/device-lifecycle-events.test.ts +0 -19
- package/__tests__/deviceUploadNft.test.ts +0 -68
- package/__tests__/evmSignTypedData.test.ts +0 -42
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -825
- package/__tests__/open-wallet-session.test.ts +1 -127
- package/__tests__/protocol-v2-resources.test.ts +4 -7
- package/__tests__/protocol-v2-unlock-policy.test.ts +1 -35
- package/__tests__/protocol-v2.test.ts +27 -710
- package/dist/api/FirmwareUpdateV4.d.ts +0 -4
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +2 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +0 -3
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +5 -21
- package/dist/index.js +402 -1136
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -2
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +0 -3
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/settings.d.ts +2 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -3
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +75 -434
- package/src/api/OpenWalletSession.ts +9 -39
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +1 -2
- package/src/api/evm/EVMSignTypedData.ts +0 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -9
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +1 -7
- package/src/api/protocol-v2/DeviceUploadNft.ts +8 -31
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -27
- package/src/api/protocol-v2/helpers.ts +0 -8
- package/src/core/index.ts +10 -121
- package/src/data/messages/messages-protocol-v2.json +1 -111
- package/src/device/Device.ts +1 -3
- package/src/device/DeviceConnector.ts +3 -7
- package/src/events/ui-request.ts +0 -3
- package/src/protocols/protocol-v2/resources.ts +1 -9
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -8
- package/src/protocols/protocol-v2/walletSession.ts +22 -65
- package/src/types/settings.ts +2 -4
- package/src/utils/deviceFeaturesUtils.ts +0 -4
- package/__tests__/pro2HostAssetPackage.test.ts +0 -58
- package/dist/utils/pro2HostAssetPackage.d.ts +0 -8
- package/dist/utils/pro2HostAssetPackage.d.ts.map +0 -1
- package/src/utils/pro2HostAssetPackage.ts +0 -354
|
@@ -14,39 +14,18 @@ describe('FirmwareUpdateV4 install polling', () => {
|
|
|
14
14
|
jest.restoreAllMocks();
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
test('
|
|
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-
|
|
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
|
|
44
|
+
getCommands: () => ({ typedCall, call }),
|
|
70
45
|
createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
|
|
71
|
-
toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-
|
|
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,759 +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
|
-
|
|
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.each([
|
|
339
|
-
{
|
|
340
|
-
component: 'boot',
|
|
341
|
-
targets: [{ target_id: 3, path: 'vol0:/bootloader.bin' }],
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
component: 'P1',
|
|
345
|
-
targets: [{ target_id: 4, path: 'vol0:/application_p1.bin' }],
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
component: 'P2',
|
|
349
|
-
targets: [{ target_id: 5, path: 'vol0:/application_p2.bin' }],
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
component: 'coprocessor',
|
|
353
|
-
targets: [{ target_id: 6, path: 'vol0:/coprocessor.bin' }],
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
component: 'SE',
|
|
357
|
-
targets: [
|
|
358
|
-
{ target_id: 7, path: 'vol0:/se01.bin' },
|
|
359
|
-
{ target_id: 8, path: 'vol0:/se02.bin' },
|
|
360
|
-
{ target_id: 9, path: 'vol0:/se03.bin' },
|
|
361
|
-
{ target_id: 10, path: 'vol0:/se04.bin' },
|
|
362
|
-
],
|
|
363
|
-
},
|
|
364
|
-
])(
|
|
365
|
-
'accepts stable finished BLE status for $component after an actual install disconnect hides in-progress',
|
|
366
|
-
async ({ targets }) => {
|
|
367
|
-
const method = new FirmwareUpdateV4({
|
|
368
|
-
id: 1,
|
|
369
|
-
payload: {
|
|
370
|
-
method: 'firmwareUpdateV4',
|
|
371
|
-
connectId: 'pro2-ble',
|
|
372
|
-
},
|
|
373
|
-
});
|
|
374
|
-
const finishedStatus = {
|
|
375
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
376
|
-
message: {
|
|
377
|
-
records: targets.map(target => ({
|
|
378
|
-
...target,
|
|
379
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
380
|
-
})),
|
|
381
|
-
},
|
|
382
|
-
};
|
|
383
|
-
const typedCall = jest
|
|
384
|
-
.fn()
|
|
385
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
386
|
-
.mockImplementationOnce(() => {
|
|
387
|
-
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
388
|
-
throw new Error('device was disconnected');
|
|
389
|
-
})
|
|
390
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
391
|
-
.mockImplementationOnce(() => {
|
|
392
|
-
expect(method.postProgressMessage).toHaveBeenCalledTimes(1);
|
|
393
|
-
expect(method.postProgressMessage).toHaveBeenCalledWith(1, 'installingFirmware');
|
|
394
|
-
return finishedStatus;
|
|
395
|
-
})
|
|
396
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
397
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
398
|
-
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
399
|
-
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
400
|
-
|
|
401
|
-
method.device = {
|
|
402
|
-
getCommands: () => ({ typedCall }),
|
|
403
|
-
setCancelableAction: jest.fn(),
|
|
404
|
-
} as unknown as Device;
|
|
405
|
-
method.postProgressMessage = jest.fn();
|
|
406
|
-
|
|
407
|
-
const firmwareUpdate = method as unknown as {
|
|
408
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
409
|
-
value: typeof targets,
|
|
410
|
-
requireCurrentInstallStatus: boolean
|
|
411
|
-
) => Promise<void>;
|
|
412
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
413
|
-
};
|
|
414
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
415
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
416
|
-
|
|
417
|
-
await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
418
|
-
|
|
419
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
420
|
-
expect(typedCall).toHaveBeenCalledTimes(6);
|
|
421
|
-
expect(method.postProgressMessage).toHaveBeenNthCalledWith(1, 1, 'installingFirmware');
|
|
422
|
-
expect(method.postProgressMessage).toHaveBeenNthCalledWith(2, 100, 'installingFirmware');
|
|
423
|
-
expect(method.postProgressMessage).toHaveBeenCalledTimes(2);
|
|
424
|
-
},
|
|
425
|
-
10_000
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
test('uses a real BLE disconnect while writing the Request as install evidence', async () => {
|
|
429
|
-
const method = new FirmwareUpdateV4({
|
|
430
|
-
id: 1,
|
|
431
|
-
payload: {
|
|
432
|
-
method: 'firmwareUpdateV4',
|
|
433
|
-
connectId: 'pro2-ble',
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
const targets = [{ target_id: 3, path: 'vol0:/bootloader.bin' }];
|
|
437
|
-
const finishedStatus = {
|
|
438
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
439
|
-
message: {
|
|
440
|
-
records: [
|
|
441
|
-
{
|
|
442
|
-
...targets[0],
|
|
443
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
444
|
-
},
|
|
445
|
-
],
|
|
446
|
-
},
|
|
447
|
-
};
|
|
448
|
-
const typedCall = jest
|
|
449
|
-
.fn()
|
|
450
|
-
.mockResolvedValueOnce({ type: 'Success', message: {} })
|
|
451
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
452
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
453
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
454
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
455
|
-
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
456
|
-
const call = jest.fn().mockRejectedValue(ERRORS.TypedError(HardwareErrorCode.BleTimeoutError));
|
|
457
|
-
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
458
|
-
|
|
459
|
-
method.device = {
|
|
460
|
-
getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
|
|
461
|
-
createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
|
|
462
|
-
toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-ble' }),
|
|
463
|
-
setCancelableAction: jest.fn(),
|
|
464
|
-
clearCancelableAction: jest.fn(),
|
|
465
|
-
} as unknown as Device;
|
|
466
|
-
method.postMessage = jest.fn();
|
|
467
|
-
method.postProgressMessage = jest.fn();
|
|
468
|
-
|
|
469
|
-
const firmwareUpdate = method as unknown as {
|
|
470
|
-
protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
|
|
471
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
472
|
-
value: typeof targets,
|
|
473
|
-
requireCurrentInstallStatus: boolean
|
|
474
|
-
) => Promise<void>;
|
|
475
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
476
|
-
};
|
|
477
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
478
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
479
|
-
|
|
480
|
-
await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
|
|
481
|
-
await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
482
|
-
|
|
483
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
484
|
-
expect(method.postProgressMessage).toHaveBeenNthCalledWith(1, 1, 'installingFirmware');
|
|
485
|
-
expect(method.postProgressMessage).toHaveBeenNthCalledWith(2, 100, 'installingFirmware');
|
|
486
|
-
expect(typedCall).toHaveBeenCalledTimes(5);
|
|
487
|
-
}, 10_000);
|
|
488
|
-
|
|
489
|
-
test('does not use a Request response timeout as BLE install evidence', async () => {
|
|
490
|
-
const method = new FirmwareUpdateV4({
|
|
491
|
-
id: 1,
|
|
492
|
-
payload: {
|
|
493
|
-
method: 'firmwareUpdateV4',
|
|
494
|
-
connectId: 'pro2-ble',
|
|
495
|
-
},
|
|
496
|
-
});
|
|
497
|
-
const targets = [{ target_id: 3, path: 'vol0:/bootloader.bin' }];
|
|
498
|
-
const finishedStatus = {
|
|
499
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
500
|
-
message: {
|
|
501
|
-
records: [
|
|
502
|
-
{
|
|
503
|
-
...targets[0],
|
|
504
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
505
|
-
},
|
|
506
|
-
],
|
|
507
|
-
},
|
|
508
|
-
};
|
|
509
|
-
const typedCall = jest
|
|
510
|
-
.fn()
|
|
511
|
-
.mockResolvedValueOnce({ type: 'Success', message: {} })
|
|
512
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
513
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
514
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
515
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
516
|
-
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
517
|
-
const call = jest
|
|
518
|
-
.fn()
|
|
519
|
-
.mockRejectedValue(
|
|
520
|
-
ERRORS.TypedError(
|
|
521
|
-
HardwareErrorCode.BleTimeoutError,
|
|
522
|
-
'device was disconnected after Lowlevel response timeout'
|
|
523
|
-
)
|
|
524
|
-
);
|
|
525
|
-
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
526
|
-
|
|
527
|
-
method.device = {
|
|
528
|
-
getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
|
|
529
|
-
createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
|
|
530
|
-
toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-ble' }),
|
|
531
|
-
setCancelableAction: jest.fn(),
|
|
532
|
-
clearCancelableAction: jest.fn(),
|
|
533
|
-
} as unknown as Device;
|
|
534
|
-
method.postMessage = jest.fn();
|
|
535
|
-
method.postProgressMessage = jest.fn();
|
|
536
|
-
|
|
537
|
-
const firmwareUpdate = method as unknown as {
|
|
538
|
-
protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
|
|
539
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
540
|
-
value: typeof targets,
|
|
541
|
-
requireCurrentInstallStatus: boolean
|
|
542
|
-
) => Promise<void>;
|
|
543
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
544
|
-
};
|
|
545
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
546
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
547
|
-
|
|
548
|
-
await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
|
|
549
|
-
await expect(
|
|
550
|
-
firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
|
|
551
|
-
).rejects.toMatchObject({
|
|
552
|
-
errorCode: HardwareErrorCode.ActionCancelled,
|
|
553
|
-
});
|
|
554
|
-
|
|
555
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
556
|
-
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
557
|
-
}, 10_000);
|
|
558
|
-
|
|
559
|
-
test('records a real BLE disconnect that occurs during install reconnect', async () => {
|
|
560
|
-
const method = new FirmwareUpdateV4({
|
|
561
|
-
id: 1,
|
|
562
|
-
payload: {
|
|
563
|
-
method: 'firmwareUpdateV4',
|
|
564
|
-
connectId: 'pro2-ble',
|
|
565
|
-
},
|
|
566
|
-
});
|
|
567
|
-
const targets = [{ target_id: 3, path: 'vol0:/bootloader.bin' }];
|
|
568
|
-
const finishedStatus = {
|
|
569
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
570
|
-
message: {
|
|
571
|
-
records: [
|
|
572
|
-
{
|
|
573
|
-
...targets[0],
|
|
574
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
575
|
-
},
|
|
576
|
-
],
|
|
577
|
-
},
|
|
578
|
-
};
|
|
579
|
-
const typedCall = jest
|
|
580
|
-
.fn()
|
|
581
|
-
.mockRejectedValueOnce(
|
|
582
|
-
ERRORS.TypedError(
|
|
583
|
-
HardwareErrorCode.BleTimeoutError,
|
|
584
|
-
'Lowlevel response timeout after 15000ms for DeviceFirmwareUpdateStatusGet'
|
|
585
|
-
)
|
|
586
|
-
)
|
|
587
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
588
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
589
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
590
|
-
.mockResolvedValueOnce(finishedStatus);
|
|
591
|
-
const reconnectProtocolV2Device = jest
|
|
592
|
-
.fn()
|
|
593
|
-
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.BleTimeoutError))
|
|
594
|
-
.mockResolvedValueOnce(undefined);
|
|
595
|
-
const setTimeoutSpy = jest.spyOn(global, 'setTimeout').mockImplementation(((
|
|
596
|
-
callback: () => void
|
|
597
|
-
) => {
|
|
598
|
-
callback();
|
|
599
|
-
return 0 as any;
|
|
600
|
-
}) as typeof setTimeout);
|
|
601
|
-
|
|
602
|
-
method.device = {
|
|
603
|
-
getCommands: () => ({ typedCall, cancelDevice: jest.fn() }),
|
|
604
|
-
setCancelableAction: jest.fn(),
|
|
605
|
-
} as unknown as Device;
|
|
606
|
-
method.postProgressMessage = jest.fn();
|
|
607
|
-
|
|
608
|
-
const firmwareUpdate = method as unknown as {
|
|
609
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
610
|
-
value: typeof targets,
|
|
611
|
-
requireCurrentInstallStatus: boolean
|
|
612
|
-
) => Promise<void>;
|
|
613
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
614
|
-
};
|
|
615
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
616
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
617
|
-
|
|
618
|
-
try {
|
|
619
|
-
await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
620
|
-
} finally {
|
|
621
|
-
setTimeoutSpy.mockRestore();
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledTimes(2);
|
|
625
|
-
expect(method.postProgressMessage).toHaveBeenNthCalledWith(1, 1, 'installingFirmware');
|
|
626
|
-
expect(method.postProgressMessage).toHaveBeenNthCalledWith(2, 100, 'installingFirmware');
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
test('does not use a reconnect response timeout as BLE install evidence', async () => {
|
|
630
|
-
const method = new FirmwareUpdateV4({
|
|
631
|
-
id: 1,
|
|
632
|
-
payload: {
|
|
633
|
-
method: 'firmwareUpdateV4',
|
|
634
|
-
connectId: 'pro2-ble',
|
|
635
|
-
},
|
|
636
|
-
});
|
|
637
|
-
const targets = [{ target_id: 3, path: 'vol0:/bootloader.bin' }];
|
|
638
|
-
const finishedStatus = {
|
|
639
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
640
|
-
message: {
|
|
641
|
-
records: [
|
|
642
|
-
{
|
|
643
|
-
...targets[0],
|
|
644
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
645
|
-
},
|
|
646
|
-
],
|
|
647
|
-
},
|
|
648
|
-
};
|
|
649
|
-
const typedCall = jest
|
|
650
|
-
.fn()
|
|
651
|
-
.mockRejectedValueOnce(
|
|
652
|
-
ERRORS.TypedError(
|
|
653
|
-
HardwareErrorCode.BleTimeoutError,
|
|
654
|
-
'Lowlevel response timeout after 15000ms for DeviceFirmwareUpdateStatusGet'
|
|
655
|
-
)
|
|
656
|
-
)
|
|
657
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
658
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
659
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
660
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
661
|
-
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
662
|
-
const reconnectProtocolV2Device = jest
|
|
663
|
-
.fn()
|
|
664
|
-
.mockRejectedValueOnce(
|
|
665
|
-
ERRORS.TypedError(
|
|
666
|
-
HardwareErrorCode.BleTimeoutError,
|
|
667
|
-
'device was disconnected after Lowlevel response timeout'
|
|
668
|
-
)
|
|
669
|
-
)
|
|
670
|
-
.mockResolvedValueOnce(undefined);
|
|
671
|
-
const setTimeoutSpy = jest.spyOn(global, 'setTimeout').mockImplementation(((
|
|
672
|
-
callback: () => void
|
|
673
|
-
) => {
|
|
674
|
-
callback();
|
|
675
|
-
return 0 as any;
|
|
676
|
-
}) as typeof setTimeout);
|
|
677
|
-
|
|
678
|
-
method.device = {
|
|
679
|
-
getCommands: () => ({ typedCall, cancelDevice: jest.fn() }),
|
|
680
|
-
setCancelableAction: jest.fn(),
|
|
681
|
-
} as unknown as Device;
|
|
682
|
-
method.postProgressMessage = jest.fn();
|
|
683
|
-
|
|
684
|
-
const firmwareUpdate = method as unknown as {
|
|
685
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
686
|
-
value: typeof targets,
|
|
687
|
-
requireCurrentInstallStatus: boolean
|
|
688
|
-
) => Promise<void>;
|
|
689
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
690
|
-
};
|
|
691
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
692
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
693
|
-
|
|
694
|
-
try {
|
|
695
|
-
await expect(
|
|
696
|
-
firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
|
|
697
|
-
).rejects.toMatchObject({
|
|
698
|
-
errorCode: HardwareErrorCode.ActionCancelled,
|
|
699
|
-
});
|
|
700
|
-
} finally {
|
|
701
|
-
setTimeoutSpy.mockRestore();
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledTimes(2);
|
|
705
|
-
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
test('rejects stable stale finished BLE status after a status response timeout', async () => {
|
|
709
|
-
const method = new FirmwareUpdateV4({
|
|
710
|
-
id: 1,
|
|
711
|
-
payload: {
|
|
712
|
-
method: 'firmwareUpdateV4',
|
|
713
|
-
connectId: 'pro2-ble',
|
|
714
|
-
},
|
|
715
|
-
});
|
|
716
|
-
const targets = [{ target_id: 6, path: 'vol0:/coprocessor.bin' }];
|
|
717
|
-
const finishedStatus = {
|
|
718
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
719
|
-
message: {
|
|
720
|
-
records: [
|
|
721
|
-
{
|
|
722
|
-
target_id: 6,
|
|
723
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
724
|
-
payload_version: 65_556,
|
|
725
|
-
path: 'vol0:/coprocessor.bin',
|
|
726
|
-
},
|
|
727
|
-
],
|
|
728
|
-
},
|
|
729
|
-
};
|
|
730
|
-
const typedCall = jest
|
|
731
|
-
.fn()
|
|
732
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
733
|
-
.mockRejectedValueOnce(
|
|
734
|
-
ERRORS.TypedError(
|
|
735
|
-
HardwareErrorCode.BleTimeoutError,
|
|
736
|
-
'Lowlevel response timeout after 15000ms for DeviceFirmwareUpdateStatusGet'
|
|
737
|
-
)
|
|
738
|
-
)
|
|
739
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
740
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
741
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
742
|
-
.mockResolvedValueOnce(finishedStatus)
|
|
743
|
-
.mockRejectedValueOnce(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
744
|
-
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
745
|
-
|
|
746
|
-
(method as any).params = {
|
|
747
|
-
expectedTargetVersions: { coprocessor: '1.0.20' },
|
|
748
|
-
};
|
|
749
|
-
method.device = {
|
|
750
|
-
getCommands: () => ({ typedCall }),
|
|
751
|
-
setCancelableAction: jest.fn(),
|
|
752
|
-
} as unknown as Device;
|
|
753
|
-
method.postProgressMessage = jest.fn();
|
|
754
|
-
|
|
755
|
-
const firmwareUpdate = method as unknown as {
|
|
756
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
757
|
-
value: typeof targets,
|
|
758
|
-
requireCurrentInstallStatus: boolean
|
|
759
|
-
) => Promise<void>;
|
|
760
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
761
|
-
};
|
|
762
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
763
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
764
|
-
|
|
765
|
-
await expect(
|
|
766
|
-
firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
|
|
767
|
-
).rejects.toMatchObject({
|
|
768
|
-
errorCode: HardwareErrorCode.ActionCancelled,
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
772
|
-
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
773
|
-
}, 10_000);
|
|
774
|
-
|
|
775
|
-
test('confirms App mode when BLE status becomes empty after current install progress', async () => {
|
|
776
|
-
const method = new FirmwareUpdateV4({
|
|
777
|
-
id: 1,
|
|
778
|
-
payload: {
|
|
779
|
-
method: 'firmwareUpdateV4',
|
|
780
|
-
connectId: 'pro2-ble',
|
|
781
|
-
},
|
|
782
|
-
});
|
|
783
|
-
const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
|
|
784
|
-
const typedCall = jest
|
|
785
|
-
.fn()
|
|
786
|
-
.mockResolvedValueOnce({
|
|
787
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
788
|
-
message: {
|
|
789
|
-
records: [
|
|
790
|
-
{
|
|
791
|
-
target_id: 4,
|
|
792
|
-
status: 'FW_MGMT_UPDATER_TASK_STATUS_IN_PROGRESS',
|
|
793
|
-
path: 'vol0:/application_p1.bin',
|
|
794
|
-
},
|
|
795
|
-
],
|
|
796
|
-
},
|
|
797
|
-
})
|
|
798
|
-
.mockResolvedValueOnce({
|
|
799
|
-
type: 'DeviceFirmwareUpdateStatus',
|
|
800
|
-
message: { records: [] },
|
|
801
|
-
});
|
|
802
|
-
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
803
|
-
const deviceInfo = {};
|
|
804
|
-
const verifyProtocolV2ReconnectIdentity = jest.fn().mockResolvedValue(deviceInfo);
|
|
805
|
-
const probeProtocolV2NormalMode = jest.fn().mockResolvedValue(true);
|
|
806
|
-
|
|
807
|
-
method.device = {
|
|
808
|
-
getCommands: () => ({ typedCall }),
|
|
809
|
-
} as unknown as Device;
|
|
810
|
-
method.postProgressMessage = jest.fn();
|
|
811
|
-
|
|
812
|
-
const firmwareUpdate = method as unknown as {
|
|
813
|
-
protocolV2InstallNeedsReconnect: boolean;
|
|
814
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
815
|
-
value: typeof targets,
|
|
816
|
-
requireCurrentInstallStatus: boolean
|
|
817
|
-
) => Promise<void>;
|
|
818
|
-
reconnectProtocolV2Device: (options: { skipProtocolProbe: boolean }) => Promise<void>;
|
|
819
|
-
verifyProtocolV2ReconnectIdentity: () => Promise<typeof deviceInfo>;
|
|
820
|
-
probeProtocolV2NormalMode: (value: typeof deviceInfo) => Promise<boolean>;
|
|
821
|
-
};
|
|
822
|
-
firmwareUpdate.protocolV2InstallNeedsReconnect = true;
|
|
823
|
-
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
824
|
-
firmwareUpdate.verifyProtocolV2ReconnectIdentity = verifyProtocolV2ReconnectIdentity;
|
|
825
|
-
firmwareUpdate.probeProtocolV2NormalMode = probeProtocolV2NormalMode;
|
|
826
|
-
(method as any).isBleReconnect = jest.fn(() => true);
|
|
827
|
-
|
|
828
|
-
await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
829
|
-
|
|
830
|
-
expect(reconnectProtocolV2Device).toHaveBeenCalledWith({ skipProtocolProbe: true });
|
|
831
|
-
expect(verifyProtocolV2ReconnectIdentity).toHaveBeenCalledTimes(1);
|
|
832
|
-
expect(probeProtocolV2NormalMode).toHaveBeenCalledWith(deviceInfo);
|
|
833
|
-
expect(method.postProgressMessage).toHaveBeenCalledWith(100, 'installingFirmware');
|
|
834
74
|
});
|
|
835
75
|
|
|
836
76
|
test('does not send Request when Stage is rejected', async () => {
|
|
@@ -843,9 +83,10 @@ describe('FirmwareUpdateV4 install polling', () => {
|
|
|
843
83
|
});
|
|
844
84
|
const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
|
|
845
85
|
const typedCall = jest.fn().mockRejectedValue(new Error('stage rejected'));
|
|
86
|
+
const call = jest.fn();
|
|
846
87
|
|
|
847
88
|
method.device = {
|
|
848
|
-
getCommands: () => ({ typedCall }),
|
|
89
|
+
getCommands: () => ({ typedCall, call }),
|
|
849
90
|
} as unknown as Device;
|
|
850
91
|
|
|
851
92
|
await expect(
|
|
@@ -856,61 +97,7 @@ describe('FirmwareUpdateV4 install polling', () => {
|
|
|
856
97
|
).protocolV2StartFirmwareUpdate({ targets })
|
|
857
98
|
).rejects.toThrow('stage rejected');
|
|
858
99
|
|
|
859
|
-
expect(
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
test('does not enter install state when the device cancels the Request', async () => {
|
|
863
|
-
const method = new FirmwareUpdateV4({
|
|
864
|
-
id: 1,
|
|
865
|
-
payload: {
|
|
866
|
-
method: 'firmwareUpdateV4',
|
|
867
|
-
connectId: 'pro2-usb',
|
|
868
|
-
},
|
|
869
|
-
});
|
|
870
|
-
const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
|
|
871
|
-
const actionCancelledError = ERRORS.TypedError(HardwareErrorCode.ActionCancelled);
|
|
872
|
-
const typedCall = jest.fn().mockImplementation((type: string) => {
|
|
873
|
-
if (type === 'DeviceFirmwareUpdateStatusGet') {
|
|
874
|
-
return Promise.reject(actionCancelledError);
|
|
875
|
-
}
|
|
876
|
-
return Promise.resolve({ type: 'Success', message: {} });
|
|
877
|
-
});
|
|
878
|
-
const call = jest.fn().mockResolvedValue({
|
|
879
|
-
type: 'WriteCompleted',
|
|
880
|
-
message: {},
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
method.device = {
|
|
884
|
-
getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
|
|
885
|
-
createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
|
|
886
|
-
toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-usb' }),
|
|
887
|
-
setCancelableAction: jest.fn(),
|
|
888
|
-
clearCancelableAction: jest.fn(),
|
|
889
|
-
} as unknown as Device;
|
|
890
|
-
method.postMessage = jest.fn();
|
|
891
|
-
method.postProgressMessage = jest.fn();
|
|
892
|
-
|
|
893
|
-
const firmwareUpdate = method as unknown as {
|
|
894
|
-
protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
|
|
895
|
-
waitForProtocolV2FirmwareUpdateComplete: (
|
|
896
|
-
value: typeof targets,
|
|
897
|
-
requireCurrentInstallStatus: boolean
|
|
898
|
-
) => Promise<void>;
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
|
|
902
|
-
await expect(
|
|
903
|
-
firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true)
|
|
904
|
-
).rejects.toMatchObject({
|
|
905
|
-
errorCode: HardwareErrorCode.ActionCancelled,
|
|
906
|
-
});
|
|
907
|
-
|
|
908
|
-
expect(call).toHaveBeenCalledWith(
|
|
909
|
-
'DeviceFirmwareUpdateRequest',
|
|
910
|
-
{},
|
|
911
|
-
expect.objectContaining({ returnAfterWrite: true })
|
|
912
|
-
);
|
|
913
|
-
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
100
|
+
expect(call).not.toHaveBeenCalled();
|
|
914
101
|
});
|
|
915
102
|
|
|
916
103
|
test('does not hide an explicit workflow cancellation during status polling', async () => {
|