taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 1397e87627bce6ecd7a2739670eb2f5eab3b99dc
parent 9d3970f20973718d66aa3b96535a5ee6750edb84
Author: Antoine A <>
Date:   Thu, 10 Apr 2025 18:28:17 +0200

harness: clean tests

Diffstat:
Mpackages/taler-harness/src/harness/harness.ts | 6+++---
Mpackages/taler-harness/src/integrationtests/test-account-restrictions.ts | 10+++++-----
Mpackages/taler-harness/src/integrationtests/test-bank-api.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-exchange-management-fault.ts | 18+++++++++---------
Mpackages/taler-harness/src/integrationtests/test-exchange-master-pub-change.ts | 10+++++-----
Mpackages/taler-harness/src/integrationtests/test-payment-claim.ts | 18+++++++++---------
Mpackages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts | 10+++++-----
Mpackages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts | 18+++++++++---------
Mpackages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts | 10+++++-----
Mpackages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts | 27++++++++++-----------------
10 files changed, 64 insertions(+), 71 deletions(-)

diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -313,10 +313,10 @@ export class GlobalTestState { } async assertThrowsTalerErrorAsync( - block: () => Promise<void>, + block: Promise<unknown>, ): Promise<TalerError> { try { - await block(); + await block } catch (e) { if (e instanceof TalerError) { return e; diff --git a/packages/taler-harness/src/integrationtests/test-account-restrictions.ts b/packages/taler-harness/src/integrationtests/test-account-restrictions.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -90,12 +90,12 @@ export async function runAccountRestrictionsTest(t: GlobalTestState) { }); // Invalid account, does not start with "foo-" - const err = await t.assertThrowsTalerErrorAsync(async () => { - await walletClient.call(WalletApiOperation.CheckDeposit, { + const err = await t.assertThrowsTalerErrorAsync( + walletClient.call(WalletApiOperation.CheckDeposit, { amount: "TESTKUDOS:5", depositPaytoUri: "payto://x-taler-bank/localhost/bar-42", - }); - }); + }) + ); logger.info(`checkResp ${j2s(err)}`); diff --git a/packages/taler-harness/src/integrationtests/test-bank-api.ts b/packages/taler-harness/src/integrationtests/test-bank-api.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -127,9 +127,9 @@ export async function runBankApiTest(t: GlobalTestState) { // Make sure that registering twice results in a 409 Conflict { - const e = await t.assertThrowsTalerErrorAsync(async () => { - await bankClient.registerAccount("user1", "password2"); - }); + const e = await t.assertThrowsTalerErrorAsync( + bankClient.registerAccount("user1", "password2") + ); t.assertTrue(e.errorDetail.httpStatusCode === 409); } diff --git a/packages/taler-harness/src/integrationtests/test-exchange-management-fault.ts b/packages/taler-harness/src/integrationtests/test-exchange-management-fault.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -189,11 +189,11 @@ export async function runExchangeManagementFaultTest( }, }); - const err1 = await t.assertThrowsTalerErrorAsync(async () => { - await wallet.client.call(WalletApiOperation.AddExchange, { + const err1 = await t.assertThrowsTalerErrorAsync( + wallet.client.call(WalletApiOperation.AddExchange, { exchangeBaseUrl: faultyExchange.baseUrl, - }); - }); + }) + ); console.log("got error", err1); @@ -237,11 +237,11 @@ export async function runExchangeManagementFaultTest( }, }); - const err2 = await t.assertThrowsTalerErrorAsync(async () => { - await wallet.client.call(WalletApiOperation.AddExchange, { + const err2 = await t.assertThrowsTalerErrorAsync( + wallet.client.call(WalletApiOperation.AddExchange, { exchangeBaseUrl: faultyExchange.baseUrl, - }); - }); + }) + ); t.assertTrue(err2.hasErrorCode(TalerErrorCode.WALLET_EXCHANGE_UNAVAILABLE)); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-master-pub-change.ts b/packages/taler-harness/src/integrationtests/test-exchange-master-pub-change.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -85,12 +85,12 @@ export async function runExchangeMasterPubChangeTest( t.logStep("exchange-restarted"); - const err = await t.assertThrowsTalerErrorAsync(async () => { - await walletClient.call(WalletApiOperation.UpdateExchangeEntry, { + const err = await t.assertThrowsTalerErrorAsync( + walletClient.call(WalletApiOperation.UpdateExchangeEntry, { exchangeBaseUrl: exchange.baseUrl, force: true, - }); - }); + }) + ); console.log("updateExchangeEntry err:", j2s(err)); diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim.ts b/packages/taler-harness/src/integrationtests/test-payment-claim.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -90,11 +90,11 @@ export async function runPaymentClaimTest(t: GlobalTestState) { preparePayResult.status === PreparePayResultType.PaymentPossible, ); - const errOne = t.assertThrowsTalerErrorAsync(async () => { - await w2.walletClient.call(WalletApiOperation.PreparePayForUri, { + const errOne = t.assertThrowsTalerErrorAsync( + w2.walletClient.call(WalletApiOperation.PreparePayForUri, { talerPayUri, - }); - }); + }) + ); console.log(errOne); @@ -112,11 +112,11 @@ export async function runPaymentClaimTest(t: GlobalTestState) { await w2.walletClient.call(WalletApiOperation.ClearDb, {}); - const err = await t.assertThrowsTalerErrorAsync(async () => { - await w2.walletClient.call(WalletApiOperation.PreparePayForUri, { + const err = await t.assertThrowsTalerErrorAsync( + w2.walletClient.call(WalletApiOperation.PreparePayForUri, { talerPayUri, - }); - }); + }) + ); t.assertTrue(err.hasErrorCode(TalerErrorCode.WALLET_ORDER_ALREADY_CLAIMED)); diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-push.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -193,15 +193,15 @@ export async function runPeerToPeerPushTest(t: GlobalTestState) { console.log(`txn2: ${j2s(txn2)}`); // We expect insufficient balance here! - const ex1 = await t.assertThrowsTalerErrorAsync(async () => { - await w1.walletClient.call(WalletApiOperation.InitiatePeerPushDebit, { + const ex1 = await t.assertThrowsTalerErrorAsync( + w1.walletClient.call(WalletApiOperation.InitiatePeerPushDebit, { partialContractTerms: { summary: "(this will fail)", amount: "TESTKUDOS:15" as AmountString, purse_expiration, }, - }); - }); + }) + ); console.log("got expected exception detail", j2s(ex1.errorDetail)); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -129,12 +129,12 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { await wres.withdrawalFinishedCond; { - const exc = await t.assertThrowsTalerErrorAsync(async () => { - await walletClient.call(WalletApiOperation.CheckDeposit, { + const exc = await t.assertThrowsTalerErrorAsync( + walletClient.call(WalletApiOperation.CheckDeposit, { amount: "TESTKUDOS:5" as AmountString, depositPaytoUri: "payto://x-taler-bank/localhost/foobar", - }); - }); + }) + ); t.assertDeepEqual( exc.errorDetail.code, @@ -167,11 +167,11 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { }); await wres2.withdrawalFinishedCond; - const exc = await t.assertThrowsTalerErrorAsync(async () => { - await walletClient.call(WalletApiOperation.CheckPeerPushDebit, { + const exc = await t.assertThrowsTalerErrorAsync( + walletClient.call(WalletApiOperation.CheckPeerPushDebit, { amount: "TESTKUDOS:20" as AmountString, - }); - }); + }) + ); const insufficientBalanceDetails: PaymentInsufficientBalanceDetails = exc.errorDetail.insufficientBalanceDetails; diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-abort-bank.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2020 Taler Systems S.A. + (C) 2020-2025 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -60,12 +60,12 @@ export async function runWithdrawalAbortBankTest(t: GlobalTestState) { // // WHY ?! // - const e = await t.assertThrowsTalerErrorAsync(async () => { - await walletClient.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, { + const e = await t.assertThrowsTalerErrorAsync( + walletClient.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, { exchangeBaseUrl: exchange.baseUrl, talerWithdrawUri: wop.taler_withdraw_uri, - }); - }); + }) + ); t.assertDeepEqual( e.errorDetail.code, TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK, diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts @@ -19,7 +19,6 @@ */ import { NotificationType, - TalerError, TalerErrorCode, TransactionMajorState, TransactionMinorState, @@ -193,20 +192,17 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) { ); // FIXME #9683 wallet should already know withdrawal already completed by this wallet - try { - await wallet1.call( + const e = await t.assertThrowsTalerErrorAsync( + wallet1.call( WalletApiOperation.AcceptBankIntegratedWithdrawal, { exchangeBaseUrl: exchange.baseUrl, talerWithdrawUri: withdrawal.taler_withdraw_uri, }, ) - throw "unreachable" - } catch (e) { - t.assertTrue(e instanceof TalerError) - t.assertTrue(e.errorDetail.code === TalerErrorCode.WALLET_REQUEST_TRANSACTION_STATE_UNSUPPORTED) - // FIXME #9683 We should not fail here - } + ); + t.assertTrue(e.errorDetail.code === TalerErrorCode.WALLET_REQUEST_TRANSACTION_STATE_UNSUPPORTED) + // FIXME #9683 We should not fail here } t.logStep("Check other wallet scan after completion"); @@ -220,20 +216,17 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) { ); // FIXME #9683 wallet should already know withdrawal already completed by wallet1 - try { - await wallet2.call( + const e = await t.assertThrowsTalerErrorAsync( + wallet2.call( WalletApiOperation.AcceptBankIntegratedWithdrawal, { exchangeBaseUrl: exchange.baseUrl, talerWithdrawUri: withdrawal.taler_withdraw_uri, }, ) - throw "unreachable" - } catch (e) { - t.assertTrue(e instanceof TalerError) - t.assertTrue(e.errorDetail.code === TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK) - // FIXME #9683 can we have a more proper error code than this ? - } + ) + t.assertTrue(e.errorDetail.code === TalerErrorCode.WALLET_WITHDRAWAL_OPERATION_ABORTED_BY_BANK) + // FIXME #9683 can we have a more proper error code than this ? } t.logStep("Check balance");