diff options
author | Florian Dold <florian@dold.me> | 2023-09-24 13:01:42 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-09-24 13:01:42 +0200 |
commit | bdd906c88707b2ec8d6d1d4afbd0bba8e3a9a3cd (patch) | |
tree | 2973eb935e90720d51650317435f3ee558a8575d | |
parent | 6b63ecc49e4baafcd2833503418bb531025d8054 (diff) |
adapt to corebank API change, minor refactoring
9 files changed, 50 insertions, 132 deletions
diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index 0a864cad3..27980857c 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -592,7 +592,9 @@ export async function withdrawViaBankV2( // Confirm it - await bankClient.confirmWithdrawalOperation(user.username, wop); + await bankClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: wop.withdrawal_id, + }); return { withdrawalFinishedCond, diff --git a/packages/taler-harness/src/integrationtests/test-kyc.ts b/packages/taler-harness/src/integrationtests/test-kyc.ts index 2b2b57183..4fc725bc3 100644 --- a/packages/taler-harness/src/integrationtests/test-kyc.ts +++ b/packages/taler-harness/src/integrationtests/test-kyc.ts @@ -331,7 +331,9 @@ export async function runKycTest(t: GlobalTestState) { // Confirm it - await bankClient.confirmWithdrawalOperation(user.username, wop); + await bankClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: wop.withdrawal_id, + }); const kycNotificationCond = walletClient.waitForNotificationCond((x) => { if ( diff --git a/packages/taler-harness/src/integrationtests/test-payment-fault.ts b/packages/taler-harness/src/integrationtests/test-payment-fault.ts index ca74a4ad6..8076e2fb4 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-fault.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-fault.ts @@ -153,7 +153,9 @@ export async function runPaymentFaultTest(t: GlobalTestState) { // Confirm it - await bankClient.confirmWithdrawalOperation(user.username, wop); + await bankClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: wop.withdrawal_id, + }); await wallet.runUntilDone(); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts b/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts index ae582fe60..2496f4887 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts @@ -161,7 +161,9 @@ export async function runWalletNotificationsTest(t: GlobalTestState) { // Confirm it - await bankAccessApiClient.confirmWithdrawalOperation(user.username, wop); + await bankAccessApiClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: wop.withdrawal_id, + }); await withdrawalFinishedReceivedPromise; } diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts index 4a2cc7df9..8c8853f4a 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts @@ -129,7 +129,9 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) { // Confirm it - await bankAccessApiClient.confirmWithdrawalOperation(user.username, wop); + await bankAccessApiClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: wop.withdrawal_id, + }); await withdrawalBankConfirmedCond; diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts index a5a5a0d99..d3df19664 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts @@ -152,7 +152,9 @@ export async function runWithdrawalFeesTest(t: GlobalTestState) { // Confirm it - await bankAccessApiClient.confirmWithdrawalOperation(user.username, wop); + await bankAccessApiClient.confirmWithdrawalOperation(user.username, { + withdrawalOperationId: wop.withdrawal_id, + }); await wallet.runUntilDone(); // Check balance diff --git a/packages/taler-util/src/bank-api-client.ts b/packages/taler-util/src/bank-api-client.ts index facb02ea8..d42317f91 100644 --- a/packages/taler-util/src/bank-api-client.ts +++ b/packages/taler-util/src/bank-api-client.ts @@ -223,6 +223,10 @@ export interface AccountData { cashout_payto_uri?: string; } +export interface ConfirmWithdrawalArgs { + withdrawalOperationId: string; +} + /** * Client for the Taler corebank API. */ @@ -356,10 +360,10 @@ export class TalerCorebankApiClient { async confirmWithdrawalOperation( username: string, - wopi: WithdrawalOperationInfo, + wopi: ConfirmWithdrawalArgs, ): Promise<void> { const url = new URL( - `accounts/${username}/withdrawals/${wopi.withdrawal_id}/confirm`, + `withdrawals/${wopi.withdrawalOperationId}/confirm`, this.baseUrl, ); logger.info(`confirming withdrawal operation via ${url.href}`); diff --git a/packages/taler-wallet-core/src/dbless.ts b/packages/taler-wallet-core/src/dbless.ts index 1684977d5..0d702a00c 100644 --- a/packages/taler-wallet-core/src/dbless.ts +++ b/packages/taler-wallet-core/src/dbless.ts @@ -142,7 +142,9 @@ export async function topupReserveWithDemobank( httpResp, codecForBankWithdrawalOperationPostResponse(), ); - await bankClient.confirmWithdrawalOperation(bankUser.username, wopi); + await bankClient.confirmWithdrawalOperation(bankUser.username, { + withdrawalOperationId: wopi.withdrawal_id, + }); } export async function withdrawCoin(args: { diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts index b5840c3a6..9b5dd2a19 100644 --- a/packages/taler-wallet-core/src/operations/testing.ts +++ b/packages/taler-wallet-core/src/operations/testing.ts @@ -27,6 +27,7 @@ import { NotificationType, RegisterAccountRequest, stringToBytes, + TalerCorebankApiClient, TestPayResult, TransactionMajorState, TransactionMinorState, @@ -74,16 +75,6 @@ import { getTransactionById, getTransactions } from "./transactions.js"; const logger = new Logger("operations/testing.ts"); -interface BankUser { - username: string; - password: string; -} - -interface BankWithdrawalResponse { - taler_withdraw_uri: string; - withdrawal_id: string; -} - interface MerchantBackendInfo { baseUrl: string; authToken?: string; @@ -103,16 +94,6 @@ function makeId(length: number): string { return result; } -/** - * Helper function to generate the "Authorization" HTTP header. - * FIXME: redundant, put in taler-util - */ -function makeBasicAuthHeader(username: string, password: string): string { - const auth = `${username}:${password}`; - const authEncoded: string = base64FromArrayBuffer(stringToBytes(auth)); - return `Basic ${authEncoded}`; -} - export async function withdrawTestBalance( ws: InternalWalletState, req: WithdrawTestBalanceRequest, @@ -122,15 +103,18 @@ export async function withdrawTestBalance( const bankAccessApiBaseUrl = req.bankAccessApiBaseUrl; logger.trace( - `Registered bank user, bank access base url ${bankAccessApiBaseUrl}`, + `Registering bank user, bank access base url ${bankAccessApiBaseUrl}`, ); - const bankUser = await registerRandomBankUser(ws.http, bankAccessApiBaseUrl); + + const corebankClient = new TalerCorebankApiClient(bankAccessApiBaseUrl); + + const bankUser = await corebankClient.createRandomBankUser(); logger.trace(`Registered bank user ${JSON.stringify(bankUser)}`); - const wresp = await createDemoBankWithdrawalUri( - ws.http, - bankAccessApiBaseUrl, - bankUser, + corebankClient.setAuth(bankUser); + + const wresp = await corebankClient.createWithdrawalOperation( + bankUser.username, amount, ); @@ -140,14 +124,14 @@ export async function withdrawTestBalance( forcedDenomSel: req.forcedDenomSel, }); - await confirmBankWithdrawalUri( - ws.http, - bankAccessApiBaseUrl, - bankUser, - wresp.withdrawal_id, - ); + await corebankClient.confirmWithdrawalOperation(bankUser.username, { + withdrawalOperationId: wresp.withdrawal_id, + }); } +/** + * FIXME: User MerchantApiClient instead. + */ function getMerchantAuthHeader(m: MerchantBackendInfo): Record<string, string> { if (m.authToken) { return { @@ -158,88 +142,8 @@ function getMerchantAuthHeader(m: MerchantBackendInfo): Record<string, string> { } /** - * Use the testing API of a demobank to create a taler://withdraw URI - * that the wallet can then use to make a withdrawal. + * FIXME: User MerchantApiClient instead. */ -export async function createDemoBankWithdrawalUri( - http: HttpRequestLibrary, - bankAccessApiBaseUrl: string, - bankUser: BankUser, - amount: AmountString, -): Promise<BankWithdrawalResponse> { - const reqUrl = new URL( - `accounts/${bankUser.username}/withdrawals`, - bankAccessApiBaseUrl, - ).href; - const resp = await http.postJson( - reqUrl, - { - amount, - }, - { - headers: { - Authorization: makeBasicAuthHeader( - bankUser.username, - bankUser.password, - ), - }, - }, - ); - const respJson = await readSuccessResponseJsonOrThrow(resp, codecForAny()); - return respJson; -} - -async function confirmBankWithdrawalUri( - http: HttpRequestLibrary, - bankAccessApiBaseUrl: string, - bankUser: BankUser, - withdrawalId: string, -): Promise<void> { - const reqUrl = new URL( - `accounts/${bankUser.username}/withdrawals/${withdrawalId}/confirm`, - bankAccessApiBaseUrl, - ).href; - const resp = await http.postJson( - reqUrl, - {}, - { - headers: { - Authorization: makeBasicAuthHeader( - bankUser.username, - bankUser.password, - ), - }, - }, - ); - await readSuccessResponseJsonOrThrow(resp, codecForAny()); - return; -} - -async function registerRandomBankUser( - http: HttpRequestLibrary, - corebankApiBaseUrl: string, -): Promise<BankUser> { - const reqUrl = new URL("accounts", corebankApiBaseUrl).href; - const randId = makeId(8); - const username = `testuser-${randId.toLowerCase()}`; - const password = `testpw-${randId}`; - - const bankUser: BankUser = { - username, - password, - }; - - const userReq: RegisterAccountRequest = { - username, - password, - name: username, - }; - - const resp = await http.fetch(reqUrl, { method: "POST", body: userReq }); - await checkSuccessResponseOrThrow(resp); - return bankUser; -} - async function refund( http: HttpRequestLibrary, merchantBackend: MerchantBackendInfo, @@ -267,6 +171,9 @@ async function refund( return refundUri; } +/** + * FIXME: User MerchantApiClient instead. + */ async function createOrder( http: HttpRequestLibrary, merchantBackend: MerchantBackendInfo, @@ -296,6 +203,9 @@ async function createOrder( return { orderId }; } +/** + * FIXME: User MerchantApiClient instead. + */ async function checkPayment( http: HttpRequestLibrary, merchantBackend: MerchantBackendInfo, @@ -309,16 +219,6 @@ async function checkPayment( return readSuccessResponseJsonOrThrow(resp, codecForCheckPaymentResponse()); } -interface BankUser { - username: string; - password: string; -} - -interface BankWithdrawalResponse { - taler_withdraw_uri: string; - withdrawal_id: string; -} - async function makePayment( ws: InternalWalletState, merchant: MerchantBackendInfo, |