@onekeyfe/hd-transport-react-native 1.2.3-alpha.1 → 1.2.3-alpha.11

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.
@@ -1,3 +1,6 @@
1
+ import { Platform } from 'react-native';
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+
1
4
  import ReactNativeBleTransport, { PROTOCOL_REPROBE_FALLBACK_ATTEMPTS } from '../index';
2
5
  import protocolV1Schema from './protocolV1SchemaFixture';
3
6
 
@@ -89,7 +92,9 @@ describe('protocol re-probe after a known device goes away', () => {
89
92
  test('an unknown device still probes both protocols', async () => {
90
93
  const { transport, probeV1, probeV2 } = createHarness({ v1: false, v2: false });
91
94
 
92
- await expect(detect(transport)).rejects.toBeDefined();
95
+ await expect(detect(transport)).rejects.toMatchObject({
96
+ errorCode: HardwareErrorCode.BleTimeoutError,
97
+ });
93
98
 
94
99
  expect(probeV1).toHaveBeenCalledTimes(1);
95
100
  expect(probeV2).toHaveBeenCalledTimes(1);
@@ -154,3 +159,90 @@ describe('protocol re-probe after a known device goes away', () => {
154
159
  expect((known.transport as any).protocolReprobeFailures.get(UUID)).toBeUndefined();
155
160
  });
156
161
  });
162
+
163
+ describe('iOS reset-device stale bond confirmation', () => {
164
+ afterEach(() => {
165
+ Object.assign(Platform, { OS: 'ios' });
166
+ });
167
+
168
+ test('promotes a probe disconnect followed by a silent reconnect to BleBondInvalid', async () => {
169
+ const transport = new ReactNativeBleTransport({});
170
+ transport.configure(protocolV1Schema);
171
+ (transport as any).callProtocolV1 = jest
172
+ .fn()
173
+ .mockRejectedValue(ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded));
174
+
175
+ await expect(detect(transport)).rejects.toMatchObject({
176
+ errorCode: HardwareErrorCode.BleDeviceNotBonded,
177
+ });
178
+
179
+ (transport as any).probeProtocolV1 = jest.fn(() => Promise.resolve(false));
180
+ (transport as any).probeProtocolV2 = jest.fn(() => Promise.resolve(false));
181
+ (transport as any).resetProbeStateAfterProtocolProbe = jest.fn(() => Promise.resolve());
182
+
183
+ await expect(detect(transport)).rejects.toMatchObject({
184
+ errorCode: HardwareErrorCode.BleBondInvalid,
185
+ });
186
+ });
187
+
188
+ test('promotes a repeated iOS probe disconnect without waiting for probe timeouts', () => {
189
+ const { transport } = createHarness({ v1: false, v2: false });
190
+ const firstError = Object.assign(new Error('The specified device has disconnected from us'), {
191
+ errorCode: 201,
192
+ iosErrorCode: 7,
193
+ });
194
+ const secondError = ERRORS.TypedError(HardwareErrorCode.BleDeviceDisconnected);
195
+
196
+ expect(
197
+ (transport as any).rememberIosProbeDisconnect(UUID, 'protocol-v1-get-features', firstError)
198
+ ).toBeUndefined();
199
+ expect(
200
+ (transport as any).rememberIosProbeDisconnect(UUID, 'protocol-v2-ping', secondError)
201
+ ).toMatchObject({ errorCode: HardwareErrorCode.BleBondInvalid });
202
+ });
203
+
204
+ test('clears the disconnect evidence after a valid protocol response', async () => {
205
+ const { transport } = createHarness({ v1: true, v2: false });
206
+ (transport as any).rememberIosProbeDisconnect(
207
+ UUID,
208
+ 'protocol-v1-get-features',
209
+ ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded)
210
+ );
211
+
212
+ await expect(detect(transport)).resolves.toBe('V1');
213
+ expect((transport as any).iosProbeDisconnectEvidence.has(UUID)).toBe(false);
214
+ });
215
+
216
+ test('preserves evidence for acquire retry cleanup and clears it on an explicit disconnect', async () => {
217
+ const { transport } = createHarness({ v1: false, v2: false });
218
+ (transport as any).rememberIosProbeDisconnect(
219
+ UUID,
220
+ 'protocol-v1-get-features',
221
+ ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded)
222
+ );
223
+
224
+ await (transport as any).disconnectUnlocked(UUID, {
225
+ preserveIosProbeDisconnect: true,
226
+ });
227
+ expect((transport as any).iosProbeDisconnectEvidence.has(UUID)).toBe(true);
228
+
229
+ await (transport as any).disconnectUnlocked(UUID);
230
+ expect((transport as any).iosProbeDisconnectEvidence.has(UUID)).toBe(false);
231
+ });
232
+
233
+ test('does not classify the same sequence as a stale bond on Android', async () => {
234
+ Object.assign(Platform, { OS: 'android' });
235
+ const { transport } = createHarness({ v1: false, v2: false });
236
+
237
+ expect(
238
+ (transport as any).rememberIosProbeDisconnect(
239
+ UUID,
240
+ 'protocol-v1-get-features',
241
+ ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded)
242
+ )
243
+ ).toBeUndefined();
244
+ await expect(detect(transport)).rejects.toMatchObject({
245
+ errorCode: HardwareErrorCode.BleTimeoutError,
246
+ });
247
+ });
248
+ });