Model+Settings.swift (5024B)
1 /* 2 * This file is part of GNU Taler, ©2022-25 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * @author Marc Stibane 7 */ 8 import Foundation 9 import taler_swift 10 import SymLog 11 12 fileprivate let MERCHANTAUTHTOKEN = "secret-token:sandbox" 13 14 // MARK: - 15 /// A request to add a test balance to the wallet. 16 fileprivate struct WithdrawTestBalanceRequest: WalletBackendFormattedRequest { 17 struct Response: Decodable {} // no result - getting no error back means success 18 func operation() -> String { "withdrawTestBalance" } 19 func args() -> Args { Args(amount: amount, 20 corebankApiBaseUrl: bankBaseUrl, 21 useForeignAccount: true, 22 exchangeBaseUrl: exchangeBaseUrl) 23 } 24 25 var amount: Amount 26 var bankBaseUrl: String 27 var exchangeBaseUrl: String 28 29 struct Args: Encodable { 30 var amount: Amount 31 // var bankBaseUrl: String // <= this should be the correct parameter name 32 var corebankApiBaseUrl: String // <= but this is used by wallet-core 33 var useForeignAccount: Bool 34 var exchangeBaseUrl: String 35 } 36 } 37 extension WalletModel { 38 nonisolated func loadTestKudos(_ test: Int, amount: Amount, viewHandles: Bool = false) 39 async throws { 40 let request = WithdrawTestBalanceRequest(amount: amount, 41 bankBaseUrl: test == 2 ? HEADBANK 42 : test == 1 ? TESTBANK : DEMOBANK, 43 exchangeBaseUrl: test == 2 ? HEADEXCHANGE 44 : test == 1 ? TESTEXCHANGE : DEMOEXCHANGE) 45 let response = try await sendRequest(request, viewHandles: viewHandles) 46 } 47 } // loadTestKudos 48 // MARK: - 49 /// A request to add a test balance to the wallet. 50 fileprivate struct RunIntegrationTest: WalletBackendFormattedRequest { 51 struct Response: Decodable {} // no result - getting no error back means success 52 func operation() -> String { newVersion ? "runIntegrationTestV2" : "runIntegrationTest" } 53 func args() -> Args { Args(exchangeBaseUrl: exchangeBaseUrl, 54 corebankApiBaseUrl: bankBaseUrl, 55 merchantBaseUrl: merchantBaseUrl, 56 merchantAuthToken: merchantAuthToken, 57 amountToWithdraw: amountToWithdraw, 58 amountToSpend: amountToSpend) 59 } 60 61 let newVersion: Bool 62 63 var exchangeBaseUrl: String 64 var bankBaseUrl: String 65 var merchantBaseUrl: String 66 var merchantAuthToken: String 67 var amountToWithdraw: Amount 68 var amountToSpend: Amount 69 70 struct Args: Encodable { 71 var exchangeBaseUrl: String 72 // var bankBaseUrl: String // <= this should be the correct parameter name 73 var corebankApiBaseUrl: String // <= but this is used by wallet-core 74 var merchantBaseUrl: String 75 var merchantAuthToken: String 76 var amountToWithdraw: Amount 77 var amountToSpend: Amount 78 } 79 } 80 extension WalletModel { 81 nonisolated func runIntegrationTest(newVersion: Bool, test: Bool, viewHandles: Bool = false) 82 async throws { 83 let amountW = Amount(currency: test ? TESTCURRENCY : DEMOCURRENCY, cent: 300) 84 let amountS = Amount(currency: test ? TESTCURRENCY : DEMOCURRENCY, cent: 100) 85 let request = RunIntegrationTest(newVersion: newVersion, 86 exchangeBaseUrl: test ? TESTEXCHANGE : DEMOEXCHANGE, 87 bankBaseUrl: (test ? TESTBANK : DEMOBANK), 88 merchantBaseUrl: test ? TESTBACKEND : DEMOBACKEND, 89 merchantAuthToken: MERCHANTAUTHTOKEN, 90 amountToWithdraw: amountW, 91 amountToSpend: amountS) 92 let _ = try await sendRequest(request, viewHandles: viewHandles) 93 } 94 } // runIntegrationTest 95 // MARK: - 96 /// A request to add a test balance to the wallet. 97 fileprivate struct InfiniteTransactionLoop: WalletBackendFormattedRequest { 98 struct Response: Decodable {} // no result - getting no error back means success 99 func operation() -> String { "testingInfiniteTransactionLoop" } 100 func args() -> Args { Args(delayMs: delayMs, 101 shouldFetch: shouldFetch) 102 } 103 104 let delayMs: Int32 105 let shouldFetch: Bool 106 107 108 struct Args: Encodable { 109 let delayMs: Int32 110 let shouldFetch: Bool 111 } 112 } 113 extension WalletModel { 114 nonisolated func testingInfiniteTransaction(delayMs: Int32, shouldFetch: Bool, viewHandles: Bool = false) 115 async throws { 116 let request = InfiniteTransactionLoop(delayMs: delayMs, shouldFetch: shouldFetch) 117 let _ = try await sendRequest(request, viewHandles: viewHandles) 118 } 119 } // testingInfiniteTransaction