diff --git a/secant/Features/App/App.swift b/secant/Features/App/App.swift index f14557e..df133ee 100644 --- a/secant/Features/App/App.swift +++ b/secant/Features/App/App.swift @@ -308,9 +308,9 @@ extension AppReducer { } catch WalletStorage.WalletStorageError.uninitializedWallet { do { // TODO: replace the hardcoded network with the environmental value, issue 239 (https://github.com/zcash/secant-ios-wallet/issues/239) - _ = try environment.databaseFiles.areDbFilesPresentFor("mainnet") - - return .keysMissing + if try environment.databaseFiles.areDbFilesPresentFor("mainnet") { + return .keysMissing + } } catch { return .uninitialized } diff --git a/secantTests/AppReducer/AppReducerTests.swift b/secantTests/AppReducer/AppReducerTests.swift index 192a5f9..08e8873 100644 --- a/secantTests/AppReducer/AppReducerTests.swift +++ b/secantTests/AppReducer/AppReducerTests.swift @@ -34,7 +34,7 @@ class AppReducerTests: XCTestCase { XCTAssertEqual(walletState, .uninitialized) } - func testWalletInitializationState_KeysMissing() throws { + func testWalletInitializationState_FilesPresentKeysMissing() throws { let wfmMock = WrappedFileManager( url: { _, _, _, _ in URL(fileURLWithPath: "") }, fileExists: { _ in return true }, @@ -54,6 +54,26 @@ class AppReducerTests: XCTestCase { XCTAssertEqual(walletState, .keysMissing) } + func testWalletInitializationState_FilesMissingKeysMissing() throws { + let wfmMock = WrappedFileManager( + url: { _, _, _, _ in URL(fileURLWithPath: "") }, + fileExists: { _ in return false }, + removeItem: { _ in } + ) + + let keysMissingEnvironment = AppEnvironment( + databaseFiles: .live(databaseFiles: DatabaseFiles(fileManager: wfmMock)), + scheduler: Self.testScheduler.eraseToAnyScheduler(), + mnemonicSeedPhraseProvider: .mock, + walletStorage: .throwing, + wrappedDerivationTool: .live() + ) + + let walletState = AppReducer.walletInitializationState(keysMissingEnvironment) + + XCTAssertEqual(walletState, .uninitialized) + } + // TODO: - Implement testWalletInitializationState_FilesMissing when WalletStorage mock is available, issue 231 (https://github.com/zcash/secant-ios-wallet/issues/231) // TODO: - Implement testWalletInitializationState_Initialized when WalletStorage mock is available, issue 231 (https://github.com/zcash/secant-ios-wallet/issues/231)