@onekeyfe/hd-core 1.2.0-alpha.99 → 1.2.1-alpha.0
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 +20 -4
- package/__tests__/DeviceCommands.test.ts +203 -27
- package/__tests__/base64Data.test.ts +69 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +48 -2
- package/__tests__/check-firmware-release-protocol-v2.test.ts +82 -13
- package/__tests__/device-connector-protocol.test.ts +21 -0
- package/__tests__/device-lifecycle-events.test.ts +427 -7
- package/__tests__/device-pool-state.test.ts +25 -0
- package/__tests__/device-settings.test.ts +237 -9
- package/__tests__/device-state-events.test.ts +2 -2
- package/__tests__/device-state-mapper.test.ts +61 -5
- package/__tests__/device-utils.test.ts +15 -1
- package/__tests__/device-wallet-session-store.test.ts +147 -21
- package/__tests__/deviceSettings.test.ts +7 -3
- package/__tests__/deviceUploadNft.test.ts +36 -4
- package/__tests__/firmware-update/device-update-bootloader.test.ts +13 -3
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +61 -9
- package/__tests__/firmware-update/firmware-prepared-host-digest.test.ts +19 -9
- package/__tests__/firmware-update/firmware-prepared-resource-archive.test.ts +21 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +63 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +59 -55
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +19 -5
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +116 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +979 -0
- package/__tests__/firmware-update/firmware-update-v4-parameters.test.ts +85 -0
- package/__tests__/get-device-state.test.ts +60 -21
- package/__tests__/logBlockEvent.test.ts +13 -1
- package/__tests__/open-wallet-session.test.ts +127 -1
- package/__tests__/protocol-v2-firmware-targets.test.ts +23 -0
- package/__tests__/protocol-v2-resources.test.ts +185 -88
- package/__tests__/protocol-v2-unlock-policy.test.ts +235 -2
- package/__tests__/protocol-v2.test.ts +2199 -486
- package/__tests__/refresh-device-state.test.ts +3 -1
- package/__tests__/resourceBase64Boundary.test.ts +48 -0
- package/__tests__/search-devices.test.ts +79 -32
- package/__tests__/ton-sign-message.test.ts +84 -0
- package/dist/api/BaseMethod.d.ts +2 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +20 -6
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts +1 -0
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +5 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
- package/dist/api/firmware/FirmwarePreparedResourceArchive.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/FirmwareUpdatePlan.d.ts +0 -15
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +3 -2
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/protocolV2Release.d.ts.map +1 -1
- package/dist/api/helpers/base64Data.d.ts +16 -0
- package/dist/api/helpers/base64Data.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +3 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +2 -3
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +2 -3
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -3
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +16 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +3 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +54 -84
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2150 -1469
- package/dist/protocols/protocol-v2/features.d.ts +13 -5
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +2 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/resources.d.ts +12 -7
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +3 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +2 -2
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -1
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +3 -31
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +3 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +1 -0
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Nft.d.ts +7 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/api/BaseMethod.ts +8 -1
- package/src/api/CheckAllFirmwareRelease.ts +2 -4
- package/src/api/CheckBLEFirmwareRelease.ts +2 -2
- package/src/api/CheckBootloaderRelease.ts +3 -2
- package/src/api/CheckFirmwareRelease.ts +2 -2
- package/src/api/FirmwareUpdateV2.ts +12 -9
- package/src/api/FirmwareUpdateV3.ts +29 -19
- package/src/api/FirmwareUpdateV4.ts +934 -739
- package/src/api/OpenWalletSession.ts +39 -9
- package/src/api/PromptWebDeviceAccess.ts +2 -2
- package/src/api/SearchDevices.ts +6 -3
- package/src/api/UploadPortfolio.ts +9 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +2 -1
- package/src/api/device/DeviceChangePin.ts +4 -1
- package/src/api/device/DeviceRebootToBoardloader.ts +3 -1
- package/src/api/device/DeviceRebootToBootloader.ts +3 -1
- package/src/api/device/DeviceSettings.ts +34 -20
- package/src/api/device/DeviceVerify.ts +25 -0
- package/src/api/device/DeviceWipe.ts +4 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +41 -14
- package/src/api/firmware/FirmwarePreparedResourceArchive.ts +16 -27
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +9 -3
- package/src/api/firmware/FirmwareUpdatePlan.ts +37 -77
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +10 -6
- package/src/api/firmware/protocolV2Release.ts +7 -2
- package/src/api/helpers/base64Data.ts +85 -0
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +6 -28
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +7 -1
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
- package/src/api/protocol-v2/DeviceReboot.ts +5 -0
- package/src/api/protocol-v2/DeviceUploadNft.ts +61 -9
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +53 -19
- package/src/api/protocol-v2/helpers.ts +8 -0
- package/src/api/ton/TonSignMessage.ts +5 -3
- package/src/core/index.ts +264 -55
- package/src/data/messages/messages-protocol-v2.json +140 -13
- package/src/data-manager/DataManager.ts +46 -39
- package/src/data-manager/TransportManager.ts +3 -1
- package/src/device/Device.ts +210 -44
- package/src/device/DeviceCommands.ts +27 -18
- package/src/device/DeviceConnector.ts +17 -3
- package/src/device/DevicePool.ts +9 -2
- package/src/device/DeviceStateMapper.ts +30 -24
- package/src/deviceProfile/buildDeviceFeatures.ts +10 -5
- package/src/events/logBlockEvent.ts +14 -1
- package/src/events/ui-request.ts +3 -0
- package/src/index.ts +0 -10
- package/src/protocols/protocol-v2/features.ts +22 -5
- package/src/protocols/protocol-v2/index.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +110 -147
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +13 -1
- package/src/protocols/protocol-v2/walletSession.ts +65 -22
- package/src/types/api/firmwareUpdate.ts +1 -1
- package/src/types/api/firmwareUpdatePlan.ts +2 -2
- package/src/types/api/protocolV2.ts +1 -1
- package/src/types/device.ts +2 -1
- package/src/types/settings.ts +6 -34
- package/src/utils/deviceFeaturesCompat.ts +9 -4
- package/src/utils/deviceFeaturesUtils.ts +4 -0
- package/src/utils/deviceInfoUtils.ts +9 -2
- package/src/utils/deviceSettings.ts +11 -4
- package/src/utils/index.ts +1 -0
- package/src/utils/pro2Nft.ts +31 -8
- package/__tests__/firmware-memory-host.test.ts +0 -126
- package/dist/api/firmware/FirmwareMemoryHost.d.ts +0 -22
- package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +0 -1
- package/src/api/firmware/FirmwareMemoryHost.ts +0 -143
|
@@ -0,0 +1,979 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import FirmwareUpdateV4 from '../../src/api/FirmwareUpdateV4';
|
|
4
|
+
|
|
5
|
+
import type { Device } from '../../src/device/Device';
|
|
6
|
+
|
|
7
|
+
jest.mock('../../src/data/config', () => ({
|
|
8
|
+
DEFAULT_DOMAIN: 'https://example.com/',
|
|
9
|
+
getSDKVersion: () => '0.0.0-test',
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe('FirmwareUpdateV4 install polling', () => {
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
jest.restoreAllMocks();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('writes the USB Request before polling current install status', async () => {
|
|
18
|
+
const method = new FirmwareUpdateV4({
|
|
19
|
+
id: 1,
|
|
20
|
+
payload: {
|
|
21
|
+
method: 'firmwareUpdateV4',
|
|
22
|
+
connectId: 'pro2-usb',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
|
|
26
|
+
const typedCall = jest
|
|
27
|
+
.fn()
|
|
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
|
+
.mockResolvedValueOnce({
|
|
51
|
+
type: 'DeviceFirmwareUpdateStatus',
|
|
52
|
+
message: {
|
|
53
|
+
records: [
|
|
54
|
+
{
|
|
55
|
+
target_id: 4,
|
|
56
|
+
status: 'FW_MGMT_UPDATER_TASK_STATUS_FINISHED',
|
|
57
|
+
path: 'vol0:/application_p1.bin',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const call = jest.fn().mockResolvedValue({
|
|
63
|
+
type: 'WriteCompleted',
|
|
64
|
+
message: {},
|
|
65
|
+
});
|
|
66
|
+
const setCancelableAction = jest.fn();
|
|
67
|
+
|
|
68
|
+
method.device = {
|
|
69
|
+
getCommands: () => ({ typedCall, call, cancelDevice: jest.fn() }),
|
|
70
|
+
createProtocolV2UiPhaseMetadata: jest.fn().mockReturnValue(undefined),
|
|
71
|
+
toMessageObject: jest.fn().mockReturnValue({ connectId: 'pro2-usb' }),
|
|
72
|
+
setCancelableAction,
|
|
73
|
+
clearCancelableAction: jest.fn(),
|
|
74
|
+
} as unknown as Device;
|
|
75
|
+
method.postMessage = jest.fn();
|
|
76
|
+
method.postTipMessage = jest.fn();
|
|
77
|
+
method.postProgressMessage = jest.fn();
|
|
78
|
+
|
|
79
|
+
const firmwareUpdate = method as unknown as {
|
|
80
|
+
protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
|
|
81
|
+
waitForProtocolV2FirmwareUpdateComplete: (
|
|
82
|
+
value: typeof targets,
|
|
83
|
+
requireCurrentInstallStatus: boolean
|
|
84
|
+
) => Promise<void>;
|
|
85
|
+
reconnectProtocolV2Device: () => Promise<void>;
|
|
86
|
+
verifyProtocolV2ReconnectIdentity: () => Promise<Record<string, never>>;
|
|
87
|
+
};
|
|
88
|
+
firmwareUpdate.reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
89
|
+
firmwareUpdate.verifyProtocolV2ReconnectIdentity = jest.fn().mockResolvedValue({});
|
|
90
|
+
(method as any).isBleReconnect = jest.fn(() => false);
|
|
91
|
+
|
|
92
|
+
await firmwareUpdate.protocolV2StartFirmwareUpdate({ targets });
|
|
93
|
+
|
|
94
|
+
expect(typedCall.mock.calls[0]).toEqual(['DeviceFirmwareUpdateStage', 'Success', { targets }]);
|
|
95
|
+
expect(call).toHaveBeenCalledWith(
|
|
96
|
+
'DeviceFirmwareUpdateRequest',
|
|
97
|
+
{},
|
|
98
|
+
expect.objectContaining({
|
|
99
|
+
returnAfterWrite: true,
|
|
100
|
+
expectedTypes: ['Success'],
|
|
101
|
+
onResponseAfterWrite: expect.any(Function),
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
expect(method.postProgressMessage).not.toHaveBeenCalled();
|
|
105
|
+
|
|
106
|
+
await firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
107
|
+
|
|
108
|
+
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
|
+
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
|
+
});
|
|
835
|
+
|
|
836
|
+
test('does not send Request when Stage is rejected', async () => {
|
|
837
|
+
const method = new FirmwareUpdateV4({
|
|
838
|
+
id: 1,
|
|
839
|
+
payload: {
|
|
840
|
+
method: 'firmwareUpdateV4',
|
|
841
|
+
connectId: 'pro2-ble',
|
|
842
|
+
},
|
|
843
|
+
});
|
|
844
|
+
const targets = [{ target_id: 4, path: 'vol0:/application_p1.bin' }];
|
|
845
|
+
const typedCall = jest.fn().mockRejectedValue(new Error('stage rejected'));
|
|
846
|
+
|
|
847
|
+
method.device = {
|
|
848
|
+
getCommands: () => ({ typedCall }),
|
|
849
|
+
} as unknown as Device;
|
|
850
|
+
|
|
851
|
+
await expect(
|
|
852
|
+
(
|
|
853
|
+
method as unknown as {
|
|
854
|
+
protocolV2StartFirmwareUpdate: (params: { targets: typeof targets }) => Promise<void>;
|
|
855
|
+
}
|
|
856
|
+
).protocolV2StartFirmwareUpdate({ targets })
|
|
857
|
+
).rejects.toThrow('stage rejected');
|
|
858
|
+
|
|
859
|
+
expect(typedCall).toHaveBeenCalledTimes(1);
|
|
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();
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
test('does not hide an explicit workflow cancellation during status polling', async () => {
|
|
917
|
+
const method = new FirmwareUpdateV4({
|
|
918
|
+
id: 1,
|
|
919
|
+
payload: {
|
|
920
|
+
method: 'firmwareUpdateV4',
|
|
921
|
+
connectId: 'pro2-ble',
|
|
922
|
+
},
|
|
923
|
+
});
|
|
924
|
+
const abortController = new AbortController();
|
|
925
|
+
abortController.abort();
|
|
926
|
+
|
|
927
|
+
method.abortSignal = abortController.signal;
|
|
928
|
+
|
|
929
|
+
await expect(
|
|
930
|
+
(
|
|
931
|
+
method as unknown as {
|
|
932
|
+
waitForProtocolV2FirmwareUpdateComplete: (
|
|
933
|
+
targets: Array<{ target_id: number; path: string }>
|
|
934
|
+
) => Promise<void>;
|
|
935
|
+
}
|
|
936
|
+
).waitForProtocolV2FirmwareUpdateComplete([
|
|
937
|
+
{ target_id: 4, path: 'vol0:/application_p1.bin' },
|
|
938
|
+
])
|
|
939
|
+
).rejects.toMatchObject({
|
|
940
|
+
errorCode: HardwareErrorCode.CallQueueActionCancelled,
|
|
941
|
+
});
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
test('stops polling when the device cancels firmware installation', async () => {
|
|
945
|
+
const method = new FirmwareUpdateV4({
|
|
946
|
+
id: 1,
|
|
947
|
+
payload: {
|
|
948
|
+
method: 'firmwareUpdateV4',
|
|
949
|
+
connectId: 'pro2-ble',
|
|
950
|
+
},
|
|
951
|
+
});
|
|
952
|
+
const typedCall = jest
|
|
953
|
+
.fn()
|
|
954
|
+
.mockRejectedValue(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
|
|
955
|
+
const reconnectProtocolV2Device = jest.fn().mockResolvedValue(undefined);
|
|
956
|
+
|
|
957
|
+
method.device = {
|
|
958
|
+
getCommands: () => ({ typedCall }),
|
|
959
|
+
} as unknown as Device;
|
|
960
|
+
const firmwareUpdate = method as unknown as {
|
|
961
|
+
waitForProtocolV2FirmwareUpdateComplete: (
|
|
962
|
+
targets: Array<{ target_id: number; path: string }>
|
|
963
|
+
) => Promise<void>;
|
|
964
|
+
reconnectProtocolV2Device: () => Promise<void>;
|
|
965
|
+
};
|
|
966
|
+
firmwareUpdate.reconnectProtocolV2Device = reconnectProtocolV2Device;
|
|
967
|
+
|
|
968
|
+
await expect(
|
|
969
|
+
firmwareUpdate.waitForProtocolV2FirmwareUpdateComplete([
|
|
970
|
+
{ target_id: 4, path: 'vol0:/application_p1.bin' },
|
|
971
|
+
])
|
|
972
|
+
).rejects.toMatchObject({
|
|
973
|
+
errorCode: HardwareErrorCode.ActionCancelled,
|
|
974
|
+
});
|
|
975
|
+
|
|
976
|
+
expect(typedCall).toHaveBeenCalledTimes(1);
|
|
977
|
+
expect(reconnectProtocolV2Device).not.toHaveBeenCalled();
|
|
978
|
+
});
|
|
979
|
+
});
|