From 22cb8adaa6d9584ad7638b9019b6d0c3eb7158bf Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 13 Feb 2023 13:15:47 +0100 Subject: wallet-core,harness: introduce reserveIsReady flag, test tx lifeycle --- .../test-withdrawal-bank-integrated.ts | 96 +++++++++++++++++++--- 1 file changed, 84 insertions(+), 12 deletions(-) (limited to 'packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts') 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 dc7298e5d..c98c18db5 100644 --- a/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-bank-integrated.ts @@ -18,13 +18,13 @@ * Imports. */ import { GlobalTestState } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironment } from "../harness/helpers.js"; +import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js"; import { WalletApiOperation, BankApi, BankAccessApi, } from "@gnu-taler/taler-wallet-core"; -import { j2s } from "@gnu-taler/taler-util"; +import { j2s, NotificationType, TransactionType, WithdrawalType } from "@gnu-taler/taler-util"; /** * Run test for basic, bank-integrated withdrawal. @@ -32,7 +32,8 @@ import { j2s } from "@gnu-taler/taler-util"; export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) { // Set up test environment - const { wallet, bank, exchange } = await createSimpleTestkudosEnvironment(t); + const { walletClient, bank, exchange } = + await createSimpleTestkudosEnvironmentV2(t); // Create a withdrawal operation @@ -45,46 +46,117 @@ export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) { // Hand it to the wallet - const r1 = await wallet.client.call( + const r1 = await walletClient.client.call( WalletApiOperation.GetWithdrawalDetailsForUri, { talerWithdrawUri: wop.taler_withdraw_uri, }, ); - await wallet.runPending(); - // Withdraw - const r2 = await wallet.client.call( + const withdrawalBankConfirmedCond = walletClient.waitForNotificationCond( + (x) => { + return x.type === NotificationType.WithdrawalGroupBankConfirmed; + }, + ); + + const withdrawalFinishedCond = walletClient.waitForNotificationCond((x) => { + return x.type === NotificationType.WithdrawGroupFinished; + }); + + const withdrawalReserveReadyCond = walletClient.waitForNotificationCond( + (x) => { + return x.type === NotificationType.WithdrawalGroupReserveReady; + }, + ); + + const r2 = await walletClient.client.call( WalletApiOperation.AcceptBankIntegratedWithdrawal, { exchangeBaseUrl: exchange.baseUrl, talerWithdrawUri: wop.taler_withdraw_uri, }, ); + // Do it twice to check idempotency - const r3 = await wallet.client.call( + const r3 = await walletClient.client.call( WalletApiOperation.AcceptBankIntegratedWithdrawal, { exchangeBaseUrl: exchange.baseUrl, talerWithdrawUri: wop.taler_withdraw_uri, }, ); - await wallet.runPending(); + + await exchange.stopWirewatch(); + + // Check status before withdrawal is confirmed by bank. + { + const txn = await walletClient.client.call( + WalletApiOperation.GetTransactions, + {}, + ); + console.log("transactions before confirmation:", j2s(txn)); + const tx0 = txn.transactions[0]; + t.assertTrue(tx0.type === TransactionType.Withdrawal); + t.assertTrue(tx0.withdrawalDetails.type === WithdrawalType.TalerBankIntegrationApi); + t.assertTrue(tx0.withdrawalDetails.confirmed === false); + t.assertTrue(tx0.withdrawalDetails.reserveIsReady === false); + } // Confirm it await BankApi.confirmWithdrawalOperation(bank, user, wop); - await wallet.runUntilDone(); + await withdrawalBankConfirmedCond; + + // Check status after withdrawal is confirmed by bank, + // but before funds are wired to the exchange. + { + const txn = await walletClient.client.call( + WalletApiOperation.GetTransactions, + {}, + ); + console.log("transactions after confirmation:", j2s(txn)); + const tx0 = txn.transactions[0]; + t.assertTrue(tx0.type === TransactionType.Withdrawal); + t.assertTrue(tx0.withdrawalDetails.type === WithdrawalType.TalerBankIntegrationApi); + t.assertTrue(tx0.withdrawalDetails.confirmed === true); + t.assertTrue(tx0.withdrawalDetails.reserveIsReady === false); + } + + await exchange.startWirewatch(); + + await withdrawalReserveReadyCond; + + // Check status after funds were wired. + { + const txn = await walletClient.client.call( + WalletApiOperation.GetTransactions, + {}, + ); + console.log("transactions after reserve ready:", j2s(txn)); + const tx0 = txn.transactions[0]; + t.assertTrue(tx0.type === TransactionType.Withdrawal); + t.assertTrue(tx0.withdrawalDetails.type === WithdrawalType.TalerBankIntegrationApi); + t.assertTrue(tx0.withdrawalDetails.confirmed === true); + t.assertTrue(tx0.withdrawalDetails.reserveIsReady === true); + } + + await withdrawalFinishedCond; // Check balance - const balResp = await wallet.client.call(WalletApiOperation.GetBalances, {}); + const balResp = await walletClient.client.call( + WalletApiOperation.GetBalances, + {}, + ); t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available); - const txn = await wallet.client.call(WalletApiOperation.GetTransactions, {}); + const txn = await walletClient.client.call( + WalletApiOperation.GetTransactions, + {}, + ); console.log(`transactions: ${j2s(txn)}`); } -- cgit v1.2.3