From 70a803038f1cbe05dc4779bdd87376fd073421be Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 13 Feb 2024 10:53:43 +0100 Subject: implement task shepherd, many small fixes and tweaks --- .../src/integrationtests/test-payment-fault.ts | 82 ++++++++-------------- .../src/integrationtests/test-payment-share.ts | 33 +++++++-- .../src/integrationtests/test-peer-repair.ts | 4 +- .../src/integrationtests/test-peer-to-peer-pull.ts | 1 - .../test-timetravel-autorefresh.ts | 19 ++++- 5 files changed, 75 insertions(+), 64 deletions(-) (limited to 'packages/taler-harness/src/integrationtests') diff --git a/packages/taler-harness/src/integrationtests/test-payment-fault.ts b/packages/taler-harness/src/integrationtests/test-payment-fault.ts index af6751ef4..cadcc9056 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-fault.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-fault.ts @@ -21,11 +21,7 @@ /** * Imports. */ -import { - TalerCorebankApiClient, - CoreApiResponse, - MerchantApiClient, -} from "@gnu-taler/taler-util"; +import { ConfirmPayResultType, MerchantApiClient } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { @@ -38,10 +34,13 @@ import { ExchangeService, GlobalTestState, MerchantService, - WalletCli, generateRandomPayto, setupDb, } from "../harness/harness.js"; +import { + createWalletDaemonWithClient, + withdrawViaBankV2, +} from "../harness/helpers.js"; /** * Run test for basic, bank-integrated withdrawal. @@ -123,45 +122,20 @@ export async function runPaymentFaultTest(t: GlobalTestState) { console.log("setup done!"); - const wallet = new WalletCli(t); - - // Create withdrawal operation - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl); - - const user = await bankClient.createRandomBankUser(); - const wop = await bankClient.createWithdrawalOperation( - user.username, - "TESTKUDOS:20", - ); - - // Hand it to the wallet - - await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, { - talerWithdrawUri: wop.taler_withdraw_uri, - }); - - await wallet.runPending(); - - // Withdraw - - await wallet.client.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, { - exchangeBaseUrl: faultyExchange.baseUrl, - talerWithdrawUri: wop.taler_withdraw_uri, + const { walletClient } = await createWalletDaemonWithClient(t, { + name: "default", }); - await wallet.runPending(); - // Confirm it + await walletClient.call(WalletApiOperation.GetBalances, {}); - await bankClient.confirmWithdrawalOperation(user.username, { - withdrawalOperationId: wop.withdrawal_id, + const wres = await withdrawViaBankV2(t, { + walletClient, + bank, + exchange: faultyExchange, + amount: "TESTKUDOS:20", }); - await wallet.runUntilDone(); - - // Check balance - - await wallet.client.call(WalletApiOperation.GetBalances, {}); + await wres.withdrawalFinishedCond; // Set up order. @@ -181,24 +155,22 @@ export async function runPaymentFaultTest(t: GlobalTestState) { // Make wallet pay for the order - let apiResp: CoreApiResponse; - - const prepResp = await wallet.client.call( + const prepResp = await walletClient.call( WalletApiOperation.PreparePayForUri, { talerPayUri: orderStatus.taler_pay_uri, }, ); - const proposalId = prepResp.proposalId; - - await wallet.runPending(); - // Drop 3 responses from the exchange. let faultCount = 0; faultyExchange.faultProxy.addFault({ async modifyResponse(ctx: FaultInjectionResponseContext) { - if (!ctx.request.requestUrl.endsWith("/deposit")) { + console.log(`in modifyResponse for ${ctx.request.requestUrl}`); + if ( + !ctx.request.requestUrl.endsWith("/deposit") && + !ctx.request.requestUrl.endsWith("/batch-deposit") + ) { return; } if (faultCount < 3) { @@ -213,12 +185,16 @@ export async function runPaymentFaultTest(t: GlobalTestState) { // confirmPay won't work, as the exchange is unreachable - await wallet.client.call(WalletApiOperation.ConfirmPay, { - // FIXME: should be validated, don't cast! - proposalId: proposalId, - }); + const confirmPayResp = await walletClient.call( + WalletApiOperation.ConfirmPay, + { + transactionId: prepResp.transactionId, + }, + ); + + t.assertDeepEqual(confirmPayResp.type, ConfirmPayResultType.Pending); - await wallet.runUntilDone(); + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); // Check if payment was successful. diff --git a/packages/taler-harness/src/integrationtests/test-payment-share.ts b/packages/taler-harness/src/integrationtests/test-payment-share.ts index ef4f8adeb..034bbc98d 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-share.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-share.ts @@ -65,6 +65,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { }); await secondWallet.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + t.logStep("setup-done"); + // create two orders to pay async function createOrder(amount: string) { const order = { @@ -74,7 +76,6 @@ export async function runPaymentShareTest(t: GlobalTestState) { }; const args = { order }; - const auth = {}; const orderResp = await merchantClient.createOrder({ order: args.order, @@ -88,6 +89,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { return { id: orderResp.order_id, uri: orderStatus.taler_pay_uri }; } + t.logStep("orders-created"); + /** * FIRST CASE, create in first wallet and pay in the second wallet * first wallet should not be able to continue @@ -104,6 +107,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { claimFirstWallet.status === PreparePayResultType.PaymentPossible, ); + t.logStep("w1-payment-possible"); + // share order from the first wallet const { privatePayUri } = await firstWallet.call( WalletApiOperation.SharePayment, @@ -113,6 +118,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { }, ); + t.logStep("w1-payment-shared"); + // claim from the second wallet const claimSecondWallet = await secondWallet.call( WalletApiOperation.PreparePayForUri, @@ -123,18 +130,25 @@ export async function runPaymentShareTest(t: GlobalTestState) { claimSecondWallet.status === PreparePayResultType.PaymentPossible, ); + t.logStep("w2-claimed"); + // pay from the second wallet const r2 = await secondWallet.call(WalletApiOperation.ConfirmPay, { - proposalId: claimSecondWallet.proposalId, + transactionId: claimSecondWallet.transactionId, }); + t.assertTrue(r2.type === ConfirmPayResultType.Done); + + t.logStep("w2-confirmed"); + // Wait for refresh to settle before we do checks await secondWallet.call( WalletApiOperation.TestingWaitTransactionsFinal, {}, ); - t.assertTrue(r2.type === ConfirmPayResultType.Done); + t.logStep("w2-refresh-settled"); + { const first = await firstWallet.call(WalletApiOperation.GetBalances, {}); const second = await secondWallet.call( @@ -155,11 +169,16 @@ export async function runPaymentShareTest(t: GlobalTestState) { claimFirstWalletAgain.status === PreparePayResultType.AlreadyConfirmed, ); + t.logStep("w1-prepared-again"); + const r1 = await firstWallet.call(WalletApiOperation.ConfirmPay, { - proposalId: claimFirstWallet.proposalId, + transactionId: claimFirstWallet.transactionId, }); t.assertTrue(r1.type === ConfirmPayResultType.Done); + + t.logStep("w1-confirmed-shared"); + { const first = await firstWallet.call(WalletApiOperation.GetBalances, {}); const second = await secondWallet.call( @@ -171,6 +190,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { } } + t.logStep("first-case-done"); + /** * SECOND CASE, create in first wallet and share to the second wallet * pay with the first wallet, second wallet should not be able to continue @@ -208,7 +229,7 @@ export async function runPaymentShareTest(t: GlobalTestState) { // pay from the second wallet const r2 = await firstWallet.call(WalletApiOperation.ConfirmPay, { - proposalId: claimFirstWallet.proposalId, + transactionId: claimFirstWallet.transactionId, }); t.assertTrue(r2.type === ConfirmPayResultType.Done); @@ -232,6 +253,8 @@ export async function runPaymentShareTest(t: GlobalTestState) { claimSecondWalletAgain.status === PreparePayResultType.AlreadyConfirmed, ); } + + t.logStep("second-case-done"); } runPaymentShareTest.suites = ["wallet"]; diff --git a/packages/taler-harness/src/integrationtests/test-peer-repair.ts b/packages/taler-harness/src/integrationtests/test-peer-repair.ts index a225a2057..22664bcc1 100644 --- a/packages/taler-harness/src/integrationtests/test-peer-repair.ts +++ b/packages/taler-harness/src/integrationtests/test-peer-repair.ts @@ -22,21 +22,19 @@ import { AmountString, Duration, NotificationType, - TalerUriAction, TransactionMajorState, TransactionMinorState, TransactionType, WalletNotification, - stringifyTalerUri, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import * as fs from "node:fs"; import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, withdrawViaBankV2, } from "../harness/helpers.js"; -import * as fs from "node:fs"; export async function runPeerRepairTest(t: GlobalTestState) { // Set up test environment diff --git a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts index e8d34e288..b61a3941b 100644 --- a/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts +++ b/packages/taler-harness/src/integrationtests/test-peer-to-peer-pull.ts @@ -33,7 +33,6 @@ import { BankServiceHandle, ExchangeService, GlobalTestState, - WalletCli, WalletClient, } from "../harness/harness.js"; import { diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts index def2462e0..3c47f30db 100644 --- a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts +++ b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts @@ -22,6 +22,7 @@ import { Duration, durationFromSpec, MerchantApiClient, + NotificationType, PreparePayResultType, } from "@gnu-taler/taler-util"; import { @@ -124,6 +125,12 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { }); await wres.withdrawalFinishedCond; + const exchangeUpdated1Cond = walletClient.waitForNotificationCond( + (x) => + x.type === NotificationType.ExchangeStateTransition && + x.exchangeBaseUrl === exchange.baseUrl, + ); + // Travel into the future, the deposit expiration is two years // into the future. console.log("applying first time travel"); @@ -142,7 +149,8 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { console.log("pending operations after first time travel"); console.log(JSON.stringify(p, undefined, 2)); - await walletClient.call(WalletApiOperation.TestingWaitTasksProcessed, {}); + // The time travel should cause exchanges to update. + await exchangeUpdated1Cond; await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); const wres2 = await withdrawViaBankV2(t, { @@ -155,6 +163,12 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + const exchangeUpdated2Cond = walletClient.waitForNotificationCond( + (x) => + x.type === NotificationType.ExchangeStateTransition && + x.exchangeBaseUrl === exchange.baseUrl, + ); + // Travel into the future, the deposit expiration is two years // into the future. console.log("applying second time travel"); @@ -167,7 +181,8 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { }, ); - await walletClient.call(WalletApiOperation.TestingWaitTasksProcessed, {}); + // The time travel should cause exchanges to update. + await exchangeUpdated2Cond; await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); // At this point, the original coins should've been refreshed. -- cgit v1.2.3