zashi-ios-wallet-private/secantTests/SettingsTests/SettingsTests.swift

230 lines
8.1 KiB
Swift
Raw Normal View History

//
// SettingsTests.swift
// secantTests
//
// Created by Lukáš Korba on 21.07.2022.
//
import XCTest
@testable import secant_testnet
import ComposableArchitecture
@MainActor
class SettingsTests: XCTestCase {
func testBackupWalletAccessRequest_AuthenticateSuccessPath() async throws {
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
"""
let mockedWalletStorage = WalletStorageClient(
importWallet: { _, _, _, _ in
throw WalletStorage.WalletStorageError.alreadyImported
},
exportWallet: {
StoredWallet(
language: .english,
seedPhrase: SeedPhrase(mnemonic),
version: 1,
hasUserPassedPhraseBackupTest: true
)
},
areKeysPresent: {
throw WalletStorage.WalletStorageError.uninitializedWallet
},
updateBirthday: { _ in
throw WalletStorage.KeychainError.encoding
},
markUserPassedPhraseBackupTest: {
throw WalletStorage.KeychainError.encoding
},
nukeWallet: { }
)
let store = TestStore(
Add crash reporter to secant (#531) * [#525] Adds functions to configure, testCrash and check if it can start. This adds a build phase where a dummy file is added to the project to make the build and Plist copy happy. When building in the CI there will be a script to replace this Plist file with the real one that then will be copied to the bundle Crashlytics will be "off" by default and then be turned on when starting up to be an Opt-Out thing. This is the only way it can be turned off later. reference: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#enable_opt-in_reporting The app will start with crash reporting turned off and will set it up on by default on the application's code. Then if the user wants to opt-out of crash reporting, it can. Otherwise, it won't be possible. Adds opting out of crash reporting as a stored user preference. This adds a value inside UserPreferencesStorage and its live and mock counterparts. also creates a builer for `CrashReporterClient` that has a Dependency to `@Dependency(\.userStoredPreferences)` and sets the references for the client to set the appropriate values into the user storage `UserPreferencesStorage` as been adapted to be a TCA Dependency. `SettingsStore` now as a `Toogle()` to turn off and on crash reporting. But it doesn't work yet because I haven't found out how to make a TCA Binding that can rely on an initial value that is not hardcoded but injected from somewhere else. See https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-1 https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-2 Adds Test Crash button and enable crash reporting Adds upload-symbols run script phase Closes #525 Add a custom build environment variable "UPLOAD_CRASHLYTICS_SYMBOLS" that will let Xcode skip the upload_symbols script for debug builds Fix Initialization tests * bump build
2023-02-15 13:18:18 -08:00
initialState: SettingsReducer.State(
phraseDisplayState: RecoveryPhraseDisplayReducer.State(phrase: nil),
isCrashReportingOn: false
),
reducer: SettingsReducer()
) { dependencies in
dependencies.localAuthentication = .mockAuthenticationSucceeded
dependencies.mnemonic = .noOp
dependencies.mnemonic.asWords = { _ in mnemonic.components(separatedBy: " ") }
dependencies.walletStorage = mockedWalletStorage
}
_ = await store.send(.backupWalletAccessRequest)
await store.receive(.backupWallet) { state in
state.phraseDisplayState.phrase = RecoveryPhrase(words: mnemonic.components(separatedBy: " ").map { $0.redacted })
}
await store.receive(.updateDestination(.backupPhrase)) { state in
state.destination = .backupPhrase
}
}
func testBackupWalletAccessRequest_AuthenticateFailedPath() async throws {
let store = TestStore(
initialState: .placeholder,
reducer: SettingsReducer()
) {
$0.localAuthentication = .mockAuthenticationFailed
}
_ = await store.send(.backupWalletAccessRequest)
await store.finish()
}
func testRescanBlockchain() async throws {
let store = TestStore(
initialState: .placeholder,
reducer: SettingsReducer()
)
_ = await store.send(.rescanBlockchain) { state in
state.rescanDialog = .init(
title: TextState("Rescan"),
message: TextState("Select the rescan you want"),
buttons: [
.default(TextState("Quick rescan"), action: .send(.quickRescan)),
.default(TextState("Full rescan"), action: .send(.fullRescan)),
.cancel(TextState("Cancel"))
]
)
}
}
func testRescanBlockchain_Cancelling() async throws {
let store = TestStore(
initialState: SettingsReducer.State(
destination: nil,
phraseDisplayState: .init(),
rescanDialog: .init(
title: TextState("Rescan"),
message: TextState("Select the rescan you want"),
buttons: [
.default(TextState("Quick rescan"), action: .send(.quickRescan)),
.default(TextState("Full rescan"), action: .send(.fullRescan)),
.cancel(TextState("Cancel"))
]
Add crash reporter to secant (#531) * [#525] Adds functions to configure, testCrash and check if it can start. This adds a build phase where a dummy file is added to the project to make the build and Plist copy happy. When building in the CI there will be a script to replace this Plist file with the real one that then will be copied to the bundle Crashlytics will be "off" by default and then be turned on when starting up to be an Opt-Out thing. This is the only way it can be turned off later. reference: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#enable_opt-in_reporting The app will start with crash reporting turned off and will set it up on by default on the application's code. Then if the user wants to opt-out of crash reporting, it can. Otherwise, it won't be possible. Adds opting out of crash reporting as a stored user preference. This adds a value inside UserPreferencesStorage and its live and mock counterparts. also creates a builer for `CrashReporterClient` that has a Dependency to `@Dependency(\.userStoredPreferences)` and sets the references for the client to set the appropriate values into the user storage `UserPreferencesStorage` as been adapted to be a TCA Dependency. `SettingsStore` now as a `Toogle()` to turn off and on crash reporting. But it doesn't work yet because I haven't found out how to make a TCA Binding that can rely on an initial value that is not hardcoded but injected from somewhere else. See https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-1 https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-2 Adds Test Crash button and enable crash reporting Adds upload-symbols run script phase Closes #525 Add a custom build environment variable "UPLOAD_CRASHLYTICS_SYMBOLS" that will let Xcode skip the upload_symbols script for debug builds Fix Initialization tests * bump build
2023-02-15 13:18:18 -08:00
),
isCrashReportingOn: false
),
reducer: SettingsReducer()
)
_ = await store.send(.cancelRescan) { state in
state.rescanDialog = nil
}
}
func testRescanBlockchain_QuickRescanClearance() async throws {
let store = TestStore(
initialState: SettingsReducer.State(
destination: nil,
phraseDisplayState: .init(),
rescanDialog: .init(
title: TextState("Rescan"),
message: TextState("Select the rescan you want"),
buttons: [
.default(TextState("Quick rescan"), action: .send(.quickRescan)),
.default(TextState("Full rescan"), action: .send(.fullRescan)),
.cancel(TextState("Cancel"))
]
Add crash reporter to secant (#531) * [#525] Adds functions to configure, testCrash and check if it can start. This adds a build phase where a dummy file is added to the project to make the build and Plist copy happy. When building in the CI there will be a script to replace this Plist file with the real one that then will be copied to the bundle Crashlytics will be "off" by default and then be turned on when starting up to be an Opt-Out thing. This is the only way it can be turned off later. reference: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#enable_opt-in_reporting The app will start with crash reporting turned off and will set it up on by default on the application's code. Then if the user wants to opt-out of crash reporting, it can. Otherwise, it won't be possible. Adds opting out of crash reporting as a stored user preference. This adds a value inside UserPreferencesStorage and its live and mock counterparts. also creates a builer for `CrashReporterClient` that has a Dependency to `@Dependency(\.userStoredPreferences)` and sets the references for the client to set the appropriate values into the user storage `UserPreferencesStorage` as been adapted to be a TCA Dependency. `SettingsStore` now as a `Toogle()` to turn off and on crash reporting. But it doesn't work yet because I haven't found out how to make a TCA Binding that can rely on an initial value that is not hardcoded but injected from somewhere else. See https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-1 https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-2 Adds Test Crash button and enable crash reporting Adds upload-symbols run script phase Closes #525 Add a custom build environment variable "UPLOAD_CRASHLYTICS_SYMBOLS" that will let Xcode skip the upload_symbols script for debug builds Fix Initialization tests * bump build
2023-02-15 13:18:18 -08:00
),
isCrashReportingOn: false
),
reducer: SettingsReducer()
)
_ = await store.send(.quickRescan) { state in
state.rescanDialog = nil
}
}
func testRescanBlockchain_FullRescanClearance() async throws {
let store = TestStore(
initialState: SettingsReducer.State(
destination: nil,
phraseDisplayState: .init(),
rescanDialog: .init(
title: TextState("Rescan"),
message: TextState("Select the rescan you want"),
buttons: [
.default(TextState("Quick rescan"), action: .send(.quickRescan)),
.default(TextState("Full rescan"), action: .send(.fullRescan)),
.cancel(TextState("Cancel"))
]
Add crash reporter to secant (#531) * [#525] Adds functions to configure, testCrash and check if it can start. This adds a build phase where a dummy file is added to the project to make the build and Plist copy happy. When building in the CI there will be a script to replace this Plist file with the real one that then will be copied to the bundle Crashlytics will be "off" by default and then be turned on when starting up to be an Opt-Out thing. This is the only way it can be turned off later. reference: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#enable_opt-in_reporting The app will start with crash reporting turned off and will set it up on by default on the application's code. Then if the user wants to opt-out of crash reporting, it can. Otherwise, it won't be possible. Adds opting out of crash reporting as a stored user preference. This adds a value inside UserPreferencesStorage and its live and mock counterparts. also creates a builer for `CrashReporterClient` that has a Dependency to `@Dependency(\.userStoredPreferences)` and sets the references for the client to set the appropriate values into the user storage `UserPreferencesStorage` as been adapted to be a TCA Dependency. `SettingsStore` now as a `Toogle()` to turn off and on crash reporting. But it doesn't work yet because I haven't found out how to make a TCA Binding that can rely on an initial value that is not hardcoded but injected from somewhere else. See https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-1 https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-2 Adds Test Crash button and enable crash reporting Adds upload-symbols run script phase Closes #525 Add a custom build environment variable "UPLOAD_CRASHLYTICS_SYMBOLS" that will let Xcode skip the upload_symbols script for debug builds Fix Initialization tests * bump build
2023-02-15 13:18:18 -08:00
),
isCrashReportingOn: false
),
reducer: SettingsReducer()
)
_ = await store.send(.fullRescan) { state in
state.rescanDialog = nil
}
}
func testExportLogs_ButtonDisableShareEnable() async throws {
let store = TestStore(
initialState: SettingsReducer.State(
destination: nil,
phraseDisplayState: .init(),
rescanDialog: .init(
title: TextState("Rescan"),
message: TextState("Select the rescan you want"),
buttons: [
.default(TextState("Quick rescan"), action: .send(.quickRescan)),
.default(TextState("Full rescan"), action: .send(.fullRescan)),
.cancel(TextState("Cancel"))
]
Add crash reporter to secant (#531) * [#525] Adds functions to configure, testCrash and check if it can start. This adds a build phase where a dummy file is added to the project to make the build and Plist copy happy. When building in the CI there will be a script to replace this Plist file with the real one that then will be copied to the bundle Crashlytics will be "off" by default and then be turned on when starting up to be an Opt-Out thing. This is the only way it can be turned off later. reference: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#enable_opt-in_reporting The app will start with crash reporting turned off and will set it up on by default on the application's code. Then if the user wants to opt-out of crash reporting, it can. Otherwise, it won't be possible. Adds opting out of crash reporting as a stored user preference. This adds a value inside UserPreferencesStorage and its live and mock counterparts. also creates a builer for `CrashReporterClient` that has a Dependency to `@Dependency(\.userStoredPreferences)` and sets the references for the client to set the appropriate values into the user storage `UserPreferencesStorage` as been adapted to be a TCA Dependency. `SettingsStore` now as a `Toogle()` to turn off and on crash reporting. But it doesn't work yet because I haven't found out how to make a TCA Binding that can rely on an initial value that is not hardcoded but injected from somewhere else. See https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-1 https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-2 Adds Test Crash button and enable crash reporting Adds upload-symbols run script phase Closes #525 Add a custom build environment variable "UPLOAD_CRASHLYTICS_SYMBOLS" that will let Xcode skip the upload_symbols script for debug builds Fix Initialization tests * bump build
2023-02-15 13:18:18 -08:00
),
isCrashReportingOn: false
),
reducer: SettingsReducer()
)
store.dependencies.logsHandler = LogsHandlerClient(exportAndStoreLogs: { _, _, _ in })
_ = await store.send(.exportLogs) { state in
state.exportLogsDisabled = true
}
await store.receive(.logsExported) { state in
state.exportLogsDisabled = false
state.isSharingLogs = true
}
}
func testLogShareFinished() async throws {
let store = TestStore(
initialState: SettingsReducer.State(
destination: nil,
isSharingLogs: true,
phraseDisplayState: .init(),
rescanDialog: .init(
title: TextState("Rescan"),
message: TextState("Select the rescan you want"),
buttons: [
.default(TextState("Quick rescan"), action: .send(.quickRescan)),
.default(TextState("Full rescan"), action: .send(.fullRescan)),
.cancel(TextState("Cancel"))
]
Add crash reporter to secant (#531) * [#525] Adds functions to configure, testCrash and check if it can start. This adds a build phase where a dummy file is added to the project to make the build and Plist copy happy. When building in the CI there will be a script to replace this Plist file with the real one that then will be copied to the bundle Crashlytics will be "off" by default and then be turned on when starting up to be an Opt-Out thing. This is the only way it can be turned off later. reference: https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=ios#enable_opt-in_reporting The app will start with crash reporting turned off and will set it up on by default on the application's code. Then if the user wants to opt-out of crash reporting, it can. Otherwise, it won't be possible. Adds opting out of crash reporting as a stored user preference. This adds a value inside UserPreferencesStorage and its live and mock counterparts. also creates a builer for `CrashReporterClient` that has a Dependency to `@Dependency(\.userStoredPreferences)` and sets the references for the client to set the appropriate values into the user storage `UserPreferencesStorage` as been adapted to be a TCA Dependency. `SettingsStore` now as a `Toogle()` to turn off and on crash reporting. But it doesn't work yet because I haven't found out how to make a TCA Binding that can rely on an initial value that is not hardcoded but injected from somewhere else. See https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-1 https://www.pointfree.co/episodes/ep158-safer-conciser-forms-part-2 Adds Test Crash button and enable crash reporting Adds upload-symbols run script phase Closes #525 Add a custom build environment variable "UPLOAD_CRASHLYTICS_SYMBOLS" that will let Xcode skip the upload_symbols script for debug builds Fix Initialization tests * bump build
2023-02-15 13:18:18 -08:00
),
isCrashReportingOn: false
),
reducer: SettingsReducer()
)
_ = await store.send(.logsShareFinished) { state in
state.isSharingLogs = false
}
}
}