From 22fe8d1c332f582a1ab5f590f3ecabb153b5bca3 Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Wed, 10 Jun 2026 10:02:29 +0200 Subject: [PATCH] test: cover recheckDeviceStatus catch branch when acquireWallet throws --- .../bloc/connect_bitbox_cubit_test.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/screens/hardware_connect_bitbox/bloc/connect_bitbox_cubit_test.dart b/test/screens/hardware_connect_bitbox/bloc/connect_bitbox_cubit_test.dart index 2d2b0a98..f419237d 100644 --- a/test/screens/hardware_connect_bitbox/bloc/connect_bitbox_cubit_test.dart +++ b/test/screens/hardware_connect_bitbox/bloc/connect_bitbox_cubit_test.dart @@ -549,6 +549,36 @@ void main() { expect(cubit.state, isA()); }); + test('recheckDeviceStatus falls back to NotConnected when acquireWallet throws', () async { + var pollCount = 0; + when(() => service.getAllUsbDevices()).thenAnswer((_) async => [device]); + when(() => service.init(any())).thenAnswer((_) async => true); + when(() => service.getChannelHash()).thenAnswer((_) async { + pollCount++; + return pollCount < 3 ? '' : 'HASH-ok'; + }); + when(() => service.confirmPairing()).thenAnswer((_) async {}); + // First call: device unseeded → BitboxNotInitialized. + // Second call (recheckDeviceStatus): device now seeded, but wallet + // acquisition fails → catch block must emit BitboxNotConnected. + var statusCalls = 0; + when(() => service.getDeviceStatus()).thenAnswer((_) async { + statusCalls++; + return statusCalls == 1 ? 'uninitialized' : 'initialized'; + }); + when(() => walletService.createBitboxWallet(any())).thenThrow(Exception('wallet boom')); + + final cubit = makeCubit(); + addTearDown(cubit.close); + + await waitForState(cubit); + await cubit.confirmPairing(); + expect(cubit.state, isA()); + + await cubit.recheckDeviceStatus(); + expect(cubit.state, isA()); + }); + // Fail-open guarantee: a failing status read must NOT block a device that // would otherwise pair. If getDeviceStatus throws, the flow falls through to // the normal acquire path and still reaches BitboxConnected — the new gate