Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Wallet9// File : UITests/SPWalletUITests.swift10// Description : Interface tests. `LaunchUITests` needs nothing.11// `LiveWalletUITests` drive the real app against the12// THROWAWAY local stack13// (../SPWalletCore/Scripts/dev-stack.sh up-fork): real API,14// real isolated signer, software passkey, Base served by a15// local fork holding fake ETH. They are skipped when the16// stack is not running. No test ever touches production.17// Module : UITests18// Repository : https://git.spboucher.ai/sp-wallet-ios19// Created : 2026-11-1820// Last Modified : 2026-11-1821//22// =============================================================================23// AUTHOR & PROFESSIONAL AFFILIATION24// =============================================================================25//26// Author : Simon-Pierre Boucher27// Position : Professor of Finance28// Institution : Université du Québec en Outaouais (UQO)29// Department : Département des sciences administratives30// Organization : SP Boucher31//32// Website : https://spboucher.ai33// Git : https://git.spboucher.ai34//35// =============================================================================36// OFFICIAL CONTACT DIRECTORY37// =============================================================================38//39// General : info@spboucher.ai40// Professional : contact@spboucher.ai41// Direct : simon@spboucher.ai42// Research : research@spboucher.ai43// Development : dev@spboucher.ai44// Support : support@spboucher.ai45// Security/Admin : admin@spboucher.ai46// Notifications : notifications@spboucher.ai47//48// Preferred Contact: support@spboucher.ai49//50// =============================================================================51// COPYRIGHT & INTELLECTUAL PROPERTY52// =============================================================================53//54// Copyright (c) 202655// Simon-Pierre Boucher56//57// All rights reserved where applicable.58//59// This file is governed by the applicable project license,60// copyright notices, institutional agreements and relevant law.61//62// Unless expressly authorized by the applicable license or63// rights holder, copying, redistribution, sublicensing,64// publication and commercial exploitation are not permitted.65//66// Existing third-party rights and notices remain unaffected.67//68// =============================================================================69// CONFIDENTIALITY & SECURITY70// =============================================================================71//72// Classification : Public73// Distribution : Public repository; use is governed by the project license74// Security Contact : admin@spboucher.ai75//76// Access to this source does not independently grant permission77// to redistribute or disclose confidential materials.78//79// Do not embed credentials, private keys, access tokens,80// certificates or confidential personal information.81//82// =============================================================================83// LICENSE & MAINTENANCE84// =============================================================================85//86// License : None specified (no license file in this repository)87// Maintainer : Simon-Pierre Boucher88// Technical Contact: dev@spboucher.ai89//90// =============================================================================91// END OF SP BOUCHER SOURCE HEADER92// =============================================================================9394import XCTest9596enum Stack {97 static let origin = ProcessInfo.processInfo.environment["SPWALLET_UITEST_ORIGIN"] ?? "http://localhost:8750"98 static let dir = ProcessInfo.processInfo.environment["SPWALLET_UITEST_DIR"] ?? "/tmp/spw-native-8750/current"99100 static var isUp: Bool {101 guard let u = URL(string: origin + "/api/v1/health/live") else { return false }102 let done = DispatchSemaphore(value: 0)103 nonisolated(unsafe) var ok = false104 URLSession(configuration: .ephemeral).dataTask(with: u) { _, r, _ in ok = (r as? HTTPURLResponse)?.statusCode == 200; done.signal() }.resume()105 _ = done.wait(timeout: .now() + 3)106 return ok107 }108 static var hasFork: Bool { FileManager.default.fileExists(atPath: dir + "/fork-address") }109110 static func app() -> XCUIApplication {111 let app = XCUIApplication()112 app.launchEnvironment["SPWALLET_EPHEMERAL"] = "1"113 app.launchEnvironment["SPWALLET_ORIGIN"] = origin114 app.launchEnvironment["SPWALLET_DEV_DIR"] = dir115 return app116 }117}118119extension XCTestCase {120 func shot(_ name: String) {121 let a = XCTAttachment(screenshot: XCUIScreen.main.screenshot())122 a.name = name; a.lifetime = .keepAlways123 add(a)124 }125 @discardableResult func signIn(_ app: XCUIApplication) -> XCUIApplication {126 app.launch()127 let login = app.buttons["login.passkey"]128 XCTAssertTrue(login.waitForExistence(timeout: 60))129 login.tap()130 XCTAssertTrue(app.staticTexts["home.total"].waitForExistence(timeout: 30), "the dashboard appears after the passkey sign-in")131 return app132 }133 var isPad: Bool { UIDevice.current.userInterfaceIdiom == .pad }134 /** Go to a section: tab bar on iPhone, sidebar on iPad. */135 func go(_ app: XCUIApplication, _ section: String) {136 if isPad {137 let row = app.descendants(matching: .any)["sidebar.\(section)"].firstMatch138 if !row.waitForExistence(timeout: 3) { app.navigationBars.buttons.firstMatch.tap() }139 XCTAssertTrue(row.waitForExistence(timeout: 5), "sidebar row \(section)")140 row.tap()141 } else {142 let tab = app.tabBars.buttons.matching(identifier: "tab.\(section)").firstMatch143 XCTAssertTrue(tab.waitForExistence(timeout: 5), "tab \(section)")144 tab.tap()145 }146 }147}148149final class LaunchUITests: XCTestCase {150 func testWithoutServerTheAppShowsSignInAndSaysTheServerIsUnreachable() {151 let app = XCUIApplication()152 app.launchEnvironment["SPWALLET_EPHEMERAL"] = "1"153 app.launchEnvironment["SPWALLET_ORIGIN"] = "http://localhost:1" // nothing listens there154 app.launch()155 XCTAssertTrue(app.buttons["login.passkey"].waitForExistence(timeout: 20))156 XCTAssertFalse(app.buttons["login.offline"].exists, "no offline consultation without synchronized data")157 shot("signin-offline")158 }159}160161final class LiveWalletUITests: XCTestCase {162 override func setUpWithError() throws {163 continueAfterFailure = false164 try XCTSkipUnless(Stack.isUp, "throwaway stack not running (../SPWalletCore/Scripts/dev-stack.sh up-fork)")165 }166167 func testSignInDashboardAndMainSections() {168 let app = signIn(Stack.app())169 shot("01-home")170 go(app, "portfolio"); XCTAssertTrue(app.navigationBars["Portefeuille"].waitForExistence(timeout: 5)); shot("02-portfolio")171 go(app, "activity"); XCTAssertTrue(app.navigationBars["Activité"].waitForExistence(timeout: 5)); shot("03-activity")172 if !isPad { go(app, "explore"); XCTAssertTrue(app.navigationBars["Explorer"].waitForExistence(timeout: 5)); shot("04-explore") }173 go(app, "settings"); XCTAssertTrue(app.navigationBars["Réglages"].waitForExistence(timeout: 5)); shot("05-settings")174 }175176 func testReceiveShowsTheWalletsOwnAddressAndItsQRCode() {177 let app = signIn(Stack.app())178 if isPad { app.buttons["Recevoir"].firstMatch.tap() } else { app.buttons["quick.receive"].tap() }179 let base = app.buttons["network.base"]180 XCTAssertTrue(base.waitForExistence(timeout: 10)); base.tap()181 let address = app.staticTexts["receive.address"]182 XCTAssertTrue(address.waitForExistence(timeout: 5))183 XCTAssertTrue(address.label.hasPrefix("0x") && address.label.count == 42, "an EVM address is shown in full: \(address.label)")184 if let fork = try? String(contentsOfFile: Stack.dir + "/fork-address", encoding: .utf8) {185 XCTAssertEqual(address.label, fork.trimmingCharacters(in: .whitespacesAndNewlines), "the address shown is the one the signer derived")186 }187 XCTAssertTrue(app.images["receive.qr"].exists || app.otherElements["receive.qr"].exists || app.descendants(matching: .any)["receive.qr"].exists)188 shot("06-receive")189 }190191 func testAnInvalidDestinationIsRefusedBeforeAnyPreparation() {192 let app = signIn(Stack.app())193 if isPad { app.buttons["Envoyer"].firstMatch.tap() } else { app.buttons["quick.send"].tap() }194 let base = app.buttons["network.base"]195 XCTAssertTrue(base.waitForExistence(timeout: 10)); base.tap()196 let recipient = app.textViews["send.recipient"].exists ? app.textViews["send.recipient"] : app.textFields["send.recipient"]197 XCTAssertTrue(recipient.waitForExistence(timeout: 5))198 recipient.tap(); recipient.typeText("0x5AAeb6053F3E94C9b9A09f33669435E7Ef1BeAeD") // mixed case, wrong checksum199 XCTAssertTrue(app.staticTexts["send.addressError"].waitForExistence(timeout: 5), "a wrong EIP-55 checksum is flagged at once")200 XCTAssertFalse(app.buttons["send.prepare"].isEnabled)201 shot("07-send-bad-address")202 }203204 func testSendFromFormToConfirmationThroughTheIntentReviewAndThePasskey() throws {205 try XCTSkipUnless(Stack.hasFork, "needs the local fork (dev-stack.sh up-fork)")206 let app = signIn(Stack.app())207 if isPad { app.buttons["Envoyer"].firstMatch.tap() } else { app.buttons["quick.send"].tap() }208 let base = app.buttons["network.base"]209 XCTAssertTrue(base.waitForExistence(timeout: 10)); base.tap()210 let to = "0x" + (0..<20).map { _ in String(format: "%02x", UInt8.random(in: 0...255)) }.joined()211 let recipient = app.textViews["send.recipient"].exists ? app.textViews["send.recipient"] : app.textFields["send.recipient"]212 XCTAssertTrue(recipient.waitForExistence(timeout: 5))213 recipient.tap(); recipient.typeText(to)214 let amount = app.textFields["send.amount"]215 amount.tap(); amount.typeText("0.001")216 shot("08-send-form")217 let prepare = app.buttons["send.prepare"]218 if app.buttons["send.keyboardDone"].exists { app.buttons["send.keyboardDone"].tap() }219 if !prepare.isHittable { app.swipeUp() }220 XCTAssertTrue(prepare.waitForExistence(timeout: 5)); XCTAssertTrue(prepare.isEnabled); prepare.tap()221222 // the review shows the intent: exact amount and the full destination as normalized by the server (EIP-55)223 let reviewAmount = app.staticTexts["review.amount"]224 XCTAssertTrue(reviewAmount.waitForExistence(timeout: 30), "the server prepared the transfer and the app verified its challenge")225 XCTAssertTrue(reviewAmount.label.contains("0,001") || reviewAmount.label.contains("0.001"), reviewAmount.label)226 XCTAssertTrue(reviewAmount.label.contains("ETH"))227 let reviewTo = app.descendants(matching: .any)["review.to"].firstMatch228 XCTAssertTrue(reviewTo.exists)229 XCTAssertTrue(reviewTo.label.lowercased().contains(to), "the full destination is displayed, not a shortened one: \(reviewTo.label)")230 XCTAssertTrue(app.staticTexts["Nouvelle destination"].exists, "the server's new-destination warning is shown")231 shot("09-send-review")232233 app.swipeUp(); app.swipeUp()234 let approve = app.buttons["send.approve"]235 XCTAssertTrue(approve.waitForExistence(timeout: 5)); approve.tap()236237 let state = app.descendants(matching: .any)["tracker.state"].firstMatch238 XCTAssertTrue(state.waitForExistence(timeout: 40), "after the passkey the app follows the transaction")239 shot("10-send-tracking")240 XCTAssertFalse(state.label.contains("Échouée") || state.label.contains("Refusée"), "state shown: \(state.label)")241 app.buttons["send.done"].tap()242 go(app, "activity")243 XCTAssertTrue(app.descendants(matching: .any)["activity.row"].firstMatch.waitForExistence(timeout: 15), "the transfer is in the history")244 shot("11-activity-after-send")245 }246}247