diff options
Diffstat (limited to 'packages/taler-wallet-core/src/testing.ts')
-rw-r--r-- | packages/taler-wallet-core/src/testing.ts | 174 |
1 files changed, 87 insertions, 87 deletions
diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts index 22af816e5..45a29a6e3 100644 --- a/packages/taler-wallet-core/src/testing.ts +++ b/packages/taler-wallet-core/src/testing.ts @@ -77,7 +77,7 @@ import { import { initiatePeerPushDebit } from "./pay-peer-push-debit.js"; import { getRefreshesForTransaction } from "./refresh.js"; import { getTransactionById, getTransactions } from "./transactions.js"; -import type { InternalWalletState } from "./wallet.js"; +import type { InternalWalletState, WalletExecutionContext } from "./wallet.js"; import { acceptWithdrawalFromUri } from "./withdraw.js"; const logger = new Logger("operations/testing.ts"); @@ -100,7 +100,7 @@ export interface WithdrawTestBalanceResult { } export async function withdrawTestBalance( - ws: InternalWalletState, + wex: WalletExecutionContext, req: WithdrawTestBalanceRequest, ): Promise<WithdrawTestBalanceResult> { const amount = req.amount; @@ -123,7 +123,7 @@ export async function withdrawTestBalance( amount, ); - const acceptResp = await acceptWithdrawalFromUri(ws, { + const acceptResp = await acceptWithdrawalFromUri(wex, { talerWithdrawUri: wresp.taler_withdraw_uri, selectedExchange: exchangeBaseUrl, forcedDenomSel: req.forcedDenomSel, @@ -239,13 +239,13 @@ interface MakePaymentResult { } async function makePayment( - ws: InternalWalletState, + wex: WalletExecutionContext, merchant: MerchantBackendInfo, amount: string, summary: string, ): Promise<MakePaymentResult> { const orderResp = await createOrder( - ws.http, + wex.http, merchant, amount, summary, @@ -254,7 +254,7 @@ async function makePayment( logger.trace("created order with orderId", orderResp.orderId); - let paymentStatus = await checkPayment(ws.http, merchant, orderResp.orderId); + let paymentStatus = await checkPayment(wex.http, merchant, orderResp.orderId); logger.trace("payment status", paymentStatus); @@ -263,7 +263,7 @@ async function makePayment( throw Error("no taler://pay/ URI in payment response"); } - const preparePayResult = await preparePayForUri(ws, talerPayUri); + const preparePayResult = await preparePayForUri(wex, talerPayUri); logger.trace("prepare pay result", preparePayResult); @@ -272,14 +272,14 @@ async function makePayment( } const confirmPayResult = await confirmPay( - ws, + wex, preparePayResult.transactionId, undefined, ); logger.trace("confirmPayResult", confirmPayResult); - paymentStatus = await checkPayment(ws.http, merchant, orderResp.orderId); + paymentStatus = await checkPayment(wex.http, merchant, orderResp.orderId); logger.trace("payment status after wallet payment:", paymentStatus); @@ -294,7 +294,7 @@ async function makePayment( } export async function runIntegrationTest( - ws: InternalWalletState, + wex: WalletExecutionContext, args: IntegrationTestArgs, ): Promise<void> { logger.info("running test with arguments", args); @@ -303,15 +303,15 @@ export async function runIntegrationTest( const currency = parsedSpendAmount.currency; logger.info("withdrawing test balance"); - const withdrawRes1 = await withdrawTestBalance(ws, { + const withdrawRes1 = await withdrawTestBalance(wex, { amount: args.amountToWithdraw, corebankApiBaseUrl: args.corebankApiBaseUrl, exchangeBaseUrl: args.exchangeBaseUrl, }); - await waitUntilGivenTransactionsFinal(ws, [withdrawRes1.transactionId]); + await waitUntilGivenTransactionsFinal(wex, [withdrawRes1.transactionId]); logger.info("done withdrawing test balance"); - const balance = await getBalances(ws); + const balance = await getBalances(wex); logger.trace(JSON.stringify(balance, null, 2)); @@ -321,14 +321,14 @@ export async function runIntegrationTest( }; const makePaymentRes = await makePayment( - ws, + wex, myMerchant, args.amountToSpend, "hello world", ); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, makePaymentRes.paymentTransactionId, ); @@ -338,23 +338,23 @@ export async function runIntegrationTest( const refundAmount = Amounts.parseOrThrow(`${currency}:6`); const spendAmountThree = Amounts.parseOrThrow(`${currency}:3`); - const withdrawRes2 = await withdrawTestBalance(ws, { + const withdrawRes2 = await withdrawTestBalance(wex, { amount: Amounts.stringify(withdrawAmountTwo), corebankApiBaseUrl: args.corebankApiBaseUrl, exchangeBaseUrl: args.exchangeBaseUrl, }); - await waitUntilGivenTransactionsFinal(ws, [withdrawRes2.transactionId]); + await waitUntilGivenTransactionsFinal(wex, [withdrawRes2.transactionId]); const { orderId: refundOrderId } = await makePayment( - ws, + wex, myMerchant, Amounts.stringify(spendAmountTwo), "order that will be refunded", ); const refundUri = await refund( - ws.http, + wex.http, myMerchant, refundOrderId, "test refund", @@ -363,20 +363,20 @@ export async function runIntegrationTest( logger.trace("refund URI", refundUri); - const refundResp = await startRefundQueryForUri(ws, refundUri); + const refundResp = await startRefundQueryForUri(wex, refundUri); logger.trace("integration test: applied refund"); // Wait until the refund is done await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, refundResp.transactionId, ); logger.trace("integration test: making payment after refund"); const paymentResp2 = await makePayment( - ws, + wex, myMerchant, Amounts.stringify(spendAmountThree), "payment after refund", @@ -384,12 +384,12 @@ export async function runIntegrationTest( logger.trace("integration test: make payment done"); - await waitUntilGivenTransactionsFinal(ws, [ + await waitUntilGivenTransactionsFinal(wex, [ paymentResp2.paymentTransactionId, ]); await waitUntilGivenTransactionsFinal( - ws, - await getRefreshesForTransaction(ws, paymentResp2.paymentTransactionId), + wex, + await getRefreshesForTransaction(wex, paymentResp2.paymentTransactionId), ); logger.trace("integration test: all done!"); @@ -399,12 +399,12 @@ export async function runIntegrationTest( * Wait until all transactions are in a final state. */ export async function waitUntilAllTransactionsFinal( - ws: InternalWalletState, + wex: WalletExecutionContext, ): Promise<void> { logger.info("waiting until all transactions are in a final state"); - ws.taskScheduler.ensureRunning(); + wex.taskScheduler.ensureRunning(); let p: OpenedPromise<void> | undefined = undefined; - const cancelNotifs = ws.addNotificationListener((notif) => { + const cancelNotifs = wex.ws.addNotificationListener((notif) => { if (!p) { return; } @@ -420,7 +420,7 @@ export async function waitUntilAllTransactionsFinal( }); while (1) { p = openPromise(); - const txs = await getTransactions(ws, { + const txs = await getTransactions(wex, { includeRefreshes: true, filterByState: "nonfinal", }); @@ -452,7 +452,7 @@ export async function waitUntilAllTransactionsFinal( * Wait until all chosen transactions are in a final state. */ export async function waitUntilGivenTransactionsFinal( - ws: InternalWalletState, + wex: WalletExecutionContext, transactionIds: string[], ): Promise<void> { logger.info( @@ -462,10 +462,10 @@ export async function waitUntilGivenTransactionsFinal( if (transactionIds.length === 0) { return; } - ws.taskScheduler.ensureRunning(); + wex.taskScheduler.ensureRunning(); const txIdSet = new Set(transactionIds); let p: OpenedPromise<void> | undefined = undefined; - const cancelNotifs = ws.addNotificationListener((notif) => { + const cancelNotifs = wex.ws.addNotificationListener((notif) => { if (!p) { return; } @@ -486,7 +486,7 @@ export async function waitUntilGivenTransactionsFinal( }); while (1) { p = openPromise(); - const txs = await getTransactions(ws, { + const txs = await getTransactions(wex, { includeRefreshes: true, filterByState: "nonfinal", }); @@ -519,12 +519,12 @@ export async function waitUntilGivenTransactionsFinal( } export async function waitUntilRefreshesDone( - ws: InternalWalletState, + wex: WalletExecutionContext, ): Promise<void> { logger.info("waiting until all refresh transactions are in a final state"); - ws.taskScheduler.ensureRunning(); + wex.taskScheduler.ensureRunning(); let p: OpenedPromise<void> | undefined = undefined; - const cancelNotifs = ws.addNotificationListener((notif) => { + const cancelNotifs = wex.ws.addNotificationListener((notif) => { if (!p) { return; } @@ -540,7 +540,7 @@ export async function waitUntilRefreshesDone( }); while (1) { p = openPromise(); - const txs = await getTransactions(ws, { + const txs = await getTransactions(wex, { includeRefreshes: true, filterByState: "nonfinal", }); @@ -572,13 +572,13 @@ export async function waitUntilRefreshesDone( } async function waitUntilTransactionPendingReady( - ws: InternalWalletState, + wex: WalletExecutionContext, transactionId: string, ): Promise<void> { logger.info(`starting waiting for ${transactionId} to be in pending(ready)`); - ws.taskScheduler.ensureRunning(); + wex.taskScheduler.ensureRunning(); let p: OpenedPromise<void> | undefined = undefined; - const cancelNotifs = ws.addNotificationListener((notif) => { + const cancelNotifs = wex.ws.addNotificationListener((notif) => { if (!p) { return; } @@ -588,7 +588,7 @@ async function waitUntilTransactionPendingReady( }); while (1) { p = openPromise(); - const tx = await getTransactionById(ws, { + const tx = await getTransactionById(wex, { transactionId, }); if ( @@ -608,7 +608,7 @@ async function waitUntilTransactionPendingReady( * Wait until a transaction is in a particular state. */ export async function waitTransactionState( - ws: InternalWalletState, + wex: WalletExecutionContext, transactionId: string, txState: TransactionState, ): Promise<void> { @@ -617,9 +617,9 @@ export async function waitTransactionState( txState, )})`, ); - ws.taskScheduler.ensureRunning(); + wex.taskScheduler.ensureRunning(); let p: OpenedPromise<void> | undefined = undefined; - const cancelNotifs = ws.addNotificationListener((notif) => { + const cancelNotifs = wex.ws.addNotificationListener((notif) => { if (!p) { return; } @@ -629,7 +629,7 @@ export async function waitTransactionState( }); while (1) { p = openPromise(); - const tx = await getTransactionById(ws, { + const tx = await getTransactionById(wex, { transactionId, }); if ( @@ -648,31 +648,31 @@ export async function waitTransactionState( } export async function waitUntilTransactionWithAssociatedRefreshesFinal( - ws: InternalWalletState, + wex: WalletExecutionContext, transactionId: string, ): Promise<void> { - await waitUntilGivenTransactionsFinal(ws, [transactionId]); + await waitUntilGivenTransactionsFinal(wex, [transactionId]); await waitUntilGivenTransactionsFinal( - ws, - await getRefreshesForTransaction(ws, transactionId), + wex, + await getRefreshesForTransaction(wex, transactionId), ); } export async function waitUntilTransactionFinal( - ws: InternalWalletState, + wex: WalletExecutionContext, transactionId: string, ): Promise<void> { - await waitUntilGivenTransactionsFinal(ws, [transactionId]); + await waitUntilGivenTransactionsFinal(wex, [transactionId]); } export async function runIntegrationTest2( - ws: InternalWalletState, + wex: WalletExecutionContext, args: IntegrationTestV2Args, ): Promise<void> { - ws.taskScheduler.ensureRunning(); + wex.taskScheduler.ensureRunning(); logger.info("running test with arguments", args); - const exchangeInfo = await fetchFreshExchange(ws, args.exchangeBaseUrl); + const exchangeInfo = await fetchFreshExchange(wex, args.exchangeBaseUrl); const currency = exchangeInfo.currency; @@ -680,15 +680,15 @@ export async function runIntegrationTest2( const amountToSpend = Amounts.parseOrThrow(`${currency}:2`); logger.info("withdrawing test balance"); - const withdrawalRes = await withdrawTestBalance(ws, { + const withdrawalRes = await withdrawTestBalance(wex, { amount: Amounts.stringify(amountToWithdraw), corebankApiBaseUrl: args.corebankApiBaseUrl, exchangeBaseUrl: args.exchangeBaseUrl, }); - await waitUntilTransactionFinal(ws, withdrawalRes.transactionId); + await waitUntilTransactionFinal(wex, withdrawalRes.transactionId); logger.info("done withdrawing test balance"); - const balance = await getBalances(ws); + const balance = await getBalances(wex); logger.trace(JSON.stringify(balance, null, 2)); @@ -698,14 +698,14 @@ export async function runIntegrationTest2( }; const makePaymentRes = await makePayment( - ws, + wex, myMerchant, Amounts.stringify(amountToSpend), "hello world", ); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, makePaymentRes.paymentTransactionId, ); @@ -715,24 +715,24 @@ export async function runIntegrationTest2( const refundAmount = Amounts.parseOrThrow(`${currency}:6`); const spendAmountThree = Amounts.parseOrThrow(`${currency}:3`); - const withdrawalRes2 = await withdrawTestBalance(ws, { + const withdrawalRes2 = await withdrawTestBalance(wex, { amount: Amounts.stringify(withdrawAmountTwo), corebankApiBaseUrl: args.corebankApiBaseUrl, exchangeBaseUrl: args.exchangeBaseUrl, }); // Wait until the withdraw is done - await waitUntilTransactionFinal(ws, withdrawalRes2.transactionId); + await waitUntilTransactionFinal(wex, withdrawalRes2.transactionId); const { orderId: refundOrderId } = await makePayment( - ws, + wex, myMerchant, Amounts.stringify(spendAmountTwo), "order that will be refunded", ); const refundUri = await refund( - ws.http, + wex.http, myMerchant, refundOrderId, "test refund", @@ -741,33 +741,33 @@ export async function runIntegrationTest2( logger.trace("refund URI", refundUri); - const refundResp = await startRefundQueryForUri(ws, refundUri); + const refundResp = await startRefundQueryForUri(wex, refundUri); logger.trace("integration test: applied refund"); // Wait until the refund is done await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, refundResp.transactionId, ); logger.trace("integration test: making payment after refund"); const makePaymentRes2 = await makePayment( - ws, + wex, myMerchant, Amounts.stringify(spendAmountThree), "payment after refund", ); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, makePaymentRes2.paymentTransactionId, ); logger.trace("integration test: make payment done"); - const peerPushInit = await initiatePeerPushDebit(ws, { + const peerPushInit = await initiatePeerPushDebit(wex, { partialContractTerms: { amount: `${currency}:1` as AmountString, summary: "Payment Peer Push Test", @@ -780,8 +780,8 @@ export async function runIntegrationTest2( }, }); - await waitUntilTransactionPendingReady(ws, peerPushInit.transactionId); - const txDetails = await getTransactionById(ws, { + await waitUntilTransactionPendingReady(wex, peerPushInit.transactionId); + const txDetails = await getTransactionById(wex, { transactionId: peerPushInit.transactionId, }); @@ -793,15 +793,15 @@ export async function runIntegrationTest2( throw Error("internal invariant failed"); } - const peerPushCredit = await preparePeerPushCredit(ws, { + const peerPushCredit = await preparePeerPushCredit(wex, { talerUri: txDetails.talerUri, }); - await confirmPeerPushCredit(ws, { + await confirmPeerPushCredit(wex, { transactionId: peerPushCredit.transactionId, }); - const peerPullInit = await initiatePeerPullPayment(ws, { + const peerPullInit = await initiatePeerPullPayment(wex, { partialContractTerms: { amount: `${currency}:1` as AmountString, summary: "Payment Peer Pull Test", @@ -814,33 +814,33 @@ export async function runIntegrationTest2( }, }); - await waitUntilTransactionPendingReady(ws, peerPullInit.transactionId); + await waitUntilTransactionPendingReady(wex, peerPullInit.transactionId); - const peerPullInc = await preparePeerPullDebit(ws, { + const peerPullInc = await preparePeerPullDebit(wex, { talerUri: peerPullInit.talerUri, }); - await confirmPeerPullDebit(ws, { + await confirmPeerPullDebit(wex, { peerPullDebitId: peerPullInc.peerPullDebitId, }); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, peerPullInc.transactionId, ); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, peerPullInit.transactionId, ); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, peerPushCredit.transactionId, ); await waitUntilTransactionWithAssociatedRefreshesFinal( - ws, + wex, peerPushInit.transactionId, ); @@ -858,7 +858,7 @@ export async function runIntegrationTest2( }); } - await createDepositGroup(ws, { + await createDepositGroup(wex, { amount: `${currency}:5` as AmountString, depositPaytoUri: depositPayto, }); @@ -867,7 +867,7 @@ export async function runIntegrationTest2( } export async function testPay( - ws: InternalWalletState, + wex: WalletExecutionContext, args: TestPayArgs, ): Promise<TestPayResult> { logger.trace("creating order"); @@ -876,26 +876,26 @@ export async function testPay( baseUrl: args.merchantBaseUrl, }; const orderResp = await createOrder( - ws.http, + wex.http, merchant, args.amount, args.summary, "taler://fulfillment-success/thank+you", ); logger.trace("created new order with order ID", orderResp.orderId); - const checkPayResp = await checkPayment(ws.http, merchant, orderResp.orderId); + const checkPayResp = await checkPayment(wex.http, merchant, orderResp.orderId); const talerPayUri = checkPayResp.taler_pay_uri; if (!talerPayUri) { console.error("fatal: no taler pay URI received from backend"); process.exit(1); } logger.trace("taler pay URI:", talerPayUri); - const result = await preparePayForUri(ws, talerPayUri); + const result = await preparePayForUri(wex, talerPayUri); if (result.status !== PreparePayResultType.PaymentPossible) { throw Error(`unexpected prepare pay status: ${result.status}`); } const r = await confirmPay( - ws, + wex, result.transactionId, undefined, args.forcedCoinSel, @@ -903,7 +903,7 @@ export async function testPay( if (r.type != ConfirmPayResultType.Done) { throw Error("payment not done"); } - const purchase = await ws.db.runReadOnlyTx(["purchases"], async (tx) => { + const purchase = await wex.db.runReadOnlyTx(["purchases"], async (tx) => { return tx.purchases.get(result.proposalId); }); checkLogicInvariant(!!purchase); |