diff options
author | Florian Dold <florian@dold.me> | 2023-04-04 15:25:29 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-04-04 15:26:14 +0200 |
commit | 07d8498abc6aa21ab7c8e7146a04b4b731504c3d (patch) | |
tree | 029fdde522f60569254a23a91a86e152f450c92a /packages/taler-wallet-core/src/operations/testing.ts | |
parent | cefec08ce7ef5d1fce0398d54b651c3a0762c788 (diff) | |
download | wallet-core-07d8498abc6aa21ab7c8e7146a04b4b731504c3d.tar.xz |
wallet-core: implement runIntegrationTestV2
Diffstat (limited to 'packages/taler-wallet-core/src/operations/testing.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/testing.ts | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts index 873fac021..c1f129fcd 100644 --- a/packages/taler-wallet-core/src/operations/testing.ts +++ b/packages/taler-wallet-core/src/operations/testing.ts @@ -18,8 +18,11 @@ * Imports. */ import { + AbsoluteTime, base64FromArrayBuffer, ConfirmPayResultType, + Duration, + IntegrationTestV2Args, Logger, stringToBytes, TestPayResult, @@ -46,6 +49,15 @@ import { applyRefund, confirmPay, preparePayForUri } from "./pay-merchant.js"; import { getBalances } from "./balance.js"; import { checkLogicInvariant } from "../util/invariants.js"; import { acceptWithdrawalFromUri } from "./withdraw.js"; +import { updateExchangeFromUrl } from "./exchanges.js"; +import { + confirmPeerPullDebit, + confirmPeerPushCredit, + initiatePeerPullPayment, + initiatePeerPushPayment, + preparePeerPullDebit, + preparePeerPushCredit, +} from "./pay-peer.js"; const logger = new Logger("operations/testing.ts"); @@ -429,6 +441,146 @@ export async function runIntegrationTest( logger.trace("integration test: all done!"); } +export async function runIntegrationTest2( + ws: InternalWalletState, + args: IntegrationTestV2Args, +): Promise<void> { + logger.info("running test with arguments", args); + + const exchangeInfo = await updateExchangeFromUrl(ws, args.exchangeBaseUrl); + + const currency = exchangeInfo.exchangeDetails.currency; + + const amountToWithdraw = Amounts.parseOrThrow(`${currency}:10`); + const amountToSpend = Amounts.parseOrThrow(`${currency}:2`); + + logger.info("withdrawing test balance"); + await withdrawTestBalance(ws, { + amount: Amounts.stringify(amountToWithdraw), + bankBaseUrl: args.bankAccessApiBaseUrl /* FIXME: not necessary */, + bankAccessApiBaseUrl: args.bankAccessApiBaseUrl, + exchangeBaseUrl: args.exchangeBaseUrl, + }); + await ws.runUntilDone(); + logger.info("done withdrawing test balance"); + + const balance = await getBalances(ws); + + logger.trace(JSON.stringify(balance, null, 2)); + + const myMerchant: MerchantBackendInfo = { + baseUrl: args.merchantBaseUrl, + authToken: args.merchantAuthToken, + }; + + await makePayment( + ws, + myMerchant, + Amounts.stringify(amountToSpend), + "hello world", + ); + + // Wait until the refresh is done + await ws.runUntilDone(); + + logger.trace("withdrawing test balance for refund"); + const withdrawAmountTwo = Amounts.parseOrThrow(`${currency}:18`); + const spendAmountTwo = Amounts.parseOrThrow(`${currency}:7`); + const refundAmount = Amounts.parseOrThrow(`${currency}:6`); + const spendAmountThree = Amounts.parseOrThrow(`${currency}:3`); + + await withdrawTestBalance(ws, { + amount: Amounts.stringify(withdrawAmountTwo), + bankBaseUrl: args.bankAccessApiBaseUrl /* FIXME: not necessary */, + bankAccessApiBaseUrl: args.bankAccessApiBaseUrl, + exchangeBaseUrl: args.exchangeBaseUrl, + }); + + // Wait until the withdraw is done + await ws.runUntilDone(); + + const { orderId: refundOrderId } = await makePayment( + ws, + myMerchant, + Amounts.stringify(spendAmountTwo), + "order that will be refunded", + ); + + const refundUri = await refund( + ws.http, + myMerchant, + refundOrderId, + "test refund", + Amounts.stringify(refundAmount), + ); + + logger.trace("refund URI", refundUri); + + await applyRefund(ws, refundUri); + + logger.trace("integration test: applied refund"); + + // Wait until the refund is done + await ws.runUntilDone(); + + logger.trace("integration test: making payment after refund"); + + await makePayment( + ws, + myMerchant, + Amounts.stringify(spendAmountThree), + "payment after refund", + ); + + logger.trace("integration test: make payment done"); + + await ws.runUntilDone(); + + const peerPushInit = await initiatePeerPushPayment(ws, { + partialContractTerms: { + amount: `${currency}:1`, + summary: "Payment Peer Push Test", + purse_expiration: AbsoluteTime.toTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ hours: 1 }), + ), + ), + }, + }); + + const peerPushCredit = await preparePeerPushCredit(ws, { + talerUri: peerPushInit.talerUri, + }); + + await confirmPeerPushCredit(ws, { + peerPushPaymentIncomingId: peerPushCredit.peerPushPaymentIncomingId, + }); + + const peerPullInit = await initiatePeerPullPayment(ws, { + partialContractTerms: { + amount: `${currency}:1`, + summary: "Payment Peer Pull Test", + purse_expiration: AbsoluteTime.toTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ hours: 1 }), + ), + ), + }, + }); + + const peerPullInc = await preparePeerPullDebit(ws, { + talerUri: peerPullInit.talerUri, + }); + + await confirmPeerPullDebit(ws, { + peerPullPaymentIncomingId: peerPullInc.peerPullPaymentIncomingId, + }); + + logger.trace("integration test: all done!"); +} + export async function testPay( ws: InternalWalletState, args: TestPayArgs, |