taler-typescript-core

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

commit dfe4e8a6c3dfe0ced087db871bfaac768d135947
parent 0d5431eebdf4fe11d502628958d8b35f395fe995
Author: Florian Dold <florian@dold.me>
Date:   Wed,  8 Jan 2025 14:55:56 +0100

harness: complete scenario test for coin acceptor

Diffstat:
Mpackages/taler-harness/src/index.ts | 40+++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts @@ -50,6 +50,7 @@ import { stringifyPayTemplateUri, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; +import { readlinePrompt } from "@gnu-taler/taler-util/compat"; import { HttpResponse, createPlatformHttpLib, @@ -132,7 +133,6 @@ testingCli const httpLib = createPlatformHttpLib(); const bankUrl = "https://bank.test.taler.net/"; const bank = new TalerCoreBankHttpClient(bankUrl, httpLib); - const bankAuth = new TalerAuthenticationHttpClient(bankUrl, httpLib); const username = "user-" + encodeCrock(getRandomBytes(10)).toLowerCase(); const password = "pw-" + encodeCrock(getRandomBytes(10)).toLowerCase(); @@ -146,25 +146,43 @@ testingCli logger.info( `Created test bank account ${username} with password ${password}`, ); - const tokRes = await bankAuth.createAccessTokenBasic(username, password, { + const tokRes = await bank.createAccessTokenBasic(username, password, { scope: "readwrite", }); narrowOpSuccessOrThrow("token", tokRes); const token = tokRes.body.access_token; + const bankAuth = { username, token }; logger.info(`Test account access token ${token}`); - const createWithdrawalResp = await bank.createWithdrawal( - { - username, - token, - }, - { - no_amount_to_wallet: true, - }, - ); + const createWithdrawalResp = await bank.createWithdrawal(bankAuth, { + no_amount_to_wallet: true, + }); narrowOpSuccessOrThrow("create-withdrawal", createWithdrawalResp); logger.info( `Created withdrawal operation ${createWithdrawalResp.body.taler_withdraw_uri}`, ); + const wopid = createWithdrawalResp.body.withdrawal_id; + while (true) { + logger.info(`Waiting for status change.`); + const statusRes = await bank.getWithdrawalById(wopid, { + timeoutMs: 30000, + old_state: "pending", + }); + narrowOpSuccessOrThrow("getWithdrawalById", statusRes); + logger.info(`Withdrawal status: ${j2s(statusRes.body.status)}`); + if (statusRes.body.status === "selected") { + break; + } + } + const amountStr = await readlinePrompt("Amount to withdraw: "); + const confirmRes = await bank.confirmWithdrawalById( + bankAuth, + { + amount: amountStr as AmountString, + }, + wopid, + ); + narrowOpSuccessOrThrow("confirmWithdrawalById", confirmRes); + logger.info("Withdrawal operation confirmed"); }); const advancedCli = talerHarnessCli.subcommand("advancedArgs", "advanced", {