2022-07-21 10:30:02 -07:00
|
|
|
//
|
|
|
|
// SettingsTests.swift
|
|
|
|
// secantTests
|
|
|
|
//
|
|
|
|
// Created by Lukáš Korba on 21.07.2022.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
@testable import secant_testnet
|
|
|
|
import ComposableArchitecture
|
|
|
|
|
2022-08-17 06:23:31 -07:00
|
|
|
@MainActor
|
2022-07-21 10:30:02 -07:00
|
|
|
class SettingsTests: XCTestCase {
|
2022-08-17 06:23:31 -07:00
|
|
|
func testBackupWalletAccessRequest_AuthenticateSuccessPath() async throws {
|
2022-07-21 10:30:02 -07:00
|
|
|
let mnemonic =
|
|
|
|
"""
|
|
|
|
still champion voice habit trend flight \
|
|
|
|
survey between bitter process artefact blind \
|
|
|
|
carbon truly provide dizzy crush flush \
|
|
|
|
breeze blouse charge solid fish spread
|
|
|
|
"""
|
|
|
|
|
2022-11-17 03:25:55 -08:00
|
|
|
let mockedWalletStorage = WalletStorageClient(
|
2022-07-21 10:30:02 -07:00
|
|
|
importWallet: { _, _, _, _ in
|
|
|
|
throw WalletStorage.WalletStorageError.alreadyImported
|
|
|
|
},
|
|
|
|
exportWallet: {
|
|
|
|
StoredWallet(
|
|
|
|
language: .english,
|
2023-02-13 11:32:50 -08:00
|
|
|
seedPhrase: SeedPhrase(mnemonic),
|
2022-07-21 10:30:02 -07:00
|
|
|
version: 1,
|
|
|
|
hasUserPassedPhraseBackupTest: true
|
|
|
|
)
|
|
|
|
},
|
|
|
|
areKeysPresent: {
|
|
|
|
throw WalletStorage.WalletStorageError.uninitializedWallet
|
|
|
|
},
|
|
|
|
updateBirthday: { _ in
|
|
|
|
throw WalletStorage.KeychainError.encoding
|
|
|
|
},
|
2023-03-01 10:33:58 -08:00
|
|
|
markUserPassedPhraseBackupTest: { _ in
|
2022-07-21 10:30:02 -07:00
|
|
|
throw WalletStorage.KeychainError.encoding
|
|
|
|
},
|
|
|
|
nukeWallet: { }
|
|
|
|
)
|
|
|
|
|
|
|
|
let store = TestStore(
|
2023-02-15 13:18:18 -08:00
|
|
|
initialState: SettingsReducer.State(
|
2023-03-07 05:01:22 -08:00
|
|
|
exportLogsState: .placeholder,
|
2023-03-01 00:52:50 -08:00
|
|
|
isCrashReportingOn: false,
|
|
|
|
phraseDisplayState: RecoveryPhraseDisplayReducer.State(phrase: nil)
|
2023-02-15 13:18:18 -08:00
|
|
|
),
|
2022-11-05 00:16:10 -07:00
|
|
|
reducer: SettingsReducer()
|
2023-03-21 03:03:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
store.dependencies.localAuthentication = .mockAuthenticationSucceeded
|
|
|
|
store.dependencies.mnemonic = .noOp
|
|
|
|
store.dependencies.mnemonic.asWords = { _ in mnemonic.components(separatedBy: " ") }
|
|
|
|
store.dependencies.walletStorage = mockedWalletStorage
|
2022-11-17 03:25:55 -08:00
|
|
|
|
2023-02-27 04:55:47 -08:00
|
|
|
await store.send(.backupWalletAccessRequest)
|
2022-07-21 10:30:02 -07:00
|
|
|
|
2022-08-17 06:23:31 -07:00
|
|
|
await store.receive(.backupWallet) { state in
|
2023-02-13 11:32:50 -08:00
|
|
|
state.phraseDisplayState.phrase = RecoveryPhrase(words: mnemonic.components(separatedBy: " ").map { $0.redacted })
|
2022-07-21 10:30:02 -07:00
|
|
|
}
|
2022-12-01 06:31:30 -08:00
|
|
|
await store.receive(.updateDestination(.backupPhrase)) { state in
|
|
|
|
state.destination = .backupPhrase
|
2022-07-21 10:30:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 06:23:31 -07:00
|
|
|
func testBackupWalletAccessRequest_AuthenticateFailedPath() async throws {
|
2022-07-21 10:30:02 -07:00
|
|
|
let store = TestStore(
|
|
|
|
initialState: .placeholder,
|
2022-11-05 00:16:10 -07:00
|
|
|
reducer: SettingsReducer()
|
2023-03-21 03:03:42 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
store.dependencies.localAuthentication = .mockAuthenticationFailed
|
2022-11-14 10:36:51 -08:00
|
|
|
|
2023-02-27 04:55:47 -08:00
|
|
|
await store.send(.backupWalletAccessRequest)
|
2022-07-21 10:30:02 -07:00
|
|
|
|
2022-08-17 06:23:31 -07:00
|
|
|
await store.finish()
|
2022-07-21 10:30:02 -07:00
|
|
|
}
|
|
|
|
|
2023-02-01 00:08:22 -08:00
|
|
|
func testExportLogs_ButtonDisableShareEnable() async throws {
|
|
|
|
let store = TestStore(
|
|
|
|
initialState: SettingsReducer.State(
|
|
|
|
destination: nil,
|
2023-03-07 05:01:22 -08:00
|
|
|
exportLogsState: .placeholder,
|
2023-03-01 00:52:50 -08:00
|
|
|
isCrashReportingOn: false,
|
2023-03-02 06:24:32 -08:00
|
|
|
phraseDisplayState: .init()
|
2023-02-01 00:08:22 -08:00
|
|
|
),
|
|
|
|
reducer: SettingsReducer()
|
|
|
|
)
|
|
|
|
|
2023-03-22 06:38:10 -07:00
|
|
|
store.dependencies.logsHandler = LogsHandlerClient(exportAndStoreLogs: { nil })
|
2023-02-01 00:08:22 -08:00
|
|
|
|
2023-03-07 05:01:22 -08:00
|
|
|
await store.send(.exportLogs(.start)) { state in
|
|
|
|
state.exportLogsState.exportLogsDisabled = true
|
2023-02-01 00:08:22 -08:00
|
|
|
}
|
|
|
|
|
2023-03-22 06:38:10 -07:00
|
|
|
await store.receive(.exportLogs(.finished(nil))) { state in
|
2023-03-07 05:01:22 -08:00
|
|
|
state.exportLogsState.exportLogsDisabled = false
|
|
|
|
state.exportLogsState.isSharingLogs = true
|
2023-02-01 00:08:22 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testLogShareFinished() async throws {
|
|
|
|
let store = TestStore(
|
|
|
|
initialState: SettingsReducer.State(
|
|
|
|
destination: nil,
|
2023-03-07 05:01:22 -08:00
|
|
|
exportLogsState: ExportLogsReducer.State(
|
|
|
|
isSharingLogs: true
|
|
|
|
),
|
2023-03-01 00:52:50 -08:00
|
|
|
isCrashReportingOn: false,
|
2023-03-02 06:24:32 -08:00
|
|
|
phraseDisplayState: .init()
|
2023-02-01 00:08:22 -08:00
|
|
|
),
|
|
|
|
reducer: SettingsReducer()
|
|
|
|
)
|
|
|
|
|
2023-03-07 05:01:22 -08:00
|
|
|
await store.send(.exportLogs(.shareFinished)) { state in
|
|
|
|
state.exportLogsState.isSharingLogs = false
|
2023-02-01 00:08:22 -08:00
|
|
|
}
|
|
|
|
}
|
2022-07-21 10:30:02 -07:00
|
|
|
}
|