taler-typescript-core

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

commit abc9a0f9304ef6ef541c3ef13769781474fdf1bb
parent b42525e997feeb90e9f80e21020edf00acaa0ea3
Author: Florian Dold <dold@taler.net>
Date:   Mon,  7 Sep 2026 14:16:24 +0200

taler-harness: share test setup and use current workflow helpers

Use the V3 standard environment for all callers, including fault injection
and wallet database generation. Move withdrawals to V4 and remove the
obsolete environment and withdrawal implementations.

Share repeated bank account, KYC, Donau, payment, peer transfer, browser,
and denomination setup while preserving scenario-specific assertions.

Diffstat:
Mpackages/taler-harness/README.md | 33+++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/harness/denomStructures.ts | 23+++++++++++++++++++++++
Mpackages/taler-harness/src/harness/environments.ts | 803+++++++++++++++++++++++++++++++++----------------------------------------------
Mpackages/taler-harness/src/harness/harness-donau.ts | 49++++++++++++++++++++++++++++++++++++++++++++++++-
Mpackages/taler-harness/src/harness/harness.ts | 5++++-
Mpackages/taler-harness/src/harness/tops.ts | 58+++++++++++++++++++++++++++++++++++-----------------------
Mpackages/taler-harness/src/index.ts | 6+++---
Mpackages/taler-harness/src/integrationtests/kyc-dynamic-measure-helper.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/kyc-form-withdrawal-helper.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/kyc-threshold-withdrawal-helper.ts | 19++-----------------
Mpackages/taler-harness/src/integrationtests/test-age-restrictions-deposit.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts | 20++++++++++----------
Mpackages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts | 16++++++++--------
Mpackages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-bank-api.ts | 22++++++++++++----------
Mpackages/taler-harness/src/integrationtests/test-claim-loop.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-clause-schnorr.ts | 17++++++-----------
Mpackages/taler-harness/src/integrationtests/test-coinsel-legacy-2024.ts | 6+++---
Mpackages/taler-harness/src/integrationtests/test-currency-scope-separation.ts | 121++++++++-----------------------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-currency-scope.ts | 127++++++++-----------------------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-denom-revoked-balance.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-denom-unoffered.ts | 19+++++++------------
Mpackages/taler-harness/src/integrationtests/test-deposit-fault.ts | 42+++++++++++++++---------------------------
Mpackages/taler-harness/src/integrationtests/test-deposit-merge.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-deposit-too-large.ts | 4++--
Mpackages/taler-harness/src/integrationtests/test-deposit-twice.ts | 12++++++------
Mpackages/taler-harness/src/integrationtests/test-deposit.ts | 12++++++------
Mpackages/taler-harness/src/integrationtests/test-donau-idempotency.ts | 70++++++++++++++++++++--------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-donau-keychange.ts | 71++++++++++++++++++++---------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-donau-minus-t.ts | 71++++++++++++++++++++---------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-donau-multi.ts | 98++++++++++++++++++++++++-------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-donau.ts | 71++++++++++++++++++++---------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-exchange-currency-change.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-exchange-denom-storage.ts | 12++++++------
Mpackages/taler-harness/src/integrationtests/test-exchange-deposit.ts | 4++--
Mpackages/taler-harness/src/integrationtests/test-exchange-ephemeral.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-exchange-keys-cherrypick.ts | 51++++++++++++++++++---------------------------------
Mpackages/taler-harness/src/integrationtests/test-exchange-keys-withdraw-filter.ts | 38+++++++++++++++-----------------------
Mpackages/taler-harness/src/integrationtests/test-exchange-kyc-auth.ts | 6+++---
Mpackages/taler-harness/src/integrationtests/test-exchange-management-fault.ts | 10++++------
Mpackages/taler-harness/src/integrationtests/test-exchange-master-pub-change.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-exchange-purse.ts | 4++--
Mpackages/taler-harness/src/integrationtests/test-exchange-timetravel.ts | 50+++++++++++++++++++-------------------------------
Mpackages/taler-harness/src/integrationtests/test-fee-regression.ts | 67++++++++++++++++++++++++-------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-forced-selection.ts | 4++--
Mpackages/taler-harness/src/integrationtests/test-known-accounts.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-kyc-amp-failure.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-kyc-amp-timeout.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-kyc-balance-withdrawal.ts | 10+++++-----
Mpackages/taler-harness/src/integrationtests/test-kyc-decisions.ts | 6+++---
Mpackages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate-implicit-auth.ts | 27++++++---------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate.ts | 39+++++++++------------------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-deposit-deposit.ts | 25+++++--------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-deposit-kycauth.ts | 26+++++---------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-form-bad-measure.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-kyc-merchant-aggregate.ts | 25+++++--------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-merchant-wallet-reuse.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-kyc-peer-pull.ts | 31++++++++-----------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-peer-push.ts | 86++++++++-----------------------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-kyc-wallet-deposit-abort.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-libeufin-bank.ts | 23+++++++++++++----------
Mpackages/taler-harness/src/integrationtests/test-libeufin-conversion.ts | 29++++++++++++++---------------
Mpackages/taler-harness/src/integrationtests/test-merchant-acctsel.ts | 23++++++++++-------------
Mpackages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts | 52+++++++++++++---------------------------------------
Mpackages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts | 49++++++++++++++++++-------------------------------
Mpackages/taler-harness/src/integrationtests/test-merchant-exchange-duplicate.ts | 23++++++++++-------------
Mpackages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts | 7++++---
Mpackages/taler-harness/src/integrationtests/test-merchant-longpolling.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-merchant-refund-api.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-merchant-reports.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-merchant-sessions.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts | 14+++++++-------
Mpackages/taler-harness/src/integrationtests/test-merchant-wire.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-multiexchange.ts | 91+++++++++++++++++++++++++++++--------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-otp.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-paivana-repurchase.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-pay-paid.ts | 21+++++++++++++--------
Mpackages/taler-harness/src/integrationtests/test-payment-abort.ts | 21+++++++++++++--------
Mpackages/taler-harness/src/integrationtests/test-payment-claim.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-payment-deleted.ts | 33+++++++++------------------------
Mpackages/taler-harness/src/integrationtests/test-payment-expired.ts | 49++++++++++++-------------------------------------
Mpackages/taler-harness/src/integrationtests/test-payment-forgettable.ts | 19+++++++------------
Mpackages/taler-harness/src/integrationtests/test-payment-multiple.ts | 48++++++++++++++++++------------------------------
Mpackages/taler-harness/src/integrationtests/test-payment-order-gone.ts | 33++++++++++++++-------------------
Mpackages/taler-harness/src/integrationtests/test-payment-template.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-payment-transient.ts | 21+++++++++++++--------
Mpackages/taler-harness/src/integrationtests/test-payment-unclaim.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-payment.ts | 7++++---
Mpackages/taler-harness/src/integrationtests/test-paywall-flow.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-peer-abort-balance.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-peer-abort-before-create.ts | 10+++++-----
Mpackages/taler-harness/src/integrationtests/test-peer-pull-debit-purse-gone.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-peer-pull-large.ts | 32++++++--------------------------
Mpackages/taler-harness/src/integrationtests/test-peer-pull.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-peer-push-large.ts | 32++++++--------------------------
Mpackages/taler-harness/src/integrationtests/test-peer-push.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-peer-repair.ts | 14+++++++-------
Mpackages/taler-harness/src/integrationtests/test-refund-auto.ts | 146+++++++++++++++++--------------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-refund-gone.ts | 103++++++++++++++++++++-----------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-refund-incremental.ts | 120+++++++++++++++++++++----------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-refund.ts | 88++++++++++++++++++++-----------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-repurchase.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-revocation.ts | 71++++++++++++++++++++++++++---------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-simple-payment.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts | 46+++++++++++++++++-----------------------------
Mpackages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts | 12++++++------
Mpackages/taler-harness/src/integrationtests/test-tops-aml-basic.ts | 67+++++++++++--------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-postal.ts | 65++++++++++++-----------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-sms.ts | 60++++++++----------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-aml-p2p-fresh-wallet.ts | 60++++++------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-aml-sanction-preserves-rules.ts | 60++++++------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-aml-stale-validation.ts | 58++++++----------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-merchant-tos.ts | 30++++++------------------------
Mpackages/taler-harness/src/integrationtests/test-tops-peer.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-tops-transaction-risk-monitoring.ts | 9++++-----
Mpackages/taler-harness/src/integrationtests/test-tos-format.ts | 6+++---
Mpackages/taler-harness/src/integrationtests/test-transaction-final-amounts.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-wallet-bad-network.ts | 14+++++---------
Mpackages/taler-harness/src/integrationtests/test-wallet-balance-zero.ts | 17++++++-----------
Mpackages/taler-harness/src/integrationtests/test-wallet-balance.ts | 59++++++++++++++++++++---------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-dbless.ts | 4++--
Mpackages/taler-harness/src/integrationtests/test-wallet-dd48.ts | 40++++++++++------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-denom-expire.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-wallet-deposit-large.ts | 32++++++--------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-devexp-fakeprotover.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-wallet-exchange-features.ts | 58+++++++++++++++++++++++-----------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-exchange-migration.ts | 14+++++++-------
Mpackages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-wallet-gendb.ts | 17++++++-----------
Mpackages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts | 40++++++++++++++++++----------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-network-availability.ts | 8++++----
Mpackages/taler-harness/src/integrationtests/test-wallet-notifications.ts | 54+++++++++++++++++++-----------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-refresh-errors.ts | 18++++++++----------
Mpackages/taler-harness/src/integrationtests/test-wallet-refresh-redenominate.ts | 31+++++++++++++------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-refresh.ts | 19+++++++------------
Mpackages/taler-harness/src/integrationtests/test-wallet-tokens-discount.ts | 29++++++++++++-----------------
Mpackages/taler-harness/src/integrationtests/test-wallet-tokens.ts | 29++++++++++++-----------------
Mpackages/taler-harness/src/integrationtests/test-wallet-transactions.ts | 15+++++----------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-chrome-extension-withdrawal.ts | 47+++++++----------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-integration.ts | 45+++++++--------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-firefox-extension-withdrawal.ts | 47+++++++----------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-peer-tos.ts | 12++++++------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-sqlite.ts | 52++++++----------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts | 49+++++--------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wallet-wirefees.ts | 126+++++--------------------------------------------------------------------------
Mpackages/taler-harness/src/integrationtests/test-wire-metadata.ts | 25+++++++++++--------------
Mpackages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts | 37++++++++++++++++---------------------
Mpackages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts | 12+++++-------
Mpackages/taler-harness/src/integrationtests/test-withdrawal-fees.ts | 38++++++++++++++------------------------
Mpackages/taler-harness/src/integrationtests/test-withdrawal-huge.ts | 26++++++++------------------
Mpackages/taler-harness/src/integrationtests/test-withdrawal-idempotent.ts | 4++--
Mpackages/taler-harness/src/integrationtests/test-withdrawal-shorten.ts | 29++++++++++++++---------------
Mpackages/taler-harness/src/integrationtests/wallet-web-ui-test-support.ts | 12++++++++++--
153 files changed, 1780 insertions(+), 3642 deletions(-)

diff --git a/packages/taler-harness/README.md b/packages/taler-harness/README.md @@ -72,6 +72,39 @@ Use `simple-payment,simple-payment-indexeddb` to select a single pair. ### Each test builds its own environment +Use `createSimpleTestkudosEnvironmentV3` for the standard bank, exchange, +merchant, and wallet setup. Configure denominations and service options at the +call site. It is the only supported version of the standard environment. + +For tests that intercept exchange or merchant traffic, pass +`{ faultInjection: true }` as the third argument. The result additionally +provides `faultyExchange` and `faultyMerchant`; the bank suggestion, advertised +exchange URL, and merchant exchange configuration use the exchange proxy. +Wallet name/persistence and the default merchant wire transfer delay can be +overridden without copying the environment setup. + +Custom environments can reuse `startHarnessBank`, +`makeHarnessExchangeBankAccount`, and `registerHarnessExchangeBankAccount`. +Construct account descriptors before startup, configure the bank suggestion, +then start the bank and register the accounts. Keep service-specific startup +ordering and unusual merchant configuration in the test. Currency-scope tests +can share `createTwoExchangeTestkudosServices` while choosing their merchant's +trusted exchanges explicitly. + +The current workflow helpers are `withdrawViaBankV4`, `makeTestPaymentV2`, and +`applyTimeTravelV2`. Withdrawal takes the bank **service**, including its admin +authentication, and returns the originating account's internal payto URI, +transaction ID, and `withdrawalFinishedCond` promise. Await that promise when +the scenario needs that withdrawal to finish; waiting for all wallet +transactions to finalize is a separate operation. For payment scenarios that +inspect choices or interrupt confirmation, `prepareTestPayment` stops at the +Dialog/Proposed state instead of completing the payment. + +Reuse the wallet-web-UI support module's TCP-port and readiness helpers. Shared +KYC rules, peer-push preparation, Donau startup/charity registration, and +large-coin denomination fixtures have small helpers; keep the scenario's +assertions and deliberate repeated requests in the test itself. + `createSimpleTestkudosEnvironmentV3` (and friends in `harness/environments.ts`) give a test its own directory, its own database and its own service processes. Nothing is carried between tests on purpose. diff --git a/packages/taler-harness/src/harness/denomStructures.ts b/packages/taler-harness/src/harness/denomStructures.ts @@ -155,3 +155,26 @@ export function makeNoFeeCoinConfig(curr: string): CoinConfig[] { return cc; } + +/** One zero-fee coin denomination, to exercise operations with many coins. */ +export function makeLargeCoinTestConfig(): CoinConfig[] { + const coinCommon = { + cipher: "RSA" as const, + durationLegal: "3 years", + durationSpend: "2 years", + durationWithdraw: "7 days", + feeDeposit: "TESTKUDOS:0", + feeRefresh: "TESTKUDOS:0", + feeRefund: "TESTKUDOS:0", + feeWithdraw: "TESTKUDOS:0", + rsaKeySize: 1024, + }; + + return [ + { + ...coinCommon, + name: "n1", + value: "TESTKUDOS:1", + }, + ]; +} diff --git a/packages/taler-harness/src/harness/environments.ts b/packages/taler-harness/src/harness/environments.ts @@ -57,6 +57,10 @@ import { TransactionMajorState, TransactionMinorState, WalletNotification, + AbsoluteTime, + BasicAuth, + TalerProtocolDuration, + TransactionType, } from "@gnu-taler/taler-util"; import { createSyncCryptoApi, @@ -105,23 +109,7 @@ import { const logger = new Logger("helpers.ts"); /** - * Improved version of the simple test environment, - * with the daemonized wallet. - */ -export interface SimpleTestEnvironmentNg { - commonDb: DbInfo; - bank: FakebankService; - exchange: ExchangeService; - exchangeBankAccount: HarnessExchangeBankAccount; - merchant: MerchantService; - merchantAdminAccessToken: AccessToken; - walletClient: WalletClient; - walletService: WalletService; -} - -/** - * Improved version of the simple test environment, - * passing bankClient instead of bank service. + * Standard environment with a bank service and an authenticated Corebank client. */ export interface SimpleTestEnvironmentNg3 { commonDb: DbInfo; @@ -139,7 +127,16 @@ export interface SimpleTestEnvironmentNg3 { }) => Promise<ThenableWebDriver>; } +export interface FaultInjectedTestEnvironment extends SimpleTestEnvironmentNg3 { + faultyExchange: FaultInjectedExchangeService; + faultyMerchant: FaultInjectedMerchantService; +} + export interface EnvOptions { + faultInjection?: boolean; + walletName?: string; + walletPersistent?: boolean; + merchantDefaultWireTransferDelay?: TalerProtocolDuration; /** * If provided, enable age restrictions with the specified age mask string. */ @@ -173,131 +170,58 @@ export interface EnvOptions { additionalBankConfig?(b: BankService): void; } -/** - * Run a test case with a simple TESTKUDOS Taler environment, consisting - * of one exchange, one bank and one merchant. - * - * V2 uses a daemonized wallet instead of the CLI wallet. - */ -export async function createSimpleTestkudosEnvironmentV2( - t: GlobalTestState, - coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")), - opts: EnvOptions = {}, -): Promise<SimpleTestEnvironmentNg> { - const db = await setupDb(t); - - const bank = await FakebankService.create(t, { - allowRegistrations: true, - currency: "TESTKUDOS", - database: db.connStr, - httpPort: 8082, - }); - - const exchange = ExchangeService.create(t, { - name: "testexchange-1", - currency: "TESTKUDOS", - httpPort: 8081, - database: db.connStr, - }); - - const merchant = await MerchantService.create(t, { - name: "testmerchant-1", - httpPort: 8083, - database: db.connStr, - }); - - const exchangeBankAccount = await bank.createExchangeAccount( - "myexchange", - "password", - ); - await exchange.addBankAccount("1", exchangeBankAccount); - - bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); - - if (opts.additionalBankConfig) { - opts.additionalBankConfig(bank); - } +/** Start a configured bank and connect with its administrator credentials. */ +export async function startHarnessBank( + bank: BankService, +): Promise<TalerCorebankApiClient> { await bank.start(); - await bank.pingUntilAvailable(); + const auth = bank.getAdminAuth(); + return new TalerCorebankApiClient(bank.corebankApiBaseUrl, { + auth: + auth.type === "bearer" + ? { username: "admin", password: "admin-password", token: auth.token } + : auth, + preferBearerAuth: bank instanceof LibeufinBankService, + }); +} - const ageMaskSpec = opts.ageMaskSpec; - - if (ageMaskSpec) { - exchange.enableAgeRestrictions(ageMaskSpec); - // Enable age restriction for all coins. - exchange.addCoinConfigList( - coinConfig.map((x) => ({ - ...x, - name: `${x.name}-age`, - ageRestricted: true, - })), - ); - // For mixed age restrictions, we also offer coins without age restrictions - if (opts.mixedAgeRestriction) { - exchange.addCoinConfigList( - coinConfig.map((x) => ({ ...x, ageRestricted: false })), - ); - } - } else { - exchange.addCoinConfigList(coinConfig); - } - - if (opts.additionalExchangeConfig) { - opts.additionalExchangeConfig(exchange); - } - await exchange.start(); - await exchange.pingUntilAvailable(); - - merchant.addExchange(exchange); - - if (opts.additionalMerchantConfig) { - opts.additionalMerchantConfig(merchant); - } - await merchant.start(); - await merchant.pingUntilAvailable(); - - const { accessToken: adminAccessToken } = - await merchant.addInstanceWithWireAccount({ - id: "admin", - name: "Default Instance", - paytoUris: [getTestHarnessPaytoForLabel("merchant-default")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), - }); - - await merchant.addInstanceWithWireAccount( - { - id: "minst1", - name: "minst1", - paytoUris: [getTestHarnessPaytoForLabel("minst1")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), - }, - { adminAccessToken }, - ); - - const { walletClient, walletService } = await createWalletDaemonWithClient( - t, - { name: "wallet", persistent: true }, - ); - - console.log("setup done!"); - +/** Describe an exchange account before starting the bank or registering it. */ +export function makeHarnessExchangeBankAccount( + bank: BankService, + options: Omit< + HarnessExchangeBankAccount, + "wireGatewayApiBaseUrl" | "wireGatewayAuth" + > & { + auth: BasicAuth; + }, +): HarnessExchangeBankAccount { + const { auth, ...accountOptions } = options; return { - commonDb: db, - exchange, - merchant, - merchantAdminAccessToken: adminAccessToken, - walletClient, - walletService, - bank, - exchangeBankAccount, + ...accountOptions, + wireGatewayApiBaseUrl: new URL( + `accounts/${auth.username}/taler-wire-gateway/`, + bank.corebankApiBaseUrl, + ).href, + wireGatewayAuth: auth, }; } +/** Register a previously configured exchange account on a running bank. */ +export async function registerHarnessExchangeBankAccount( + bankClient: TalerCorebankApiClient, + account: HarnessExchangeBankAccount, + name = account.wireGatewayAuth.username, +): Promise<void> { + await bankClient.registerAccountExtended({ + name, + username: account.wireGatewayAuth.username, + password: account.wireGatewayAuth.password, + is_taler_exchange: true, + payto_uri: account.accountPaytoUri, + }); +} + export function createBrowser(t: GlobalTestState) { return async function createBrowser({ browserType, @@ -365,11 +289,21 @@ export function createBrowser(t: GlobalTestState) { * V3 uses the unified Corebank API and allows to choose between * Fakebank and Libeufin-bank. */ +export function createSimpleTestkudosEnvironmentV3( + t: GlobalTestState, + coinConfig: CoinConfig[] | undefined, + opts: EnvOptions & { faultInjection: true }, +): Promise<FaultInjectedTestEnvironment>; +export function createSimpleTestkudosEnvironmentV3( + t: GlobalTestState, + coinConfig?: CoinConfig[], + opts?: EnvOptions, +): Promise<SimpleTestEnvironmentNg3>; export async function createSimpleTestkudosEnvironmentV3( t: GlobalTestState, coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")), opts: EnvOptions = {}, -): Promise<SimpleTestEnvironmentNg3> { +): Promise<SimpleTestEnvironmentNg3 & Partial<FaultInjectedTestEnvironment>> { const db = await setupDb(t); let paivanaDestination = "https://grothoff.org/"; @@ -425,56 +359,51 @@ export async function createSimpleTestkudosEnvironmentV3( database: db.connStr, }); + const faultyExchange = opts.faultInjection + ? new FaultInjectedExchangeService(t, exchange, 9081) + : undefined; + const faultyMerchant = opts.faultInjection + ? new FaultInjectedMerchantService(t, merchant, 9083) + : undefined; + if (faultyExchange) { + await exchange.modifyConfig(async (config) => { + config.setString("exchange", "base_url", faultyExchange.baseUrl); + }); + } + const advertisedExchange = faultyExchange ?? exchange; + const receiverName = "Exchange"; const exchangeBankUsername = "exchange"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; - - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - accountPaytoUri: exchangePaytoUri, - skipWireFeeCreation: opts.skipWireFeeCreation === true, - accountRestrictions: opts.accountRestrictions, - }; - bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + skipWireFeeCreation: opts.skipWireFeeCreation === true, + accountRestrictions: opts.accountRestrictions, + }); + + bank.setSuggestedExchange( + advertisedExchange, + exchangeBankAccount.accountPaytoUri, + ); if (opts.additionalBankConfig) { opts.additionalBankConfig(bank); } - await bank.start(); + const bankClient = await startHarnessBank(bank); - await bank.pingUntilAvailable(); - - const bankAdminAuth = bank.getAdminAuth(); - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: - bankAdminAuth.type === "bearer" - ? { - username: "admin", - password: "admin-password", - token: bankAdminAuth.token, - } - : bankAdminAuth, - preferBearerAuth: bank instanceof LibeufinBankService, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); if (bank instanceof LibeufinBankService) { const coreBankClient = new TalerCoreBankHttpClient(bank.corebankApiBaseUrl); @@ -516,7 +445,7 @@ export async function createSimpleTestkudosEnvironmentV3( } await exchange.start(); - merchant.addExchange(exchange); + merchant.addExchange(advertisedExchange); if (opts.additionalMerchantConfig) { opts.additionalMerchantConfig(merchant); @@ -531,9 +460,9 @@ export async function createSimpleTestkudosEnvironmentV3( id: "admin", name: "Default Instance", paytoUris: [getTestHarnessPaytoForLabel("merchant-default")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), + defaultWireTransferDelay: + opts.merchantDefaultWireTransferDelay ?? + Duration.toTalerProtocolDuration(Duration.fromSpec({ minutes: 1 })), }); await bankClient.registerAccountExtended({ @@ -547,9 +476,9 @@ export async function createSimpleTestkudosEnvironmentV3( id: "minst1", name: "minst1", paytoUris: [getTestHarnessPaytoForLabel("minst1")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), + defaultWireTransferDelay: + opts.merchantDefaultWireTransferDelay ?? + Duration.toTalerProtocolDuration(Duration.fromSpec({ minutes: 1 })), }, { adminAccessToken: merchantAdminAccessToken }, ); @@ -563,8 +492,8 @@ export async function createSimpleTestkudosEnvironmentV3( const { walletClient, walletService } = await createWalletDaemonWithClient( t, { - name: "wallet", - persistent: true, + name: opts.walletName ?? "wallet", + persistent: opts.walletPersistent ?? true, emitObservabilityEvents: !!opts.walletTestObservability, config: opts.walletConfig, logLevel: opts.walletLogLevel, @@ -591,6 +520,8 @@ export async function createSimpleTestkudosEnvironmentV3( console.log("setup done!"); return { + faultyExchange, + faultyMerchant, commonDb: db, exchange, merchant, @@ -672,126 +603,6 @@ export async function createWalletDaemonWithClient( return { walletClient, walletService }; } -export interface FaultyMerchantTestEnvironment { - commonDb: DbInfo; - bank: FakebankService; - exchange: ExchangeService; - faultyExchange: FaultInjectedExchangeService; - exchangeBankAccount: HarnessExchangeBankAccount; - merchant: MerchantService; - merchantAdminAccessToken: AccessToken; - faultyMerchant: FaultInjectedMerchantService; - walletClient: WalletClient; -} - -export interface FaultyMerchantTestEnvironmentNg { - commonDb: DbInfo; - bankClient: TalerCorebankApiClient; - exchange: ExchangeService; - faultyExchange: FaultInjectedExchangeService; - merchant: MerchantService; - merchantAdminAccessToken: AccessToken; - faultyMerchant: FaultInjectedMerchantService; - walletClient: WalletClient; -} - -/** - * Run a test case with a simple TESTKUDOS Taler environment, consisting - * of one exchange, one bank and one merchant. - */ -export async function createFaultInjectedMerchantTestkudosEnvironment( - t: GlobalTestState, -): Promise<FaultyMerchantTestEnvironment> { - const db = await setupDb(t); - - const bank = await FakebankService.create(t, { - allowRegistrations: true, - currency: "TESTKUDOS", - database: db.connStr, - httpPort: 8082, - }); - - const exchange = ExchangeService.create(t, { - name: "testexchange-1", - currency: "TESTKUDOS", - httpPort: 8081, - database: db.connStr, - }); - - const merchant = await MerchantService.create(t, { - name: "testmerchant-1", - httpPort: 8083, - database: db.connStr, - }); - - const faultyMerchant = new FaultInjectedMerchantService(t, merchant, 9083); - const faultyExchange = new FaultInjectedExchangeService(t, exchange, 9081); - - // Base URL must contain port that the proxy is listening on. - await exchange.modifyConfig(async (config) => { - config.setString("exchange", "base_url", "http://localhost:9081/"); - }); - - const exchangeBankAccount = await bank.createExchangeAccount( - "myexchange", - "password", - ); - exchange.addBankAccount("1", exchangeBankAccount); - - bank.setSuggestedExchange( - faultyExchange, - exchangeBankAccount.accountPaytoUri, - ); - - await bank.start(); - - await bank.pingUntilAvailable(); - - exchange.addOfferedCoins(defaultCoinConfig); - - await exchange.start(); - await exchange.pingUntilAvailable(); - - merchant.addExchange(faultyExchange); - - await merchant.start(); - await merchant.pingUntilAvailable(); - - const { accessToken: adminAccessToken } = - await merchant.addInstanceWithWireAccount({ - id: "admin", - name: "Default Instance", - paytoUris: [getTestHarnessPaytoForLabel("merchant-default")], - }); - - await merchant.addInstanceWithWireAccount( - { - id: "minst1", - name: "minst1", - paytoUris: [getTestHarnessPaytoForLabel("minst1")], - }, - { adminAccessToken }, - ); - - console.log("setup done!"); - - const { walletClient } = await createWalletDaemonWithClient(t, { - name: "default", - }); - - return { - commonDb: db, - exchange, - merchant, - walletClient, - merchantAdminAccessToken: adminAccessToken, - bank, - exchangeBankAccount, - faultyMerchant, - faultyExchange, - }; -} - export interface WithdrawViaBankResult { /** * Payto URI of the account that the withdrawal @@ -811,79 +622,6 @@ export interface WithdrawViaBankResult { } /** - * Withdraw via a bank with the testing API enabled. - * Uses the new Corebank API. - * - * @deprecated use withdrawViaBankV4 - */ -export async function withdrawViaBankV3( - t: GlobalTestState, - p: { - walletClient: WalletClient; - bankClient: TalerCorebankApiClient; - exchange: ExchangeServiceInterface; - amount: AmountString | string; - restrictAge?: number; - }, -): Promise<WithdrawViaBankResult> { - const { walletClient: wallet, bankClient, exchange, amount } = p; - - const user = await bankClient.createRandomBankUser(); - const bankClient2 = new TalerCorebankApiClient(bankClient.baseUrl); - bankClient2.setAuth(user); - - const wop = await bankClient2.createWithdrawalOperation( - user.username, - amount, - ); - - // Hand it to the wallet - - await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, { - talerWithdrawUri: wop.taler_withdraw_uri, - restrictAge: p.restrictAge, - }); - - // Withdraw (AKA select) - - const acceptRes = await wallet.client.call( - WalletApiOperation.AcceptBankIntegratedWithdrawal, - { - exchangeBaseUrl: exchange.baseUrl, - talerWithdrawUri: wop.taler_withdraw_uri, - restrictAge: p.restrictAge, - }, - ); - - const withdrawalFinishedCond = wallet.waitForNotificationCond( - (x) => - x.type === NotificationType.TransactionStateTransition && - x.newTxState.major === TransactionMajorState.Done && - x.transactionId === acceptRes.transactionId, - ); - - await wallet.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: acceptRes.transactionId, - txState: { - major: TransactionMajorState.Pending, - minor: TransactionMinorState.BankConfirmTransfer, - }, - }); - - // Confirm it - - await bankClient2.confirmWithdrawalOperation(user.username, { - withdrawalOperationId: wop.withdrawal_id, - }); - - return { - accountPaytoUri: user.accountPaytoUri, - withdrawalFinishedCond, - transactionId: acceptRes.transactionId, - }; -} - -/** * Withdraw via a bank that supports the corebank testing API. */ export async function withdrawViaBankV4( @@ -1053,21 +791,11 @@ export async function makeTestPaymentV2( // Make wallet pay for the order - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, { transactionId: preparePayResult.transactionId, choiceIndex: 0, @@ -1261,41 +989,26 @@ export async function createKycTestkudosEnvironmentFull( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; - - await exchange.addBankAccount("1", { - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - wireGatewayApiBaseUrl, - accountPaytoUri: exchangePaytoUri, - }); + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addCoinConfigList(coinConfig); @@ -1373,16 +1086,6 @@ export async function createKycTestkudosEnvironmentFull( { adminAccessToken }, ); - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - accountPaytoUri: exchangePaytoUri, - wireGatewayApiBaseUrl, - }; - t.logStep("env-setup-done"); const bankApi = new TalerCoreBankHttpClient( @@ -1468,41 +1171,26 @@ export async function createKycTestkudosEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; - - await exchange.addBankAccount("1", { - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - wireGatewayApiBaseUrl, - accountPaytoUri: exchangePaytoUri, - }); + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); + const bankClient = await startHarnessBank(bank); - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addCoinConfigList(coinConfig); @@ -1520,16 +1208,6 @@ export async function createKycTestkudosEnvironment( await exchange.enableAmlAccount(amlKeypair.pub, "Alice"); - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - accountPaytoUri: exchangePaytoUri, - wireGatewayApiBaseUrl, - }; - t.logStep("env-setup-done"); const bankApi = new TalerCoreBankHttpClient( @@ -1633,3 +1311,182 @@ export function configureCommonKyc(config: Configuration): void { config.setString("AML-PROGRAM-NONE", "description", "this does nothing"); config.setString("AML-PROGRAM-NONE", "fallback", "FREEZE"); } + +/** Initiate a peer push and return its URI once the purse is ready. */ +export async function doPeerPushDebit( + t: GlobalTestState, + args: { + walletClient: WalletClient; + amount: AmountString; + summary?: string; + }, +): Promise<{ + transactionId: string; + talerUri: string; +}> { + const purse_expiration = AbsoluteTime.toProtocolTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ days: 2 }), + ), + ); + const initRet = await args.walletClient.call( + WalletApiOperation.InitiatePeerPushDebit, + { + partialContractTerms: { + amount: args.amount, + summary: args.summary ?? "Test P2P Payment", + purse_expiration, + }, + }, + ); + + await args.walletClient.call(WalletApiOperation.TestingWaitTransactionState, { + transactionId: initRet.transactionId, + txState: { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.Ready, + }, + }); + + const txDet = await args.walletClient.call( + WalletApiOperation.GetTransactionById, + { + transactionId: initRet.transactionId, + }, + ); + + t.assertTrue(txDet.type === TransactionType.PeerPushDebit); + const talerUri = txDet.talerUri; + t.assertTrue(!!talerUri); + + return { + transactionId: initRet.transactionId, + talerUri, + }; +} + +/** Configure the INFO check shared by the simple threshold KYC scenarios. */ +export function configureSimpleKycInfoRule( + config: Configuration, + operationType: "aggregate" | "deposit" | "merge" | "withdraw", +): void { + configureCommonKyc(config); + config.setString("KYC-RULE-R1", "operation_type", operationType); + config.setString("KYC-RULE-R1", "enabled", "yes"); + config.setString("KYC-RULE-R1", "exposed", "yes"); + config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); + config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); + config.setString("KYC-RULE-R1", "timeframe", "1d"); + config.setString("KYC-RULE-R1", "next_measures", "M1"); + config.setString("KYC-MEASURE-M1", "check_name", "C1"); + config.setString("KYC-MEASURE-M1", "context", "{}"); + config.setString("KYC-CHECK-C1", "type", "INFO"); + config.setString("KYC-CHECK-C1", "description", "my check!"); + config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); +} + +/** Two independent exchanges sharing a bank, for currency-scope scenarios. */ +export async function createTwoExchangeTestkudosServices(t: GlobalTestState) { + const dbDefault = await setupDb(t); + + const dbExchangeTwo = await setupDb(t, { + nameSuffix: "exchange2", + }); + + const bank = await BankService.create(t, { + allowRegistrations: true, + currency: "TESTKUDOS", + database: dbDefault.connStr, + httpPort: 8082, + }); + + const exchangeOne = ExchangeService.create(t, { + name: "testexchange-1", + currency: "TESTKUDOS", + httpPort: 8081, + database: dbDefault.connStr, + }); + + const exchangeTwo = ExchangeService.create(t, { + name: "testexchange-2", + currency: "TESTKUDOS", + httpPort: 8281, + database: dbExchangeTwo.connStr, + }); + + let exchangeOneBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: "myexchange", + password: "password", + }, + accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), + }); + + let exchangeTwoBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: "myexchange2", + password: "password", + }, + accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), + }); + + bank.setSuggestedExchange( + exchangeOne, + exchangeOneBankAccount.accountPaytoUri, + ); + + const bankClient = await startHarnessBank(bank); + + await registerHarnessExchangeBankAccount(bankClient, exchangeOneBankAccount); + await exchangeOne.addBankAccount("1", exchangeOneBankAccount); + + await registerHarnessExchangeBankAccount(bankClient, exchangeTwoBankAccount); + await exchangeTwo.addBankAccount("1", exchangeTwoBankAccount); + + // Set up the first exchange + + exchangeOne.addOfferedCoins(defaultCoinConfig); + await exchangeOne.start(); + await exchangeOne.pingUntilAvailable(); + + // Set up the second exchange + + exchangeTwo.addOfferedCoins(defaultCoinConfig); + await exchangeTwo.start(); + await exchangeTwo.pingUntilAvailable(); + + return { + commonDb: dbDefault, + exchangeTwoDb: dbExchangeTwo, + bank, + bankClient, + exchangeOne, + exchangeTwo, + exchangeOneBankAccount, + exchangeTwoBankAccount, + }; +} + +/** Prepare a payment and wait until its choices can be inspected or confirmed. */ +export async function prepareTestPayment( + walletClient: WalletClient, + talerPayUri: string, +) { + const result = await walletClient.call( + WalletApiOperation.PreparePayForUriV2, + { talerPayUri }, + ); + await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { + transactionId: result.transactionId, + txState: { + major: TransactionMajorState.Dialog, + minor: TransactionMinorState.Proposed, + }, + }); + return result; +} diff --git a/packages/taler-harness/src/harness/harness-donau.ts b/packages/taler-harness/src/harness/harness-donau.ts @@ -19,9 +19,11 @@ import { ConfigSources, Configuration, DonauHttpClient, + succeedOrThrow, + TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; import * as fs from "node:fs"; -import { CoinConfig } from "./denomStructures.js"; +import { CoinConfig, defaultCoinConfig } from "./denomStructures.js"; import { GlobalTestState, pingProc, ProcessWrapper, sh } from "./harness.js"; /** @@ -339,3 +341,48 @@ function setDonauCoin(config: Configuration, c: CoinConfig) { throw new Error(); } } + +/** Start the donation authority used by the TESTKUDOS donation scenarios. */ +export async function createTestkudosDonau( + t: GlobalTestState, + database: string, +) { + const donau = DonauService.create(t, { + currency: "TESTKUDOS", + database, + httpPort: 8084, + name: "donau", + domain: "Bern", + }); + donau.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); + await donau.start(); + return donau; +} + +/** Register a charity; associating it with the merchant remains a test step. */ +export async function registerDonauMerchantCharity(args: { + donau: DonauService; + merchantInstanceUrl: string; + merchantAccessToken: AccessToken; + charityName: string; + currentYear: number; +}) { + const merchantClient = new TalerMerchantInstanceHttpClient( + args.merchantInstanceUrl, + ); + const inst = succeedOrThrow( + await merchantClient.getCurrentInstanceDetails(args.merchantAccessToken), + ); + const donauClient = new DonauHttpClient(args.donau.baseUrl); + const charity = succeedOrThrow( + await donauClient.createCharity(args.donau.adminAccessToken, { + charity_pub: inst.merchant_pub, + current_year: args.currentYear, + max_per_year: "TESTKUDOS:1000", + charity_name: args.charityName, + receipts_to_date: "TESTKUDOS:0", + charity_url: args.merchantInstanceUrl, + }), + ); + return { charityId: charity.charity_id, merchantPub: inst.merchant_pub }; +} diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts @@ -1491,7 +1491,10 @@ export interface BankServiceHandle { readonly corebankApiBaseUrl: string; readonly http: HttpRequestLibrary; - setSuggestedExchange(exchange: ExchangeService, exchangePayto: string): void; + setSuggestedExchange( + exchange: ExchangeServiceInterface, + exchangePayto: string, + ): void; start(): Promise<void>; pingUntilAvailable(): Promise<void>; stop(): Promise<void>; diff --git a/packages/taler-harness/src/harness/tops.ts b/packages/taler-harness/src/harness/tops.ts @@ -941,29 +941,7 @@ export async function doTopsAcceptTos( accessToken, merchantAdminAccessToken, } = args; - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - t.assertDeepEqual(kycInfo.case, "ok"); - t.assertDeepEqual(kycInfo.body.requirements.length, 1); - t.assertDeepEqual(kycInfo.body.requirements[0].form, "accept-tos"); - const requirementId = kycInfo.body.requirements[0].id; - t.assertTrue(typeof requirementId === "string"); - - const uploadRes = await exchangeClient.uploadKycForm(requirementId, { - FORM_ID: "accept-tos", - FORM_VERSION: 1, - ACCEPTED_TERMS_OF_SERVICE: "v1", - DOWNLOADED_TERMS_OF_SERVICE: true, - }); - console.log("upload res", uploadRes); - t.assertDeepEqual(uploadRes.case, "ok"); - } + await acceptTopsTosForm(t, { exchangeClient, accessToken }); { const kycInfo = await exchangeClient.checkKycInfo( @@ -1393,3 +1371,37 @@ async function doTriggerMeasure( currentDecision: decisionsRespAfter.records[0], }; } + +/** Accept the single advertised ToS form without assuming a merchant state. */ +export async function acceptTopsTosForm( + t: GlobalTestState, + args: { + exchangeClient: TalerExchangeHttpClient; + accessToken: AccessToken; + }, +): Promise<void> { + const { exchangeClient, accessToken } = args; + { + const kycInfo = await exchangeClient.checkKycInfo( + accessToken, + undefined, + undefined, + ); + console.log(j2s(kycInfo)); + + t.assertDeepEqual(kycInfo.case, "ok"); + t.assertDeepEqual(kycInfo.body.requirements.length, 1); + t.assertDeepEqual(kycInfo.body.requirements[0].form, "accept-tos"); + const requirementId = kycInfo.body.requirements[0].id; + t.assertTrue(typeof requirementId === "string"); + + const uploadRes = await exchangeClient.uploadKycForm(requirementId, { + FORM_ID: "accept-tos", + FORM_VERSION: 1, + ACCEPTED_TERMS_OF_SERVICE: "v1", + DOWNLOADED_TERMS_OF_SERVICE: true, + }); + console.log("upload res", uploadRes); + t.assertDeepEqual(uploadRes.case, "ok"); + } +} diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts @@ -87,9 +87,9 @@ import os from "node:os"; import path from "node:path"; import postgres from "postgres"; import { runBench1 } from "./bench1.js"; -import { runBenchWalletDb } from "./benchWalletDb.js"; import { runBench2 } from "./bench2.js"; import { runBench3 } from "./bench3.js"; +import { runBenchWalletDb } from "./benchWalletDb.js"; import { formatChallengerTesterCommandError, runChallengerTester, @@ -98,8 +98,8 @@ import { import { runEnvFull } from "./env-full.js"; import { runEnv1 } from "./env1.js"; import { - createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, + createSimpleTestkudosEnvironmentV3, } from "./harness/environments.js"; import { ExchangeService, @@ -775,7 +775,7 @@ advancedCli exchange, merchant, merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV2(t); + } = await createSimpleTestkudosEnvironmentV3(t); await walletClient.call(WalletApiOperation.RunIntegrationTestV2, { corebankApiBaseUrl: bank.corebankApiBaseUrl, exchangeBaseUrl: exchange.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/kyc-dynamic-measure-helper.ts b/packages/taler-harness/src/integrationtests/kyc-dynamic-measure-helper.ts @@ -27,7 +27,7 @@ import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecision, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; @@ -88,14 +88,14 @@ export async function runDynamicMeasureScenario( assertRequirements: (info: KycProcessClientInformation) => void; }, ): Promise<void> { - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig: (config) => configureDynamicMeasureExchange(config, args.amlProgramName), }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:20", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/kyc-form-withdrawal-helper.ts b/packages/taler-harness/src/integrationtests/kyc-form-withdrawal-helper.ts @@ -26,7 +26,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { configureCommonKyc, createKycTestkudosEnvironmentFull, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -73,11 +73,11 @@ export async function runKycFormWithdrawalScenario( t: GlobalTestState, upload: { body: object; compress?: "deflate" }, ): Promise<void> { - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:20", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/kyc-threshold-withdrawal-helper.ts b/packages/taler-harness/src/integrationtests/kyc-threshold-withdrawal-helper.ts @@ -16,22 +16,14 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, + configureSimpleKycInfoRule, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; function adjustExchangeConfig(config: Configuration): void { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "withdraw"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); + configureSimpleKycInfoRule(config, "withdraw"); config.setString("KYC-RULE-R2", "operation_type", "withdraw"); config.setString("KYC-RULE-R2", "enabled", "yes"); @@ -40,13 +32,6 @@ function adjustExchangeConfig(config: Configuration): void { config.setString("KYC-RULE-R2", "threshold", "TESTKUDOS:300"); config.setString("KYC-RULE-R2", "timeframe", "1d"); config.setString("KYC-RULE-R2", "next_measures", "verboten"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); } /** Run the common successful withdrawal that establishes an AML account. */ diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-deposit.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-deposit.ts @@ -26,7 +26,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -39,7 +39,7 @@ import { export async function runAgeRestrictionsDepositTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3( t, defaultCoinConfig.map((x) => x("TESTKUDOS")), @@ -50,9 +50,9 @@ export async function runAgeRestrictionsDepositTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const withdrawalResult = await withdrawViaBankV3(t, { + const withdrawalResult = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts @@ -24,7 +24,7 @@ import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -35,8 +35,8 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient: walletClientOne, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -66,9 +66,9 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { name: "w0", }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient: walletClientZero, - bankClient, + bank, exchange, amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, @@ -97,9 +97,9 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { { const walletClient = walletClientOne; - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", restrictAge: 13, @@ -128,9 +128,9 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { { const walletClient = walletClientTwo; - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, @@ -158,9 +158,9 @@ export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) { { const walletClient = walletClientThree; - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20" as AmountString, }); diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-mixed-merchant.ts @@ -24,7 +24,7 @@ import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -35,8 +35,8 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient: walletOne, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -60,9 +60,9 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { { const walletClient = walletOne; - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, @@ -90,9 +90,9 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { } { - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient: walletTwo, - bankClient, + bank, exchange, amount: "TESTKUDOS:20" as AmountString, restrictAge: 13, @@ -116,9 +116,9 @@ export async function runAgeRestrictionsMixedMerchantTest(t: GlobalTestState) { } { - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient: walletThree, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts b/packages/taler-harness/src/integrationtests/test-age-restrictions-peer.ts @@ -31,7 +31,7 @@ import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -41,7 +41,7 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runAgeRestrictionsPeerTest(t: GlobalTestState) { // Set up test environment - const { bankClient, exchange } = await createSimpleTestkudosEnvironmentV3( + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3( t, defaultCoinConfig.map((x) => x("TESTKUDOS")), { @@ -62,9 +62,9 @@ export async function runAgeRestrictionsPeerTest(t: GlobalTestState) { const wallet2 = w2.walletClient; { - const withdrawalRes = await withdrawViaBankV3(t, { + const withdrawalRes = await withdrawViaBankV4(t, { walletClient: wallet1, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", restrictAge: 13, diff --git a/packages/taler-harness/src/integrationtests/test-bank-api.ts b/packages/taler-harness/src/integrationtests/test-bank-api.ts @@ -28,6 +28,10 @@ import { } from "@gnu-taler/taler-util"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, +} from "../harness/environments.js"; +import { BankService, ExchangeService, GlobalTestState, @@ -78,11 +82,11 @@ export async function runBankApiTest(t: GlobalTestState) { "accounts/exchange/taler-wire-gateway/", bank.baseUrl, ).href; - await exchange.addBankAccount("1", { - wireGatewayAuth, - wireGatewayApiBaseUrl, + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: wireGatewayAuth, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); @@ -127,13 +131,11 @@ export async function runBankApiTest(t: GlobalTestState) { }, }); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); const bankUser = await bankClient.registerAccount("user1", "password1"); diff --git a/packages/taler-harness/src/integrationtests/test-claim-loop.ts b/packages/taler-harness/src/integrationtests/test-claim-loop.ts @@ -30,7 +30,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -46,17 +46,12 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runClaimLoopTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-clause-schnorr.ts b/packages/taler-harness/src/integrationtests/test-clause-schnorr.ts @@ -20,12 +20,12 @@ import { TalerMerchantApi } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; -import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -55,19 +55,14 @@ export async function runClauseSchnorrTest(t: GlobalTestState) { name: "rsa_dummy", }); - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t, coinConfig); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t, coinConfig); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-coinsel-legacy-2024.ts b/packages/taler-harness/src/integrationtests/test-coinsel-legacy-2024.ts @@ -20,9 +20,9 @@ import { AmountString, j2s, TransactionIdStr } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - createSimpleTestkudosEnvironmentV2, createWalletDaemonWithClient, makeTestPaymentV2, + createSimpleTestkudosEnvironmentV3, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; @@ -70,7 +70,7 @@ async function withdrawAndPay( args: { name: string; extraEnv?: Record<string, string>; - env: Awaited<ReturnType<typeof createSimpleTestkudosEnvironmentV2>>; + env: Awaited<ReturnType<typeof createSimpleTestkudosEnvironmentV3>>; }, ): Promise<SpentCoin[]> { const { bank, exchange, merchant, merchantAdminAccessToken } = args.env; @@ -145,7 +145,7 @@ export async function runCoinselLegacy2024Test(t: GlobalTestState) { "the test explicitly starts one comparison wallet with the legacy-2024 coin-selection algorithm", }); - const env = await createSimpleTestkudosEnvironmentV2(t); + const env = await createSimpleTestkudosEnvironmentV3(t); const legacySpent = await withdrawAndPay(t, { name: "legacy", diff --git a/packages/taler-harness/src/integrationtests/test-currency-scope-separation.ts b/packages/taler-harness/src/integrationtests/test-currency-scope-separation.ts @@ -20,56 +20,31 @@ import { Duration, ScopeType, - TalerCorebankApiClient, TalerMerchantInstanceHttpClient, j2s, succeedOrThrow, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + createTwoExchangeTestkudosServices, + withdrawViaBankV4, } from "../harness/environments.js"; import { - BankService, - ExchangeService, GlobalTestState, - HarnessExchangeBankAccount, MerchantService, getTestHarnessPaytoForLabel, - setupDb, } from "../harness/harness.js"; export async function runCurrencyScopeSeparationTest(t: GlobalTestState) { // Set up test environment - const dbDefault = await setupDb(t); - - const dbExchangeTwo = await setupDb(t, { - nameSuffix: "exchange2", - }); - - const bank = await BankService.create(t, { - allowRegistrations: true, - currency: "TESTKUDOS", - database: dbDefault.connStr, - httpPort: 8082, - }); - - const exchangeOne = ExchangeService.create(t, { - name: "testexchange-1", - currency: "TESTKUDOS", - httpPort: 8081, - database: dbDefault.connStr, - }); - - const exchangeTwo = ExchangeService.create(t, { - name: "testexchange-2", - currency: "TESTKUDOS", - httpPort: 8281, - database: dbExchangeTwo.connStr, - }); + const { + commonDb: dbDefault, + bank, + exchangeOne, + exchangeTwo, + } = await createTwoExchangeTestkudosServices(t); const merchant = await MerchantService.create(t, { name: "testmerchant-1", @@ -77,78 +52,6 @@ export async function runCurrencyScopeSeparationTest(t: GlobalTestState) { database: dbDefault.connStr, }); - let exchangeOneBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { - type: "basic", - username: "myexchange", - password: "password", - }, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), - }; - - let exchangeTwoBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange2/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { - type: "basic", - username: "myexchange2", - password: "password", - }, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), - }; - - bank.setSuggestedExchange( - exchangeOne, - exchangeOneBankAccount.accountPaytoUri, - ); - - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: exchangeOneBankAccount.wireGatewayAuth.username, - username: exchangeOneBankAccount.wireGatewayAuth.username, - password: exchangeOneBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeOneBankAccount.accountPaytoUri, - }); - await exchangeOne.addBankAccount("1", exchangeOneBankAccount); - - await bankClient.registerAccountExtended({ - name: exchangeTwoBankAccount.wireGatewayAuth.username, - username: exchangeTwoBankAccount.wireGatewayAuth.username, - password: exchangeTwoBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeTwoBankAccount.accountPaytoUri, - }); - await exchangeTwo.addBankAccount("1", exchangeTwoBankAccount); - - // Set up the first exchange - - exchangeOne.addOfferedCoins(defaultCoinConfig); - await exchangeOne.start(); - await exchangeOne.pingUntilAvailable(); - - // Set up the second exchange - - exchangeTwo.addOfferedCoins(defaultCoinConfig); - await exchangeTwo.start(); - await exchangeTwo.pingUntilAvailable(); - // Start and configure merchant merchant.addExchange(exchangeOne); @@ -174,16 +77,16 @@ export async function runCurrencyScopeSeparationTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const w1 = await withdrawViaBankV3(t, { + const w1 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: exchangeOne, amount: "TESTKUDOS:15", }); - const w2 = await withdrawViaBankV3(t, { + const w2 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: exchangeTwo, amount: "TESTKUDOS:1", }); diff --git a/packages/taler-harness/src/integrationtests/test-currency-scope.ts b/packages/taler-harness/src/integrationtests/test-currency-scope.ts @@ -17,57 +17,28 @@ /** * Imports. */ -import { - Duration, - ScopeType, - TalerCorebankApiClient, - j2s, -} from "@gnu-taler/taler-util"; +import { Duration, ScopeType, j2s } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + createTwoExchangeTestkudosServices, + withdrawViaBankV4, } from "../harness/environments.js"; import { - BankService, - ExchangeService, GlobalTestState, - HarnessExchangeBankAccount, MerchantService, getTestHarnessPaytoForLabel, - setupDb, } from "../harness/harness.js"; export async function runCurrencyScopeTest(t: GlobalTestState) { // Set up test environment - const dbDefault = await setupDb(t); - - const dbExchangeTwo = await setupDb(t, { - nameSuffix: "exchange2", - }); - - const bank = await BankService.create(t, { - allowRegistrations: true, - currency: "TESTKUDOS", - database: dbDefault.connStr, - httpPort: 8082, - }); - - const exchangeOne = ExchangeService.create(t, { - name: "testexchange-1", - currency: "TESTKUDOS", - httpPort: 8081, - database: dbDefault.connStr, - }); - - const exchangeTwo = ExchangeService.create(t, { - name: "testexchange-2", - currency: "TESTKUDOS", - httpPort: 8281, - database: dbExchangeTwo.connStr, - }); + const { + commonDb: dbDefault, + bank, + exchangeOne, + exchangeTwo, + } = await createTwoExchangeTestkudosServices(t); const merchant = await MerchantService.create(t, { name: "testmerchant-1", @@ -75,78 +46,6 @@ export async function runCurrencyScopeTest(t: GlobalTestState) { database: dbDefault.connStr, }); - let exchangeOneBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { - type: "basic", - username: "myexchange", - password: "password", - }, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), - }; - - let exchangeTwoBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange2/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { - type: "basic", - username: "myexchange2", - password: "password", - }, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), - }; - - bank.setSuggestedExchange( - exchangeOne, - exchangeOneBankAccount.accountPaytoUri, - ); - - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: exchangeOneBankAccount.wireGatewayAuth.username, - username: exchangeOneBankAccount.wireGatewayAuth.username, - password: exchangeOneBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeOneBankAccount.accountPaytoUri, - }); - await exchangeOne.addBankAccount("1", exchangeOneBankAccount); - - await bankClient.registerAccountExtended({ - name: exchangeTwoBankAccount.wireGatewayAuth.username, - username: exchangeTwoBankAccount.wireGatewayAuth.username, - password: exchangeTwoBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeTwoBankAccount.accountPaytoUri, - }); - await exchangeTwo.addBankAccount("1", exchangeTwoBankAccount); - - // Set up the first exchange - - exchangeOne.addOfferedCoins(defaultCoinConfig); - await exchangeOne.start(); - await exchangeOne.pingUntilAvailable(); - - // Set up the second exchange - - exchangeTwo.addOfferedCoins(defaultCoinConfig); - await exchangeTwo.start(); - await exchangeTwo.pingUntilAvailable(); - // Start and configure merchant merchant.addExchange(exchangeOne); @@ -185,16 +84,16 @@ export async function runCurrencyScopeTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const w1 = await withdrawViaBankV3(t, { + const w1 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: exchangeOne, amount: "TESTKUDOS:6", }); - const w2 = await withdrawViaBankV3(t, { + const w2 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: exchangeTwo, amount: "TESTKUDOS:6", }); diff --git a/packages/taler-harness/src/integrationtests/test-denom-revoked-balance.ts b/packages/taler-harness/src/integrationtests/test-denom-revoked-balance.ts @@ -35,7 +35,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -68,15 +68,15 @@ export async function runDenomRevokedBalanceTest(t: GlobalTestState) { "the test revokes one denomination and exercises the currently disabled recoup endpoint (exchange FIXME 9828), then verifies the resulting lost balance", }); - const { walletClient, bankClient, exchange } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3( t, makeNoFeeCoinConfig("TESTKUDOS"), ); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: initialAmount, }); diff --git a/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts b/packages/taler-harness/src/integrationtests/test-denom-unoffered.ts @@ -29,7 +29,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -64,19 +64,14 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { "the test deliberately removes denominations after withdrawal and verifies the wallet's accounting for the four affected coins", }); - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -180,9 +175,9 @@ export async function runDenomUnofferedTest(t: GlobalTestState) { logger.info(`withdrawing (with new denoms)`); // Now withdrawal should work again. - const wres2 = await withdrawViaBankV3(t, { + const wres2 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-deposit-fault.ts b/packages/taler-harness/src/integrationtests/test-deposit-fault.ts @@ -25,14 +25,16 @@ import { HttpStatusCode, j2s, openPromise, - TalerCorebankApiClient, TransactionMajorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectedExchangeService, @@ -75,18 +77,15 @@ export async function runDepositFaultTest(t: GlobalTestState) { let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); const faultyExchange = new FaultInjectedExchangeService(t, exchange, 8091); // Base URL must contain port that the proxy is listening on. @@ -96,24 +95,13 @@ export async function runDepositFaultTest(t: GlobalTestState) { bank.setSuggestedExchange(faultyExchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addOfferedCoins(defaultCoinConfig); @@ -138,9 +126,9 @@ export async function runDepositFaultTest(t: GlobalTestState) { await walletClient.call(WalletApiOperation.GetBalances, {}); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-deposit-merge.ts b/packages/taler-harness/src/integrationtests/test-deposit-merge.ts @@ -28,7 +28,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -47,7 +47,7 @@ export async function runDepositMergeTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); async function setTimeOffset(minutes: number): Promise<void> { @@ -63,9 +63,9 @@ export async function runDepositMergeTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const withdrawalResult = await withdrawViaBankV3(t, { + const withdrawalResult = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:50", }); diff --git a/packages/taler-harness/src/integrationtests/test-deposit-too-large.ts b/packages/taler-harness/src/integrationtests/test-deposit-too-large.ts @@ -34,7 +34,7 @@ import { topupReserveWithBank, withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; /** @@ -60,7 +60,7 @@ export async function runDepositTooLargeTest(t: GlobalTestState) { // Set up test environment - const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); const http = harnessHttpLib; const cryptiDisp = new CryptoDispatcher( diff --git a/packages/taler-harness/src/integrationtests/test-deposit-twice.ts b/packages/taler-harness/src/integrationtests/test-deposit-twice.ts @@ -27,7 +27,7 @@ import { CoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -80,8 +80,8 @@ const coinConfigList: CoinConfig[] = topsValues.map( export async function runDepositTwiceTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient: aliceWallet, - bankClient, exchange, } = await createSimpleTestkudosEnvironmentV3(t, coinConfigList); @@ -90,15 +90,15 @@ export async function runDepositTwiceTest(t: GlobalTestState) { }); // I sent 50.- to device A and 5.-- to device B from different bank accounts. - const aliceWithdrawRes = await withdrawViaBankV3(t, { + const aliceWithdrawRes = await withdrawViaBankV4(t, { walletClient: aliceWallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:50", }); - const bobWithdrawRes = await withdrawViaBankV3(t, { + const bobWithdrawRes = await withdrawViaBankV4(t, { walletClient: bobWallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:5", }); diff --git a/packages/taler-harness/src/integrationtests/test-deposit.ts b/packages/taler-harness/src/integrationtests/test-deposit.ts @@ -26,7 +26,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -39,15 +39,15 @@ import { export async function runDepositTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. { - const withdrawalResult = await withdrawViaBankV3(t, { + const withdrawalResult = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -143,9 +143,9 @@ export async function runDepositTest(t: GlobalTestState) { // Now, test tiny deposits where fees eat the amount! { - const withdrawalResult = await withdrawViaBankV3(t, { + const withdrawalResult = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:5", }); diff --git a/packages/taler-harness/src/integrationtests/test-donau-idempotency.ts b/packages/taler-harness/src/integrationtests/test-donau-idempotency.ts @@ -28,23 +28,25 @@ import { succeedOrThrow, TalerMerchantInstanceHttpClient, TransactionMajorState, - TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; -import { DonauService } from "../harness/harness-donau.js"; +import { + createTestkudosDonau, + registerDonauMerchantCharity, +} from "../harness/harness-donau.js"; import { delayMs, GlobalTestState } from "../harness/harness.js"; export async function runDonauIdempotencyTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -59,49 +61,29 @@ export async function runDonauIdempotencyTest(t: GlobalTestState) { }, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, amount: "TESTKUDOS:100", exchange, }); await wres.withdrawalFinishedCond; - const donau = DonauService.create(t, { - currency: "TESTKUDOS", - database: commonDb.connStr, - httpPort: 8084, - name: "donau", - domain: "Bern", - }); - - donau.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); - - await donau.start(); + const donau = await createTestkudosDonau(t, commonDb.connStr); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); - const inst = succeedOrThrow( - await merchantClient.getCurrentInstanceDetails(merchantAdminAccessToken), - ); - const merchantPub = inst.merchant_pub; - const donauClient = new DonauHttpClient(donau.baseUrl); - const currentYear = new Date().getFullYear(); - - const charityResp = succeedOrThrow( - await donauClient.createCharity(donau.adminAccessToken, { - charity_pub: merchantPub, - current_year: currentYear, - max_per_year: "TESTKUDOS:1000", - charity_name: "42", - receipts_to_date: "TESTKUDOS:0", - charity_url: merchant.makeInstanceBaseUrl(), - }), - ); + const { charityId } = await registerDonauMerchantCharity({ + donau, + merchantInstanceUrl: merchant.makeInstanceBaseUrl(), + merchantAccessToken: merchantAdminAccessToken, + charityName: "42", + currentYear, + }); const config = await donauClient.getConfig(); console.log(`config: ${j2s(config)}`); @@ -109,8 +91,6 @@ export async function runDonauIdempotencyTest(t: GlobalTestState) { const keys = await donauClient.getKeys(); console.log(`keys: ${j2s(keys)}`); - const charityId = charityResp["charity_id"]; - succeedOrThrow( await merchantClient.postDonau({ body: { @@ -190,21 +170,11 @@ export async function runDonauIdempotencyTest(t: GlobalTestState) { t.assertTrue(orderStatus.order_status === "unpaid"); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - const choicesResult = await walletClient.call( WalletApiOperation.GetChoicesForPayment, { diff --git a/packages/taler-harness/src/integrationtests/test-donau-keychange.ts b/packages/taler-harness/src/integrationtests/test-donau-keychange.ts @@ -28,24 +28,25 @@ import { OrderVersion, succeedOrThrow, TalerMerchantInstanceHttpClient, - TransactionMajorState, - TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; -import { DonauService } from "../harness/harness-donau.js"; +import { + createTestkudosDonau, + registerDonauMerchantCharity, +} from "../harness/harness-donau.js"; import { delayMs, GlobalTestState } from "../harness/harness.js"; export async function runDonauKeychangeTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -57,49 +58,29 @@ export async function runDonauKeychangeTest(t: GlobalTestState) { }, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, amount: "TESTKUDOS:100", exchange, }); await wres.withdrawalFinishedCond; - const donau = DonauService.create(t, { - currency: "TESTKUDOS", - database: commonDb.connStr, - httpPort: 8084, - name: "donau", - domain: "Bern", - }); - - donau.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); - - await donau.start(); + const donau = await createTestkudosDonau(t, commonDb.connStr); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); - const inst = succeedOrThrow( - await merchantClient.getCurrentInstanceDetails(merchantAdminAccessToken), - ); - const merchantPub = inst.merchant_pub; - const donauClient = new DonauHttpClient(donau.baseUrl); - const currentYear = new Date().getFullYear(); - - const charityResp = succeedOrThrow( - await donauClient.createCharity(donau.adminAccessToken, { - charity_pub: merchantPub, - current_year: currentYear, - max_per_year: "TESTKUDOS:1000", - charity_name: "42", - receipts_to_date: "TESTKUDOS:0", - charity_url: merchant.makeInstanceBaseUrl(), - }), - ); + const { charityId } = await registerDonauMerchantCharity({ + donau, + merchantInstanceUrl: merchant.makeInstanceBaseUrl(), + merchantAccessToken: merchantAdminAccessToken, + charityName: "42", + currentYear, + }); const config = await donauClient.getConfig(); console.log(`config: ${j2s(config)}`); @@ -107,8 +88,6 @@ export async function runDonauKeychangeTest(t: GlobalTestState) { const keys = await donauClient.getKeys(); console.log(`keys: ${j2s(keys)}`); - const charityId = charityResp["charity_id"]; - succeedOrThrow( await merchantClient.postDonau({ body: { @@ -197,21 +176,11 @@ export async function runDonauKeychangeTest(t: GlobalTestState) { t.assertTrue(orderStatus.order_status === "unpaid"); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - const choicesResult = await walletClient.call( WalletApiOperation.GetChoicesForPayment, { diff --git a/packages/taler-harness/src/integrationtests/test-donau-minus-t.ts b/packages/taler-harness/src/integrationtests/test-donau-minus-t.ts @@ -27,24 +27,25 @@ import { OrderVersion, succeedOrThrow, TalerMerchantInstanceHttpClient, - TransactionMajorState, - TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; -import { DonauService } from "../harness/harness-donau.js"; +import { + createTestkudosDonau, + registerDonauMerchantCharity, +} from "../harness/harness-donau.js"; import { GlobalTestState } from "../harness/harness.js"; export async function runDonauMinusTTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -55,49 +56,29 @@ export async function runDonauMinusTTest(t: GlobalTestState) { }, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, amount: "TESTKUDOS:20", exchange, }); await wres.withdrawalFinishedCond; - const donau = DonauService.create(t, { - currency: "TESTKUDOS", - database: commonDb.connStr, - httpPort: 8084, - name: "donau", - domain: "Bern", - }); - - donau.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); - - await donau.start(); + const donau = await createTestkudosDonau(t, commonDb.connStr); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); - const inst = succeedOrThrow( - await merchantClient.getCurrentInstanceDetails(merchantAdminAccessToken), - ); - const merchantPub = inst.merchant_pub; - const donauClient = new DonauHttpClient(donau.baseUrl); - const currentYear = new Date().getFullYear(); - - const charityResp = succeedOrThrow( - await donauClient.createCharity(donau.adminAccessToken, { - charity_pub: merchantPub, - current_year: currentYear, - max_per_year: "TESTKUDOS:1000", - charity_name: "42", - receipts_to_date: "TESTKUDOS:0", - charity_url: merchant.makeInstanceBaseUrl(), - }), - ); + const { charityId } = await registerDonauMerchantCharity({ + donau, + merchantInstanceUrl: merchant.makeInstanceBaseUrl(), + merchantAccessToken: merchantAdminAccessToken, + charityName: "42", + currentYear, + }); const config = await donauClient.getConfig(); console.log(`config: ${j2s(config)}`); @@ -105,8 +86,6 @@ export async function runDonauMinusTTest(t: GlobalTestState) { const keys = await donauClient.getKeys(); console.log(`keys: ${j2s(keys)}`); - const charityId = charityResp["charity_id"]; - succeedOrThrow( await merchantClient.postDonau({ body: { @@ -156,21 +135,11 @@ export async function runDonauMinusTTest(t: GlobalTestState) { taxPayerId: "test-tax-payer", }); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - const choicesResult = await walletClient.call( WalletApiOperation.GetChoicesForPayment, { diff --git a/packages/taler-harness/src/integrationtests/test-donau-multi.ts b/packages/taler-harness/src/integrationtests/test-donau-multi.ts @@ -28,16 +28,17 @@ import { OrderVersion, succeedOrThrow, TalerMerchantInstanceHttpClient, - TransactionMajorState, - TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; -import { DonauService } from "../harness/harness-donau.js"; +import { + createTestkudosDonau, + registerDonauMerchantCharity, +} from "../harness/harness-donau.js"; import { delayMs, getTestHarnessPaytoForLabel, @@ -48,8 +49,8 @@ export async function runDonauMultiTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -61,51 +62,30 @@ export async function runDonauMultiTest(t: GlobalTestState) { }, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, amount: "TESTKUDOS:100", exchange, }); await wres.withdrawalFinishedCond; - const donau = DonauService.create(t, { - currency: "TESTKUDOS", - database: commonDb.connStr, - httpPort: 8084, - name: "donau", - domain: "Bern", - }); - - donau.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); - - await donau.start(); + const donau = await createTestkudosDonau(t, commonDb.connStr); const merchantClient1 = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); - const inst1 = succeedOrThrow( - await merchantClient1.getCurrentInstanceDetails(merchantAdminAccessToken), - ); - const merchantPub1 = inst1.merchant_pub; - const donauClient = new DonauHttpClient(donau.baseUrl); - const currentYear = new Date().getFullYear(); - - const charityResp1 = succeedOrThrow( - await donauClient.createCharity(donau.adminAccessToken, { - charity_pub: merchantPub1, - current_year: currentYear, - max_per_year: "TESTKUDOS:1000", - charity_name: "42", - receipts_to_date: "TESTKUDOS:0", - charity_url: merchant.makeInstanceBaseUrl(), - }), - ); - - const charityId1 = charityResp1["charity_id"]; + const { charityId: charityId1, merchantPub: merchantPub1 } = + await registerDonauMerchantCharity({ + donau, + merchantInstanceUrl: merchant.makeInstanceBaseUrl(), + merchantAccessToken: merchantAdminAccessToken, + charityName: "42", + currentYear, + }); succeedOrThrow( await merchantClient1.postDonau({ @@ -135,27 +115,17 @@ export async function runDonauMultiTest(t: GlobalTestState) { merchant.makeInstanceBaseUrl("minst2"), ); - const inst2 = succeedOrThrow( - await merchantClient2.getCurrentInstanceDetails(tok2), - ); - const merchantPub2 = inst2.merchant_pub; - + const { charityId: charityId2, merchantPub: merchantPub2 } = + await registerDonauMerchantCharity({ + donau, + merchantInstanceUrl: merchant.makeInstanceBaseUrl("minst2"), + merchantAccessToken: tok2, + charityName: "43", + currentYear, + }); console.log(`pub1: ${merchantPub1}`); console.log(`pub2: ${merchantPub2}`); - const charityResp2 = succeedOrThrow( - await donauClient.createCharity(donau.adminAccessToken, { - charity_pub: merchantPub2, - current_year: currentYear, - max_per_year: "TESTKUDOS:1000", - charity_name: "43", - receipts_to_date: "TESTKUDOS:0", - charity_url: merchant.makeInstanceBaseUrl("minst2"), - }), - ); - - const charityId2 = charityResp2["charity_id"]; - succeedOrThrow( await merchantClient2.postDonau({ body: { @@ -231,21 +201,11 @@ export async function runDonauMultiTest(t: GlobalTestState) { t.assertTrue(orderStatus.order_status === "unpaid"); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - const choicesResult = await walletClient.call( WalletApiOperation.GetChoicesForPayment, { diff --git a/packages/taler-harness/src/integrationtests/test-donau.ts b/packages/taler-harness/src/integrationtests/test-donau.ts @@ -28,24 +28,25 @@ import { OrderVersion, succeedOrThrow, TalerMerchantInstanceHttpClient, - TransactionMajorState, - TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; -import { DonauService } from "../harness/harness-donau.js"; +import { + createTestkudosDonau, + registerDonauMerchantCharity, +} from "../harness/harness-donau.js"; import { delayMs, GlobalTestState } from "../harness/harness.js"; export async function runDonauTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -57,49 +58,29 @@ export async function runDonauTest(t: GlobalTestState) { }, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, amount: "TESTKUDOS:100", exchange, }); await wres.withdrawalFinishedCond; - const donau = DonauService.create(t, { - currency: "TESTKUDOS", - database: commonDb.connStr, - httpPort: 8084, - name: "donau", - domain: "Bern", - }); - - donau.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); - - await donau.start(); + const donau = await createTestkudosDonau(t, commonDb.connStr); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); - const inst = succeedOrThrow( - await merchantClient.getCurrentInstanceDetails(merchantAdminAccessToken), - ); - const merchantPub = inst.merchant_pub; - const donauClient = new DonauHttpClient(donau.baseUrl); - const currentYear = new Date().getFullYear(); - - const charityResp = succeedOrThrow( - await donauClient.createCharity(donau.adminAccessToken, { - charity_pub: merchantPub, - current_year: currentYear, - max_per_year: "TESTKUDOS:1000", - charity_name: "42", - receipts_to_date: "TESTKUDOS:0", - charity_url: merchant.makeInstanceBaseUrl(), - }), - ); + const { charityId } = await registerDonauMerchantCharity({ + donau, + merchantInstanceUrl: merchant.makeInstanceBaseUrl(), + merchantAccessToken: merchantAdminAccessToken, + charityName: "42", + currentYear, + }); const config = await donauClient.getConfig(); console.log(`config: ${j2s(config)}`); @@ -107,8 +88,6 @@ export async function runDonauTest(t: GlobalTestState) { const keys = await donauClient.getKeys(); console.log(`keys: ${j2s(keys)}`); - const charityId = charityResp["charity_id"]; - succeedOrThrow( await merchantClient.postDonau({ body: { @@ -191,21 +170,11 @@ export async function runDonauTest(t: GlobalTestState) { t.assertTrue(orderStatus.order_status === "unpaid"); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - const choicesResult = await walletClient.call( WalletApiOperation.GetChoicesForPayment, { diff --git a/packages/taler-harness/src/integrationtests/test-exchange-currency-change.ts b/packages/taler-harness/src/integrationtests/test-exchange-currency-change.ts @@ -26,7 +26,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { ExchangeService, @@ -55,13 +55,13 @@ export async function runExchangeCurrencyChangeTest( "the test replaces the exchange at the same URL with one using another currency and verifies that the wallet detects the incompatible key set", }); - const { walletClient, exchange, bankClient, exchangeBankAccount } = + const { bank, walletClient, exchange, exchangeBankAccount } = await createSimpleTestkudosEnvironmentV3(t); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, amount: "TESTKUDOS:10", - bankClient, + bank, exchange, }); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-denom-storage.ts b/packages/taler-harness/src/integrationtests/test-exchange-denom-storage.ts @@ -23,7 +23,7 @@ import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -52,15 +52,15 @@ export async function runExchangeDenomStorageTest( // Set up test environment - const { walletClient, bankClient, exchange, merchant } = + const { bank, walletClient, exchange, merchant } = await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet, so that it holds coins of the // denominations the exchange currently issues. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -160,9 +160,9 @@ export async function runExchangeDenomStorageTest( t.logStep("fresh wallet stored only the withdrawable denominations"); // What it stored is enough to withdraw with. - const wres2 = await withdrawViaBankV3(t, { + const wres2 = await withdrawViaBankV4(t, { walletClient: freshWalletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:10", }); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts b/packages/taler-harness/src/integrationtests/test-exchange-deposit.ts @@ -39,7 +39,7 @@ import { topupReserveWithBank, withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; const logger = new Logger("test-exchange-deposit.ts"); @@ -47,7 +47,7 @@ const logger = new Logger("test-exchange-deposit.ts"); export async function runExchangeDepositTest(t: GlobalTestState) { // Set up test environment - const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); const http = createPlatformHttpLib({ enableThrottling: false, diff --git a/packages/taler-harness/src/integrationtests/test-exchange-ephemeral.ts b/packages/taler-harness/src/integrationtests/test-exchange-ephemeral.ts @@ -29,7 +29,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -49,7 +49,7 @@ interface WalletDaemon { * ephemeral and is kept. */ export async function runExchangeEphemeralTest(t: GlobalTestState) { - const { bankClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); let w1 = await createWalletDaemonWithClient(t, { name: "w1", @@ -93,9 +93,9 @@ export async function runExchangeEphemeralTest(t: GlobalTestState) { }); await t.runSpanAsync("used entry kept on cold start", async () => { - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient: w1.walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-keys-cherrypick.ts b/packages/taler-harness/src/integrationtests/test-exchange-keys-cherrypick.ts @@ -17,18 +17,16 @@ /** * Imports. */ -import { - Duration, - TalerCorebankApiClient, - URL, - j2s, -} from "@gnu-taler/taler-util"; +import { Duration, URL, j2s } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { applyTimeTravelV2, createWalletDaemonWithClient, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectedExchangeService } from "../harness/faultInjection.js"; import { @@ -93,18 +91,15 @@ export async function runExchangeKeysCherrypickTest( const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); // The wallet talks to the exchange through a proxy, so that the test can // see the /keys requests it makes. @@ -117,23 +112,13 @@ export async function runExchangeKeysCherrypickTest( bank.setSuggestedExchange(proxiedExchange, exchangePaytoUri); - await bank.start(); - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: "Exchange", - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + "Exchange", + ); exchange.addOfferedCoins(defaultCoinConfig); @@ -164,9 +149,9 @@ export async function runExchangeKeysCherrypickTest( // Withdraw digital cash into the wallet. This adds the exchange entry and // thus downloads /keys for the first time. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: proxiedExchange, amount: "TESTKUDOS:20", }); @@ -305,9 +290,9 @@ export async function runExchangeKeysCherrypickTest( } // The wallet can still spend and withdraw from the exchange. - const wres2 = await withdrawViaBankV3(t, { + const wres2 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: proxiedExchange, amount: "TESTKUDOS:10", }); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-keys-withdraw-filter.ts b/packages/taler-harness/src/integrationtests/test-exchange-keys-withdraw-filter.ts @@ -16,11 +16,15 @@ import { ExchangeKeysResponse, - TalerCorebankApiClient, URL, codecForExchangeKeysResponse, } from "@gnu-taler/taler-util"; -import { applyTimeTravelV2 } from "../harness/environments.js"; +import { + applyTimeTravelV2, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, +} from "../harness/environments.js"; import { BankService, ExchangeService, @@ -159,34 +163,22 @@ export async function runExchangeKeysWithdrawFilterTest( const exchangeBankUsername = "exchange"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); - await bank.start(); - await bank.pingUntilAvailable(); - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - await bankClient.registerAccountExtended({ - name: "Exchange", - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + const bankClient = await startHarnessBank(bank); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + "Exchange", + ); exchange.addCoinConfigList([ { diff --git a/packages/taler-harness/src/integrationtests/test-exchange-kyc-auth.ts b/packages/taler-harness/src/integrationtests/test-exchange-kyc-auth.ts @@ -37,7 +37,7 @@ import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { getTestHarnessPaytoForLabel, @@ -127,10 +127,10 @@ export async function runExchangeKycAuthTest(t: GlobalTestState) { const merchantPair = await cryptoApi.createEddsaKeypair({}); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, exchange, - bankClient, + bank, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-management-fault.ts b/packages/taler-harness/src/integrationtests/test-exchange-management-fault.ts @@ -26,6 +26,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; +import { makeHarnessExchangeBankAccount } from "../harness/environments.js"; import { FaultInjectedExchangeService, FaultInjectionResponseContext, @@ -74,18 +75,15 @@ export async function runExchangeManagementFaultTest( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); const faultyExchange = new FaultInjectedExchangeService(t, exchange, 8091); // Base URL must contain port that the proxy is listening on. diff --git a/packages/taler-harness/src/integrationtests/test-exchange-master-pub-change.ts b/packages/taler-harness/src/integrationtests/test-exchange-master-pub-change.ts @@ -28,7 +28,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { ExchangeService, @@ -55,13 +55,13 @@ export async function runExchangeMasterPubChangeTest( // Set up test environment - const { walletClient, exchange, bankClient, exchangeBankAccount } = + const { bank, walletClient, exchange, exchangeBankAccount } = await createSimpleTestkudosEnvironmentV3(t); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, amount: "TESTKUDOS:10", - bankClient, + bank, exchange, }); diff --git a/packages/taler-harness/src/integrationtests/test-exchange-purse.ts b/packages/taler-harness/src/integrationtests/test-exchange-purse.ts @@ -42,8 +42,8 @@ import { topupReserveWithBank, withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; /** * Test the exchange's purse API. @@ -51,7 +51,7 @@ import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; export async function runExchangePurseTest(t: GlobalTestState) { // Set up test environment - const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); const http = harnessHttpLib; const cryptoDisp = new CryptoDispatcher( diff --git a/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts b/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts @@ -25,7 +25,6 @@ import { Duration, ExchangeKeysResponse, Logger, - TalerCorebankApiClient, } from "@gnu-taler/taler-util"; import { createPlatformHttpLib, @@ -33,6 +32,14 @@ import { } from "@gnu-taler/taler-util/http"; import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { + applyTimeTravelV2, + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, +} from "../harness/environments.js"; +import { BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -40,11 +47,6 @@ import { MerchantService, setupDb, } from "../harness/harness.js"; -import { - applyTimeTravelV2, - createWalletDaemonWithClient, - withdrawViaBankV3, -} from "../harness/environments.js"; const logger = new Logger("test-exchange-timetravel.ts"); @@ -129,39 +131,25 @@ export async function runExchangeTimetravelTest(t: GlobalTestState) { let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); + const bankClient = await startHarnessBank(bank); - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addCoinConfigList(makeNoFeeCoinConfig("TESTKUDOS")); @@ -197,9 +185,9 @@ export async function runExchangeTimetravelTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:15", }); diff --git a/packages/taler-harness/src/integrationtests/test-fee-regression.ts b/packages/taler-harness/src/integrationtests/test-fee-regression.ts @@ -17,17 +17,17 @@ /** * Imports. */ -import { - TalerCorebankApiClient, - TalerMerchantApi, -} from "@gnu-taler/taler-util"; +import { TalerMerchantApi } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { SimpleTestEnvironmentNg3, createBrowser, createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -79,41 +79,27 @@ export async function createMyTestkudosEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayAuth: { - type: "basic", - password: exchangeBankPassword, - username: exchangeBankUsername, - }, - accountPaytoUri: exchangePaytoUri, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + password: exchangeBankPassword, + username: exchangeBankUsername, + }, + accountPaytoUri: exchangePaytoUri, + }); await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); + const bankClient = await startHarnessBank(bank); - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); const coinCommon = { cipher: "RSA" as const, @@ -220,19 +206,14 @@ export async function createMyTestkudosEnvironment( export async function runFeeRegressionTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchantAdminAccessToken, - merchant, - } = await createMyTestkudosEnvironment(t); + const { bank, walletClient, exchange, merchantAdminAccessToken, merchant } = + await createMyTestkudosEnvironment(t); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:1.92", }); diff --git a/packages/taler-harness/src/integrationtests/test-forced-selection.ts b/packages/taler-harness/src/integrationtests/test-forced-selection.ts @@ -19,8 +19,8 @@ */ import { AmountString, j2s } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; /** * Run test for forced denom/coin selection. @@ -38,7 +38,7 @@ export async function runForcedSelectionTest(t: GlobalTestState) { // Set up test environment const { walletClient, bank, exchange, merchant, merchantAdminAccessToken } = - await createSimpleTestkudosEnvironmentV2(t); + await createSimpleTestkudosEnvironmentV3(t); await walletClient.call(WalletApiOperation.AddExchange, { uri: exchange.baseUrl, diff --git a/packages/taler-harness/src/integrationtests/test-known-accounts.ts b/packages/taler-harness/src/integrationtests/test-known-accounts.ts @@ -21,7 +21,7 @@ import { j2s, TalerErrorCode } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -31,14 +31,14 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runKnownAccountsTest(t: GlobalTestState) { // Set up test environment - const { walletClient, exchange, bankClient } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-amp-failure.ts b/packages/taler-harness/src/integrationtests/test-kyc-amp-failure.ts @@ -29,7 +29,7 @@ import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -85,13 +85,13 @@ export async function runKycAmpFailureTest(t: GlobalTestState) { // Set up test environment // FIXME: Reduced test environment without merchant suffices - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, exchange, - bankClient, + bank, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-amp-timeout.ts b/packages/taler-harness/src/integrationtests/test-kyc-amp-timeout.ts @@ -29,7 +29,7 @@ import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -77,13 +77,13 @@ export async function runKycAmpTimeoutTest(t: GlobalTestState) { // Set up test environment // FIXME: Reduced test environment without merchant suffices - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, exchange, - bankClient, + bank, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-balance-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-kyc-balance-withdrawal.ts @@ -37,7 +37,7 @@ import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecision, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -95,9 +95,9 @@ async function runBalanceWithdrawal(t: GlobalTestState, cumulative: boolean) { }, ); t.assertDeepEqual(firstPreview.kycRequired, false); - const first = await withdrawViaBankV3(t, { + const first = await withdrawViaBankV4(t, { amount: "TESTKUDOS:8", - bankClient, + bank, exchange, walletClient, }); @@ -143,9 +143,9 @@ async function runBalanceWithdrawal(t: GlobalTestState, cumulative: boolean) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount, - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts b/packages/taler-harness/src/integrationtests/test-kyc-decisions.ts @@ -42,7 +42,7 @@ import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecision, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { getTestHarnessPaytoForLabel, @@ -105,10 +105,10 @@ export async function runKycDecisionsTest(t: GlobalTestState) { const kycPaytoHash = encodeCrock(Paytos.hashNormalized(merchantPayto)); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, exchange, - bankClient, + bank, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate-implicit-auth.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate-implicit-auth.ts @@ -24,30 +24,15 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, - withdrawViaBankV3, + configureSimpleKycInfoRule, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; function adjustExchangeConfig(config: Configuration): void { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "aggregate"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "aggregate"); } export async function runKycDepositAggregateImplicitAuthTest( @@ -55,15 +40,15 @@ export async function runKycDepositAggregateImplicitAuthTest( ) { // Set up test environment - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig, }); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:50", exchange: exchange, walletClient: walletClient, diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-aggregate.ts @@ -26,50 +26,29 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, - withdrawViaBankV3, + configureSimpleKycInfoRule, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; function adjustExchangeConfig(config: Configuration): void { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "aggregate"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "aggregate"); } export async function runKycDepositAggregateTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - bank, - wireGatewayApi, - amlKeypair, - } = await createKycTestkudosEnvironmentFull(t, { - adjustExchangeConfig, - }); + const { walletClient, exchange, bank, wireGatewayApi, amlKeypair } = + await createKycTestkudosEnvironmentFull(t, { + adjustExchangeConfig, + }); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:50", exchange: exchange, walletClient: walletClient, diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-deposit.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-deposit.ts @@ -29,10 +29,10 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecisionNoRules, - withdrawViaBankV3, + configureSimpleKycInfoRule, + withdrawViaBankV4, } from "../harness/environments.js"; import { getTestHarnessPaytoForLabel, @@ -42,22 +42,7 @@ import { const logger = new Logger("test-kyc-deposit-deposit.ts"); function adjustExchangeConfig(config: Configuration) { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "deposit"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "deposit"); } export async function runKycDepositDepositTest(t: GlobalTestState) { @@ -74,8 +59,8 @@ export async function runKycDepositDepositTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:50", exchange: exchange, walletClient: walletClient, diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-kycauth.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-kycauth.ts @@ -11,11 +11,11 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, createWalletDaemonWithClient, postAmlDecisionNoRules, - withdrawViaBankV3, + configureSimpleKycInfoRule, + withdrawViaBankV4, } from "../harness/environments.js"; import { getTestHarnessPaytoForLabel, @@ -23,22 +23,7 @@ import { } from "../harness/harness.js"; function adjustExchangeConfig(config: Configuration) { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "deposit"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "deposit"); } export async function runKycDepositKycauthTest(t: GlobalTestState) { @@ -47,7 +32,6 @@ export async function runKycDepositKycauthTest(t: GlobalTestState) { // wallet that will send p2p transfer const { walletClient: w0, - bankClient, exchange, bank, exchangeBankAccount, @@ -59,8 +43,8 @@ export async function runKycDepositKycauthTest(t: GlobalTestState) { name: "w0", }); - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:50", exchange: exchange, walletClient: w0, diff --git a/packages/taler-harness/src/integrationtests/test-kyc-form-bad-measure.ts b/packages/taler-harness/src/integrationtests/test-kyc-form-bad-measure.ts @@ -30,7 +30,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { configureCommonKyc, createKycTestkudosEnvironmentFull, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -89,14 +89,14 @@ export async function runKycFormBadMeasureTest(t: GlobalTestState) { }); // Set up test environment - const { walletClient, bankClient, exchange } = + const { bank, walletClient, exchange } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig }); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:20", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-aggregate.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-aggregate.ts @@ -26,30 +26,15 @@ import { succeedOrThrow, } from "@gnu-taler/taler-util"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, makeTestPaymentV2, - withdrawViaBankV3, + configureSimpleKycInfoRule, + withdrawViaBankV4, } from "../harness/environments.js"; import { doMerchantKycAuth, GlobalTestState } from "../harness/harness.js"; function adjustExchangeConfig(config: Configuration) { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "aggregate"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "aggregate"); } export async function runKycMerchantAggregateTest(t: GlobalTestState) { @@ -68,8 +53,8 @@ export async function runKycMerchantAggregateTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:50", exchange: exchange, walletClient: walletClient, diff --git a/packages/taler-harness/src/integrationtests/test-kyc-merchant-wallet-reuse.ts b/packages/taler-harness/src/integrationtests/test-kyc-merchant-wallet-reuse.ts @@ -24,7 +24,7 @@ import { TalerMerchantInstanceHttpClient, TalerProtocolDuration, } from "@gnu-taler/taler-util"; -import { withdrawViaBankV3 } from "../harness/environments.js"; +import { withdrawViaBankV4 } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; import { createTopsEnvironment } from "../harness/tops.js"; @@ -35,8 +35,8 @@ export async function runKycMerchantWalletReuseTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, exchange, exchangeApi, merchant, @@ -51,9 +51,9 @@ export async function runKycMerchantWalletReuseTest(t: GlobalTestState) { t.logStep("starting withdrawal"); // Withdrawal below threshold succeeds! - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "CHF:20", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-kyc-peer-pull.ts b/packages/taler-harness/src/integrationtests/test-kyc-peer-pull.ts @@ -29,36 +29,21 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, createWalletDaemonWithClient, postAmlDecisionNoRules, - withdrawViaBankV3, + configureSimpleKycInfoRule, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; export async function runKycPeerPullTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig(config) { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "merge"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "merge"); }, }); @@ -70,8 +55,8 @@ export async function runKycPeerPullTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres1 = await withdrawViaBankV3(t, { - bankClient, + const wres1 = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:20", exchange: exchange, walletClient: w0.walletClient, @@ -79,8 +64,8 @@ export async function runKycPeerPullTest(t: GlobalTestState) { await wres1.withdrawalFinishedCond; - const wres2 = await withdrawViaBankV3(t, { - bankClient, + const wres2 = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:1", exchange: exchange, walletClient: walletClient, diff --git a/packages/taler-harness/src/integrationtests/test-kyc-peer-push.ts b/packages/taler-harness/src/integrationtests/test-kyc-peer-push.ts @@ -18,46 +18,28 @@ * Imports. */ import { - AbsoluteTime, - AmountString, - Duration, j2s, TransactionMajorState, TransactionMinorState, - TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - configureCommonKyc, createKycTestkudosEnvironmentFull, createWalletDaemonWithClient, postAmlDecisionNoRules, - withdrawViaBankV3, + configureSimpleKycInfoRule, + doPeerPushDebit, + withdrawViaBankV4, } from "../harness/environments.js"; -import { GlobalTestState, WalletClient } from "../harness/harness.js"; +import { GlobalTestState } from "../harness/harness.js"; export async function runKycPeerPushTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange, amlKeypair } = + const { bank, walletClient, exchange, amlKeypair } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig(config) { - configureCommonKyc(config); - - config.setString("KYC-RULE-R1", "operation_type", "merge"); - config.setString("KYC-RULE-R1", "enabled", "yes"); - config.setString("KYC-RULE-R1", "exposed", "yes"); - config.setString("KYC-RULE-R1", "is_and_combinator", "yes"); - config.setString("KYC-RULE-R1", "threshold", "TESTKUDOS:5"); - config.setString("KYC-RULE-R1", "timeframe", "1d"); - config.setString("KYC-RULE-R1", "next_measures", "M1"); - - config.setString("KYC-MEASURE-M1", "check_name", "C1"); - config.setString("KYC-MEASURE-M1", "context", "{}"); - - config.setString("KYC-CHECK-C1", "type", "INFO"); - config.setString("KYC-CHECK-C1", "description", "my check!"); - config.setString("KYC-CHECK-C1", "fallback", "FREEZE"); + configureSimpleKycInfoRule(config, "merge"); }, }); @@ -68,8 +50,8 @@ export async function runKycPeerPushTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "TESTKUDOS:20", exchange: exchange, walletClient: w0.walletClient, @@ -136,57 +118,5 @@ export async function runKycPeerPushTest(t: GlobalTestState) { * Initiate a push debit transaction, wait until the transaction * is ready. */ -async function doPeerPushDebit( - t: GlobalTestState, - args: { - walletClient: WalletClient; - amount: AmountString; - summary?: string; - }, -): Promise<{ - transactionId: string; - talerUri: string; -}> { - const purse_expiration = AbsoluteTime.toProtocolTimestamp( - AbsoluteTime.addDuration( - AbsoluteTime.now(), - Duration.fromSpec({ days: 2 }), - ), - ); - const initRet = await args.walletClient.call( - WalletApiOperation.InitiatePeerPushDebit, - { - partialContractTerms: { - amount: args.amount, - summary: args.summary ?? "Test P2P Payment", - purse_expiration, - }, - }, - ); - - await args.walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: initRet.transactionId, - txState: { - major: TransactionMajorState.Pending, - minor: TransactionMinorState.Ready, - }, - }); - - const txDet = await args.walletClient.call( - WalletApiOperation.GetTransactionById, - { - transactionId: initRet.transactionId, - }, - ); - - t.assertTrue(txDet.type === TransactionType.PeerPushDebit); - const talerUri = txDet.talerUri; - t.assertTrue(!!talerUri); - - return { - transactionId: initRet.transactionId, - talerUri, - }; -} runKycPeerPushTest.suites = ["wallet"]; diff --git a/packages/taler-harness/src/integrationtests/test-kyc-wallet-deposit-abort.ts b/packages/taler-harness/src/integrationtests/test-kyc-wallet-deposit-abort.ts @@ -27,7 +27,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { configureCommonKyc, createKycTestkudosEnvironmentFull, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -94,14 +94,14 @@ export async function runKycWalletDepositAbortTest(t: GlobalTestState) { }); // Set up test environment - const { bankClient, exchange, walletClient } = + const { bank, exchange, walletClient } = await createKycTestkudosEnvironmentFull(t, { adjustExchangeConfig, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-bank.ts b/packages/taler-harness/src/integrationtests/test-libeufin-bank.ts @@ -32,7 +32,10 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, +} from "../harness/environments.js"; import { ExchangeService, GlobalTestState, @@ -83,15 +86,15 @@ export async function runLibeufinBankTest(t: GlobalTestState) { logger.info("creating bank account for the exchange"); - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPw, - }, - accountPaytoUri: exchangePayto, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPw, + }, + accountPaytoUri: exchangePayto, + }); bank.setSuggestedExchange(exchange); diff --git a/packages/taler-harness/src/integrationtests/test-libeufin-conversion.ts b/packages/taler-harness/src/integrationtests/test-libeufin-conversion.ts @@ -28,7 +28,10 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, +} from "../harness/environments.js"; import { ExchangeService, GlobalTestState, @@ -81,23 +84,19 @@ export async function runLibeufinConversionTest(t: GlobalTestState) { const exchangeBankUsername = "exchange"; const exchangeBankPw = "mypw-password"; const exchangePayto = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href; logger.info("creating bank account for the exchange"); - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPw, - }, - accountPaytoUri: exchangePayto, - conversionUrl: new URL("conversion-info/", bank.baseUrl).href, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPw, + }, + accountPaytoUri: exchangePayto, + conversionUrl: new URL("conversion-info/", bank.baseUrl).href, + }); bank.setSuggestedExchange(exchange); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-acctsel.ts b/packages/taler-harness/src/integrationtests/test-merchant-acctsel.ts @@ -29,7 +29,10 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, +} from "../harness/environments.js"; import { BankService, ExchangeService, @@ -91,18 +94,15 @@ export async function runMerchantAcctselTest(t: GlobalTestState) { const paytoIban = "payto://iban/DE76500202009817493529?receiver-name=exchange" as PaytoString; - await exchange1.addBankAccount("1", { + const exchange1BankAccount = makeHarnessExchangeBankAccount(bank, { accountPaytoUri: paytoXtb, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { + auth: { type: "basic", password: "test", username: "exchange", }, }); + await exchange1.addBankAccount("1", exchange1BankAccount); const exchange2 = ExchangeService.create(t, { name: "testexchange-2", @@ -111,18 +111,15 @@ export async function runMerchantAcctselTest(t: GlobalTestState) { database: exchange2Db.connStr, }); - await exchange2.addBankAccount("1", { + const exchange2BankAccount = makeHarnessExchangeBankAccount(bank, { accountPaytoUri: paytoIban, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange-iban/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { + auth: { type: "basic", password: "test", username: "exchange-iban", }, }); + await exchange2.addBankAccount("1", exchange2BankAccount); for (const [username, paytoUri] of [ ["exchange", paytoXtb], diff --git a/packages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts b/packages/taler-harness/src/integrationtests/test-merchant-deposit-large.ts @@ -29,33 +29,13 @@ import { UserAndToken, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig } from "../harness/denomStructures.js"; +import { makeLargeCoinTestConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, waitMs } from "../harness/harness.js"; -const coinCommon = { - cipher: "RSA" as const, - durationLegal: "3 years", - durationSpend: "2 years", - durationWithdraw: "7 days", - feeDeposit: "TESTKUDOS:0", - feeRefresh: "TESTKUDOS:0", - feeRefund: "TESTKUDOS:0", - feeWithdraw: "TESTKUDOS:0", - rsaKeySize: 1024, -}; - -const coinConfigList: CoinConfig[] = [ - { - ...coinCommon, - name: "n1", - value: "TESTKUDOS:1", - }, -]; - /** * Test deposit with a large number of coins. * @@ -67,26 +47,20 @@ const coinConfigList: CoinConfig[] = [ */ export async function runMerchantDepositLargeTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - bank, - merchantAdminAccessToken, - merchant, - } = await createSimpleTestkudosEnvironmentV3(t, coinConfigList, { - forceLibeufin: true, - exchangeConfig: { - roundUnit: "TESTKUDOS:2", - tinyAmount: "TESTKUDOS:2", - overrideWireFee: "TESTKUDOS:0", - }, - }); + const { walletClient, exchange, bank, merchantAdminAccessToken, merchant } = + await createSimpleTestkudosEnvironmentV3(t, makeLargeCoinTestConfig(), { + forceLibeufin: true, + exchangeConfig: { + roundUnit: "TESTKUDOS:2", + tinyAmount: "TESTKUDOS:2", + overrideWireFee: "TESTKUDOS:0", + }, + }); // Withdraw digital cash into the wallet. - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:200", }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-confusion.ts @@ -22,7 +22,6 @@ import { ConfirmPayResultType, j2s, succeedOrThrow, - TalerCorebankApiClient, TalerErrorCode, TalerMerchantInstanceHttpClient, TransactionMajorState, @@ -34,8 +33,10 @@ import { URL } from "node:url"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, - FaultyMerchantTestEnvironmentNg, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectedExchangeService, @@ -57,7 +58,7 @@ import { */ export async function createConfusedMerchantTestkudosEnvironment( t: GlobalTestState, -): Promise<FaultyMerchantTestEnvironmentNg> { +) { const db = await setupDb(t); const bank = await BankService.create(t, { @@ -93,39 +94,25 @@ export async function createConfusedMerchantTestkudosEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addOfferedCoins(defaultCoinConfig); @@ -161,12 +148,12 @@ export async function createConfusedMerchantTestkudosEnvironment( }); return { + bank, commonDb: db, exchange, merchant, merchantAdminAccessToken: adminAccessToken, walletClient, - bankClient, faultyMerchant, faultyExchange, }; @@ -201,8 +188,8 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient, - bankClient, faultyExchange, faultyMerchant, merchantAdminAccessToken, @@ -210,9 +197,9 @@ export async function runMerchantExchangeConfusionTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-exchange-duplicate.ts b/packages/taler-harness/src/integrationtests/test-merchant-exchange-duplicate.ts @@ -30,7 +30,10 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, +} from "../harness/environments.js"; import { BankService, ExchangeService, @@ -86,31 +89,25 @@ export async function runMerchantExchangeDuplicateTest(t: GlobalTestState) { const paytoXtb2 = "payto://x-taler-bank/localhost/exchange-two?receiver-name=exchange-two" as PaytoString; - await exchange1.addBankAccount("1", { + const exchange1BankAccount = makeHarnessExchangeBankAccount(bank, { accountPaytoUri: paytoXtb1, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { + auth: { type: "basic", password: "test", username: "exchange", }, }); + await exchange1.addBankAccount("1", exchange1BankAccount); - await exchange1.addBankAccount("2", { + const exchange1SecondBankAccount = makeHarnessExchangeBankAccount(bank, { accountPaytoUri: paytoXtb2, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange-two/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { + auth: { type: "basic", password: "test", username: "exchange-two", }, }); + await exchange1.addBankAccount("2", exchange1SecondBankAccount); for (const [username, paytoUri] of [ ["exchange", paytoXtb1], diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts b/packages/taler-harness/src/integrationtests/test-merchant-instance-casing.ts @@ -33,7 +33,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { getTestHarnessPaytoForLabel, @@ -99,6 +99,7 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { "the test changes only the case of the instance segment in one payment URI and verifies that the wallet follows the canonical signed contract URL", }); const { + bank, bankClient, walletClient, exchange, @@ -263,11 +264,11 @@ export async function runMerchantInstanceCasingTest(t: GlobalTestState) { // Fund the wallet before the payment part. t.assertTrue(bankClient !== undefined); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, exchange, amount: "TESTKUDOS:20", - bankClient, + bank, }); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts b/packages/taler-harness/src/integrationtests/test-merchant-longpolling.ts @@ -31,7 +31,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -41,19 +41,14 @@ import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; */ export async function runMerchantLongpollingTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts b/packages/taler-harness/src/integrationtests/test-merchant-refund-api.ts @@ -20,7 +20,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -145,16 +145,11 @@ export async function runMerchantRefundApiTest(t: GlobalTestState) { justification: "the refund API test deliberately requests order status with two wrong contract hashes and verifies both forbidden responses", }); - const { + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); - const wres = await withdrawViaBankV3(t, { - walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-reports.ts b/packages/taler-harness/src/integrationtests/test-merchant-reports.ts @@ -29,7 +29,7 @@ import { applyTimeTravelV2, makeTestPaymentV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, sh } from "../harness/harness.js"; @@ -45,17 +45,12 @@ export async function runMerchantReportsTest(t: GlobalTestState) { console.log(`XDG_DATA_HOME: ${process.env["XDG_DATA_HOME"]}`); - const { - walletClient, - exchange, - merchant, - merchantAdminAccessToken, - bankClient, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:30", }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-sessions.ts b/packages/taler-harness/src/integrationtests/test-merchant-sessions.ts @@ -23,7 +23,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -44,17 +44,12 @@ export async function runMerchantSessionsTest(t: GlobalTestState) { justification: "the session test intentionally submits an invalid fulfillment signature and checks that it is rejected", }); - const { - bankClient, - walletClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); - const withdrawal = await withdrawViaBankV3(t, { + const withdrawal = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:10", }); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts @@ -13,7 +13,6 @@ import { encodeCrock, getRandomBytes, succeedOrThrow, - TalerCorebankApiClient, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -24,20 +23,21 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { ExchangeService, GlobalTestState, harnessHttpLib, MerchantService, + BankService, } from "../harness/harness.js"; interface Context { merchant: MerchantService; merchantBaseUrl: string; merchantAccessToken: AccessToken; - bankClient: TalerCorebankApiClient; + bank: BankService; exchange: ExchangeService; } @@ -62,9 +62,9 @@ async function testPublicOrderScenario( const { walletClient } = await createWalletDaemonWithClient(t, { name: `public-order-${suffix}`, }); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient: c.bankClient, + bank: c.bank, exchange: c.exchange, amount: "TESTKUDOS:20", }); @@ -203,7 +203,7 @@ export async function runMerchantSpecPublicOrdersTest(t: GlobalTestState) { justification: "the public-order matrix deliberately supplies mismatching contract hashes and claim tokens for each supported order mode", }); - const { bankClient, exchange, merchant, merchantAdminAccessToken } = + const { bank, exchange, merchant, merchantAdminAccessToken } = await createSimpleTestkudosEnvironmentV3(t); const merchantBaseUrl = merchant.makeInstanceBaseUrl(); @@ -229,7 +229,7 @@ export async function runMerchantSpecPublicOrdersTest(t: GlobalTestState) { merchant, merchantBaseUrl, exchange, - bankClient, + bank, merchantAccessToken: merchantAdminAccessToken, }; await testPublicOrderScenario(t, context, true); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-wire.ts b/packages/taler-harness/src/integrationtests/test-merchant-wire.ts @@ -33,7 +33,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, waitMs } from "../harness/harness.js"; @@ -43,13 +43,8 @@ import { GlobalTestState, waitMs } from "../harness/harness.js"; export async function runMerchantWireTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); await t.runSpanAsync("unsupported-wire-account", async () => { const { accessToken } = await merchant.addInstanceWithWireAccount( @@ -98,9 +93,9 @@ export async function runMerchantWireTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-multiexchange.ts b/packages/taler-harness/src/integrationtests/test-multiexchange.ts @@ -23,7 +23,6 @@ import { openPromise, RefreshReason, succeedOrThrow, - TalerCorebankApiClient, TalerErrorCode, TalerErrorDetail, TalerMerchantApi, @@ -37,7 +36,10 @@ import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectedExchangeService, @@ -150,64 +152,37 @@ export async function runMultiExchangeTest(t: GlobalTestState) { config.setString("exchange", "base_url", faultyExchangeTwo.baseUrl); }); - let exchangeOneBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { - type: "basic", - username: "myexchange", - password: "password", - }, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), - }; + let exchangeOneBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: "myexchange", + password: "password", + }, + accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), + }); - let exchangeTwoBankAccount: HarnessExchangeBankAccount = { - wireGatewayAuth: { - type: "basic", - username: "myexchange2", - password: "password", - }, - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange2/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), - }; + let exchangeTwoBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: "myexchange2", + password: "password", + }, + accountPaytoUri: getTestHarnessPaytoForLabel("myexchange2"), + }); bank.setSuggestedExchange( faultyExchangeOne, exchangeOneBankAccount.accountPaytoUri, ); - await bank.start(); - - await bank.pingUntilAvailable(); + const bankClient = await startHarnessBank(bank); - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: exchangeOneBankAccount.wireGatewayAuth.username, - username: exchangeOneBankAccount.wireGatewayAuth.username, - password: exchangeOneBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeOneBankAccount.accountPaytoUri, - }); + await registerHarnessExchangeBankAccount(bankClient, exchangeOneBankAccount); await exchangeOne.addBankAccount("1", exchangeOneBankAccount); - await bankClient.registerAccountExtended({ - name: exchangeTwoBankAccount.wireGatewayAuth.username, - username: exchangeTwoBankAccount.wireGatewayAuth.username, - password: exchangeTwoBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeTwoBankAccount.accountPaytoUri, - }); + await registerHarnessExchangeBankAccount(bankClient, exchangeTwoBankAccount); await exchangeTwo.addBankAccount("1", exchangeTwoBankAccount); // Set up the first exchange @@ -260,16 +235,16 @@ export async function runMultiExchangeTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchangeOne, amount: "TESTKUDOS:6", }); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchangeTwo, amount: "TESTKUDOS:6", }); @@ -322,15 +297,15 @@ export async function runMultiExchangeTest(t: GlobalTestState) { // Fund both exchanges again. Neither balance is enough for the next // payment by itself, which forces the merchant to submit one deposit batch // to each exchange. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchangeOne, amount: "TESTKUDOS:6", }); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchangeTwo, amount: "TESTKUDOS:6", }); diff --git a/packages/taler-harness/src/integrationtests/test-otp.ts b/packages/taler-harness/src/integrationtests/test-otp.ts @@ -32,7 +32,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -42,13 +42,8 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runOtpTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -85,9 +80,9 @@ export async function runOtpTest(t: GlobalTestState) { console.log(`template: ${j2s(getTemplateResp)}`); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-paivana-repurchase.ts b/packages/taler-harness/src/integrationtests/test-paivana-repurchase.ts @@ -30,7 +30,7 @@ import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, waitMs } from "../harness/harness.js"; @@ -48,7 +48,7 @@ export async function runPaivanaRepurchaseTest(t: GlobalTestState) { const { walletClient, - bankClient, + bank, exchange, paivana, merchant, @@ -57,9 +57,9 @@ export async function runPaivanaRepurchaseTest(t: GlobalTestState) { paivanaWebsite: ".*.html", // block all html pages }); - const withdrawalRes = await withdrawViaBankV3(t, { + const withdrawalRes = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-pay-paid.ts b/packages/taler-harness/src/integrationtests/test-pay-paid.ts @@ -18,8 +18,8 @@ * Imports. */ import { + Duration, ConfirmPayResultType, - TalerCorebankApiClient, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -30,8 +30,8 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - createFaultInjectedMerchantTestkudosEnvironment, - withdrawViaBankV3, + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectionRequestContext } from "../harness/faultInjection.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -53,15 +53,20 @@ export async function runPayPaidTest(t: GlobalTestState) { faultyExchange, faultyMerchant, merchantAdminAccessToken, - } = await createFaultInjectedMerchantTestkudosEnvironment(t); + } = await createSimpleTestkudosEnvironmentV3(t, undefined, { + faultInjection: true, + walletName: "default", + walletPersistent: false, + merchantDefaultWireTransferDelay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ days: 1 }), + ), + }); // Withdraw digital cash into the wallet. - const bankClient = new TalerCorebankApiClient(bank.baseUrl); - - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-abort.ts b/packages/taler-harness/src/integrationtests/test-payment-abort.ts @@ -18,9 +18,9 @@ * Imports. */ import { + Duration, ConfirmPayResultType, Amounts, - TalerCorebankApiClient, TalerErrorCode, TalerErrorDetail, TalerMerchantInstanceHttpClient, @@ -33,8 +33,8 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - createFaultInjectedMerchantTestkudosEnvironment, - withdrawViaBankV3, + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectionRequestContext } from "../harness/faultInjection.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -48,15 +48,20 @@ export async function runPaymentAbortTest(t: GlobalTestState) { faultyMerchant, faultyExchange, merchantAdminAccessToken, - } = await createFaultInjectedMerchantTestkudosEnvironment(t); + } = await createSimpleTestkudosEnvironmentV3(t, undefined, { + faultInjection: true, + walletName: "default", + walletPersistent: false, + merchantDefaultWireTransferDelay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ days: 1 }), + ), + }); // Withdraw digital cash into the wallet. - const bankClient = new TalerCorebankApiClient(bank.baseUrl); - - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-claim.ts b/packages/taler-harness/src/integrationtests/test-payment-claim.ts @@ -31,7 +31,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; @@ -41,13 +41,8 @@ import { GlobalTestState, WalletClient } from "../harness/harness.js"; export async function runPaymentClaimTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -83,9 +78,9 @@ export async function runPaymentClaimTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-deleted.ts b/packages/taler-harness/src/integrationtests/test-payment-deleted.ts @@ -21,14 +21,14 @@ import { ConfirmPayResultType, TalerMerchantInstanceHttpClient, TransactionMajorState, - TransactionMinorState, j2s, succeedOrThrow, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -47,21 +47,16 @@ export async function runPaymentDeletedTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // First, make a "free" payment when we don't even have // any money in the // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -92,21 +87,11 @@ export async function runPaymentDeletedTest(t: GlobalTestState) { // Make wallet pay for the order - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - succeedOrThrow( await merchantClient.deleteOrder( merchantAdminAccessToken, diff --git a/packages/taler-harness/src/integrationtests/test-payment-expired.ts b/packages/taler-harness/src/integrationtests/test-payment-expired.ts @@ -23,7 +23,6 @@ import { TalerMerchantApi, TalerMerchantInstanceHttpClient, TransactionMajorState, - TransactionMinorState, j2s, succeedOrThrow, } from "@gnu-taler/taler-util"; @@ -31,7 +30,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + prepareTestPayment, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -59,19 +59,14 @@ export async function runPaymentExpiredTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -111,21 +106,11 @@ export async function runPaymentExpiredTest(t: GlobalTestState) { t.assertTrue(orderStatus.order_status === "unpaid"); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - // Do *not* time-travel the wallet await applyTimeTravelV2( Duration.toMilliseconds(Duration.fromSpec({ hours: 1 })), @@ -189,21 +174,11 @@ export async function runPaymentExpiredTest(t: GlobalTestState) { t.assertTrue(orderStatus.order_status === "unpaid"); - const preparePayResult = await walletClient.call( - WalletApiOperation.PreparePayForUriV2, - { - talerPayUri: orderStatus.taler_pay_uri, - }, + const preparePayResult = await prepareTestPayment( + walletClient, + orderStatus.taler_pay_uri, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: preparePayResult.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, - }, - }); - await applyTimeTravelV2( Duration.toMilliseconds(Duration.fromSpec({ hours: 1 })), { exchange, merchant, walletClient }, diff --git a/packages/taler-harness/src/integrationtests/test-payment-forgettable.ts b/packages/taler-harness/src/integrationtests/test-payment-forgettable.ts @@ -17,14 +17,14 @@ /** * Imports. */ +import { TalerMerchantApi } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; -import { TalerMerchantApi } from "@gnu-taler/taler-util"; +import { GlobalTestState } from "../harness/harness.js"; /** * Run test for payment with a contract that has forgettable fields. @@ -32,19 +32,14 @@ import { TalerMerchantApi } from "@gnu-taler/taler-util"; export async function runPaymentForgettableTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-multiple.ts b/packages/taler-harness/src/integrationtests/test-payment-multiple.ts @@ -20,7 +20,6 @@ import { AccessToken, succeedOrThrow, - TalerCorebankApiClient, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -29,7 +28,10 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { coin_ct10, coin_u1 } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -44,7 +46,7 @@ async function setupTest(t: GlobalTestState): Promise<{ merchant: MerchantService; merchantAdminAccessToken: AccessToken; exchange: ExchangeService; - bankClient: TalerCorebankApiClient; + bank: BankService; }> { const db = await setupDb(t); @@ -69,39 +71,25 @@ async function setupTest(t: GlobalTestState): Promise<{ let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); await exchange.start(); await exchange.pingUntilAvailable(); @@ -136,8 +124,8 @@ async function setupTest(t: GlobalTestState): Promise<{ console.log("setup done!"); return { + bank, merchant, - bankClient, merchantAdminAccessToken: adminAccessToken, exchange, }; @@ -151,7 +139,7 @@ async function setupTest(t: GlobalTestState): Promise<{ export async function runPaymentMultipleTest(t: GlobalTestState) { // Set up test environment - const { merchant, bankClient, exchange, merchantAdminAccessToken } = + const { bank, merchant, exchange, merchantAdminAccessToken } = await setupTest(t); const { walletClient } = await createWalletDaemonWithClient(t, { @@ -164,9 +152,9 @@ export async function runPaymentMultipleTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:100", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-order-gone.ts b/packages/taler-harness/src/integrationtests/test-payment-order-gone.ts @@ -28,7 +28,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -39,30 +39,25 @@ import { GlobalTestState } from "../harness/harness.js"; * that grows with the number of wallets, and that no merchant can shed. */ export async function runPaymentOrderGoneTest(t: GlobalTestState) { - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t, undefined, { - // The merchant keeps a paid order around for its legal preservation - // period and refuses to delete it before that. Cut the period short, so - // that the test can produce the order the merchant no longer has. - additionalMerchantConfig(m) { - m.modifyConfig(async (cfg) => { - cfg.setString("merchant", "LEGAL_PRESERVATION", "0 s"); - }); - }, - }); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t, undefined, { + // The merchant keeps a paid order around for its legal preservation + // period and refuses to delete it before that. Cut the period short, so + // that the test can produce the order the merchant no longer has. + additionalMerchantConfig(m) { + m.modifyConfig(async (cfg) => { + cfg.setString("merchant", "LEGAL_PRESERVATION", "0 s"); + }); + }, + }); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-template.ts b/packages/taler-harness/src/integrationtests/test-payment-template.ts @@ -33,7 +33,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -43,13 +43,8 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runPaymentTemplateTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -79,9 +74,9 @@ export async function runPaymentTemplateTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-transient.ts b/packages/taler-harness/src/integrationtests/test-payment-transient.ts @@ -18,8 +18,8 @@ * Imports. */ import { + Duration, ConfirmPayResultType, - TalerCorebankApiClient, TalerErrorCode, TalerErrorDetail, TalerMerchantInstanceHttpClient, @@ -31,8 +31,8 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { - createFaultInjectedMerchantTestkudosEnvironment, - withdrawViaBankV3, + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { FaultInjectionResponseContext } from "../harness/faultInjection.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -50,7 +50,14 @@ export async function runPaymentTransientTest(t: GlobalTestState) { faultyMerchant, faultyExchange, merchantAdminAccessToken, - } = await createFaultInjectedMerchantTestkudosEnvironment(t); + } = await createSimpleTestkudosEnvironmentV3(t, undefined, { + faultInjection: true, + walletName: "default", + walletPersistent: false, + merchantDefaultWireTransferDelay: Duration.toTalerProtocolDuration( + Duration.fromSpec({ days: 1 }), + ), + }); const merchantClient = new TalerMerchantInstanceHttpClient( faultyMerchant.makeInstanceBaseUrl(), @@ -58,11 +65,9 @@ export async function runPaymentTransientTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const bankClient = new TalerCorebankApiClient(bank.baseUrl); - - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: faultyExchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment-unclaim.ts b/packages/taler-harness/src/integrationtests/test-payment-unclaim.ts @@ -21,7 +21,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -37,8 +37,8 @@ export async function runPaymentUnclaimTest(t: GlobalTestState) { }); const { + bank, walletClient: firstWallet, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -46,9 +46,9 @@ export async function runPaymentUnclaimTest(t: GlobalTestState) { const { walletClient: secondWallet } = await createWalletDaemonWithClient(t, { name: "wallet2", }); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient: secondWallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:10", }); diff --git a/packages/taler-harness/src/integrationtests/test-payment.ts b/packages/taler-harness/src/integrationtests/test-payment.ts @@ -30,7 +30,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -41,6 +41,7 @@ export async function runPaymentTest(t: GlobalTestState) { // Set up test environment const { + bank, bankClient, walletClient, exchange, @@ -84,11 +85,11 @@ export async function runPaymentTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. t.assertTrue(bankClient !== undefined); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, exchange, amount: "TESTKUDOS:20", - bankClient, + bank, }); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); diff --git a/packages/taler-harness/src/integrationtests/test-paywall-flow.ts b/packages/taler-harness/src/integrationtests/test-paywall-flow.ts @@ -31,7 +31,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; @@ -41,13 +41,8 @@ import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; export async function runPaywallFlowTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -55,9 +50,9 @@ export async function runPaywallFlowTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-abort-balance.ts b/packages/taler-harness/src/integrationtests/test-peer-abort-balance.ts @@ -34,7 +34,7 @@ import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; @@ -66,7 +66,7 @@ interface ExpectedBalance { */ export async function runPeerAbortBalanceTest(t: GlobalTestState) { const [ - { walletClient: wallet1, bankClient, exchange }, + { bank, walletClient: wallet1, bankClient, exchange }, { walletClient: wallet2 }, ] = await Promise.all([ createSimpleTestkudosEnvironmentV3(t, makeNoFeeCoinConfig("TESTKUDOS")), @@ -169,9 +169,9 @@ export async function runPeerAbortBalanceTest(t: GlobalTestState) { await Promise.all( [wallet1, wallet2].map(async (walletClient) => { - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: initialAmount, }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-abort-before-create.ts b/packages/taler-harness/src/integrationtests/test-peer-abort-before-create.ts @@ -10,26 +10,26 @@ import { TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; -import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; /** An undelivered purse deposit leaves coins unknown to the exchange. */ export async function runPeerAbortBeforeCreateTest(t: GlobalTestState) { const { + bank, walletClient: wallet, - bankClient, exchange, } = await createSimpleTestkudosEnvironmentV3( t, makeNoFeeCoinConfig("TESTKUDOS"), ); - const withdrawal = await withdrawViaBankV3(t, { + const withdrawal = await withdrawViaBankV4(t, { walletClient: wallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-pull-debit-purse-gone.ts b/packages/taler-harness/src/integrationtests/test-peer-pull-debit-purse-gone.ts @@ -32,7 +32,7 @@ import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -57,7 +57,7 @@ const paymentAmount = "TESTKUDOS:5" as AmountString; */ export async function runPeerPullDebitPurseGoneTest(t: GlobalTestState) { const [ - { walletClient: wallet1, bankClient, exchange }, + { bank, walletClient: wallet1, bankClient, exchange }, { walletClient: wallet2 }, ] = await Promise.all([ createSimpleTestkudosEnvironmentV3(t, makeNoFeeCoinConfig("TESTKUDOS")), @@ -66,9 +66,9 @@ export async function runPeerPullDebitPurseGoneTest(t: GlobalTestState) { }), ]); - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient: wallet2, - bankClient, + bank, exchange, amount: initialAmount, }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-pull-large.ts b/packages/taler-harness/src/integrationtests/test-peer-pull-large.ts @@ -22,34 +22,14 @@ import { TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig } from "../harness/denomStructures.js"; +import { makeLargeCoinTestConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; -const coinCommon = { - cipher: "RSA" as const, - durationLegal: "3 years", - durationSpend: "2 years", - durationWithdraw: "7 days", - feeDeposit: "TESTKUDOS:0", - feeRefresh: "TESTKUDOS:0", - feeRefund: "TESTKUDOS:0", - feeWithdraw: "TESTKUDOS:0", - rsaKeySize: 1024, -}; - -const coinConfigList: CoinConfig[] = [ - { - ...coinCommon, - name: "n1", - value: "TESTKUDOS:1", - }, -]; - const purse_expiration = AbsoluteTime.toProtocolTimestamp( AbsoluteTime.addDuration(AbsoluteTime.now(), Duration.fromSpec({ days: 2 })), ); @@ -63,19 +43,19 @@ const purse_expiration = AbsoluteTime.toProtocolTimestamp( export async function runPeerPullLargeTest(t: GlobalTestState) { // Set up test environment const [ - { walletClient: wallet1, bankClient, exchange }, + { bank, walletClient: wallet1, bankClient, exchange }, { walletClient: wallet2 }, ] = await Promise.all([ - createSimpleTestkudosEnvironmentV3(t, coinConfigList), + createSimpleTestkudosEnvironmentV3(t, makeLargeCoinTestConfig()), createWalletDaemonWithClient(t, { name: "w2", }), ]); // Withdraw digital cash into the wallet. - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient: wallet2, - bankClient, + bank, exchange, amount: "TESTKUDOS:500", }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-pull.ts b/packages/taler-harness/src/integrationtests/test-peer-pull.ts @@ -29,7 +29,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; @@ -67,7 +67,7 @@ export async function runPeerPullTest(t: GlobalTestState) { }); const [ - { walletClient: wallet1, bankClient, exchange }, + { bank, walletClient: wallet1, bankClient, exchange }, { walletClient: wallet2 }, { walletClient: wallet3 }, { walletClient: wallet4 }, @@ -87,9 +87,9 @@ export async function runPeerPullTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. await Promise.all( [wallet1, wallet2, wallet3, wallet4].map(async (w) => { - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient: w, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-push-large.ts b/packages/taler-harness/src/integrationtests/test-peer-push-large.ts @@ -22,34 +22,14 @@ import { TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig } from "../harness/denomStructures.js"; +import { makeLargeCoinTestConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; -const coinCommon = { - cipher: "RSA" as const, - durationLegal: "3 years", - durationSpend: "2 years", - durationWithdraw: "7 days", - feeDeposit: "TESTKUDOS:0", - feeRefresh: "TESTKUDOS:0", - feeRefund: "TESTKUDOS:0", - feeWithdraw: "TESTKUDOS:0", - rsaKeySize: 1024, -}; - -const coinConfigList: CoinConfig[] = [ - { - ...coinCommon, - name: "n1", - value: "TESTKUDOS:1", - }, -]; - const purse_expiration = AbsoluteTime.toProtocolTimestamp( AbsoluteTime.addDuration(AbsoluteTime.now(), Duration.fromSpec({ days: 2 })), ); @@ -63,10 +43,10 @@ const purse_expiration = AbsoluteTime.toProtocolTimestamp( export async function runPeerPushLargeTest(t: GlobalTestState) { // Set up test environment const [ - { walletClient: wallet1, bankClient, exchange }, + { bank, walletClient: wallet1, bankClient, exchange }, { walletClient: wallet2 }, ] = await Promise.all([ - createSimpleTestkudosEnvironmentV3(t, coinConfigList, { + createSimpleTestkudosEnvironmentV3(t, makeLargeCoinTestConfig(), { additionalBankConfig(b) {}, }), createWalletDaemonWithClient(t, { @@ -75,9 +55,9 @@ export async function runPeerPushLargeTest(t: GlobalTestState) { ]); // Withdraw digital cash into the wallet. - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient: wallet1, - bankClient, + bank, exchange, amount: "TESTKUDOS:300", }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-push.ts b/packages/taler-harness/src/integrationtests/test-peer-push.ts @@ -29,7 +29,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; @@ -56,7 +56,7 @@ const stNotExpired = [ */ export async function runPeerPushTest(t: GlobalTestState) { const [ - { walletClient: wallet1, bankClient, exchange }, + { bank, walletClient: wallet1, bankClient, exchange }, { walletClient: wallet2 }, { walletClient: wallet3 }, { walletClient: wallet4 }, @@ -74,9 +74,9 @@ export async function runPeerPushTest(t: GlobalTestState) { ]); // Withdraw digital cash into the wallet. - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient: wallet1, - bankClient, + bank, exchange, amount: "TESTKUDOS:200", }); diff --git a/packages/taler-harness/src/integrationtests/test-peer-repair.ts b/packages/taler-harness/src/integrationtests/test-peer-repair.ts @@ -29,12 +29,12 @@ import { } 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 { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; export async function runPeerRepairTest(t: GlobalTestState) { // Set up test environment @@ -65,7 +65,7 @@ export async function runPeerRepairTest(t: GlobalTestState) { "the rollback scenario deliberately reaches one zero-balance refresh conflict before newly withdrawn coins allow reselection", }); - const { bankClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); let allW1Notifications: WalletNotification[] = []; let allW2Notifications: WalletNotification[] = []; @@ -95,9 +95,9 @@ export async function runPeerRepairTest(t: GlobalTestState) { x.transactionId.startsWith("txn:withdrawal:"), ); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient: wallet1, - bankClient, + bank, exchange, amount: "TESTKUDOS:5", }); @@ -235,9 +235,9 @@ export async function runPeerRepairTest(t: GlobalTestState) { // Now withdraw so we have enough coins to re-select - const withdraw2Res = await withdrawViaBankV3(t, { + const withdraw2Res = await withdrawViaBankV4(t, { walletClient: wallet1, - bankClient, + bank, exchange, amount: "TESTKUDOS:5", }); diff --git a/packages/taler-harness/src/integrationtests/test-refund-auto.ts b/packages/taler-harness/src/integrationtests/test-refund-auto.ts @@ -27,7 +27,8 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + makeTestPaymentV2, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -37,13 +38,8 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runRefundAutoTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -51,9 +47,9 @@ export async function runRefundAutoTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -65,65 +61,25 @@ export async function runRefundAutoTest(t: GlobalTestState) { t.logStep("start-test-autorefund"); // Set up order. - const orderResp = succeedOrThrow( - await merchantClient.createOrder(merchantAdminAccessToken, { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:5", - fulfillment_url: "taler://fulfillment-success/thx", - auto_refund: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 5 }), - ), - }, - refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 10 }), + const payment = await makeTestPaymentV2(t, { + merchant, + merchantAdminAccessToken, + walletClient, + order: { + summary: "Buy me!", + amount: "TESTKUDOS:5", + fulfillment_url: "taler://fulfillment-success/thx", + auto_refund: Duration.toTalerProtocolDuration( + Duration.fromSpec({ minutes: 5 }), ), - }), - ); - - let orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "unpaid"); - - // Make wallet pay for the order - - const r1 = await walletClient.call(WalletApiOperation.PreparePayForUriV2, { - talerPayUri: orderStatus.taler_pay_uri, - }); - - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, }, + refundDelay: Duration.fromSpec({ minutes: 10 }), }); - await walletClient.call(WalletApiOperation.ConfirmPay, { - transactionId: r1.transactionId, - choiceIndex: 0, - }); - - // Check if payment was successful. - - orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "paid"); - const ref = succeedOrThrow( await merchantClient.addRefund( merchantAdminAccessToken, - orderResp.order_id, + payment.orderId, { refund: "TESTKUDOS:5", reason: "foo", @@ -159,63 +115,23 @@ export async function runRefundAutoTest(t: GlobalTestState) { { // Set up order. - const orderResp = succeedOrThrow( - await merchantClient.createOrder(merchantAdminAccessToken, { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:5", - fulfillment_url: "taler://fulfillment-success/thx", - auto_refund: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 5 }), - ), - }, - refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 10 }), + const payment = await makeTestPaymentV2(t, { + merchant, + merchantAdminAccessToken, + walletClient, + order: { + summary: "Buy me!", + amount: "TESTKUDOS:5", + fulfillment_url: "taler://fulfillment-success/thx", + auto_refund: Duration.toTalerProtocolDuration( + Duration.fromSpec({ minutes: 5 }), ), - }), - ); - - let orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "unpaid"); - - // Make wallet pay for the order - - const r1 = await walletClient.call(WalletApiOperation.PreparePayForUriV2, { - talerPayUri: orderStatus.taler_pay_uri, - }); - - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, }, + refundDelay: Duration.fromSpec({ minutes: 10 }), }); - await walletClient.call(WalletApiOperation.ConfirmPay, { - transactionId: r1.transactionId, - choiceIndex: 0, - }); - - // Check if payment was successful. - - orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "paid"); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, txState: { major: TransactionMajorState.Finalizing, minor: TransactionMinorState.AutoRefund, @@ -226,7 +142,7 @@ export async function runRefundAutoTest(t: GlobalTestState) { offsetMs: 10 * 60 * 1000, }); await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, txState: { major: TransactionMajorState.Done, }, diff --git a/packages/taler-harness/src/integrationtests/test-refund-gone.ts b/packages/taler-harness/src/integrationtests/test-refund-gone.ts @@ -23,14 +23,14 @@ import { succeedOrThrow, TalerMerchantInstanceHttpClient, TransactionMajorState, - TransactionMinorState, TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + makeTestPaymentV2, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -52,13 +52,8 @@ export async function runRefundGoneTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -66,9 +61,9 @@ export async function runRefundGoneTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -77,77 +72,31 @@ export async function runRefundGoneTest(t: GlobalTestState) { // Set up order. - const orderResp = succeedOrThrow( - await merchantClient.createOrder(merchantAdminAccessToken, { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:5", - fulfillment_url: "taler://fulfillment-success/thx", - pay_deadline: AbsoluteTime.toProtocolTimestamp( - AbsoluteTime.addDuration( - AbsoluteTime.now(), - Duration.fromSpec({ - minutes: 10, - }), - ), + const payment = await makeTestPaymentV2(t, { + merchant, + merchantAdminAccessToken, + walletClient: walletClient, + order: { + summary: "Buy me!", + amount: "TESTKUDOS:5", + fulfillment_url: "taler://fulfillment-success/thx", + pay_deadline: AbsoluteTime.toProtocolTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ + minutes: 10, + }), ), - }, - refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), ), - }), - ); - - let orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "unpaid"); - - // Make wallet pay for the order - - const r1 = await walletClient.call(WalletApiOperation.PreparePayForUriV2, { - talerPayUri: orderStatus.taler_pay_uri, - }); - - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, }, + refundDelay: Duration.fromSpec({ minutes: 1 }), }); - await walletClient.call(WalletApiOperation.ConfirmPay, { - transactionId: r1.transactionId, - choiceIndex: 0, - }); - - // Check if payment was successful. - - orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "paid"); - - console.log(orderStatus); - const ref = succeedOrThrow( - await merchantClient.addRefund( - merchantAdminAccessToken, - orderResp.order_id, - { - refund: "TESTKUDOS:5", - reason: "foo", - }, - ), + await merchantClient.addRefund(merchantAdminAccessToken, payment.orderId, { + refund: "TESTKUDOS:5", + reason: "foo", + }), ); console.log(ref); @@ -160,7 +109,7 @@ export async function runRefundGoneTest(t: GlobalTestState) { await exchange.runAggregatorOnce(); await walletClient.call(WalletApiOperation.StartRefundQuery, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, }); await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); diff --git a/packages/taler-harness/src/integrationtests/test-refund-incremental.ts b/packages/taler-harness/src/integrationtests/test-refund-incremental.ts @@ -22,14 +22,13 @@ import { Duration, succeedOrThrow, TalerMerchantInstanceHttpClient, - TransactionMajorState, - TransactionMinorState, TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + makeTestPaymentV2, + withdrawViaBankV4, } from "../harness/environments.js"; import { delayMs, GlobalTestState } from "../harness/harness.js"; @@ -39,13 +38,8 @@ import { delayMs, GlobalTestState } from "../harness/harness.js"; export async function runRefundIncrementalTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -53,9 +47,9 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -64,58 +58,18 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { // Set up order. - const orderResp = succeedOrThrow( - await merchantClient.createOrder(merchantAdminAccessToken, { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:10", - fulfillment_url: "taler://fulfillment-success/thx", - }, - refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 5 }), - ), - }), - ); - - let orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "unpaid"); - - // Make wallet pay for the order - - const r1 = await walletClient.call(WalletApiOperation.PreparePayForUriV2, { - talerPayUri: orderStatus.taler_pay_uri, - }); - - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, + const payment = await makeTestPaymentV2(t, { + merchant, + merchantAdminAccessToken, + walletClient: walletClient, + order: { + summary: "Buy me!", + amount: "TESTKUDOS:10", + fulfillment_url: "taler://fulfillment-success/thx", }, + refundDelay: Duration.fromSpec({ minutes: 5 }), }); - await walletClient.call(WalletApiOperation.ConfirmPay, { - transactionId: r1.transactionId, - choiceIndex: 0, - }); - - // Check if payment was successful. - - orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "paid"); - await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); const beforeRefunds = await walletClient.call( WalletApiOperation.GetBalances, @@ -123,21 +77,17 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { ); let ref = succeedOrThrow( - await merchantClient.addRefund( - merchantAdminAccessToken, - orderResp.order_id, - { - refund: "TESTKUDOS:2.5", - reason: "foo", - }, - ), + await merchantClient.addRefund(merchantAdminAccessToken, payment.orderId, { + refund: "TESTKUDOS:2.5", + reason: "foo", + }), ); console.log("first refund increase response", ref); { let wr = await walletClient.call(WalletApiOperation.StartRefundQuery, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, }); await walletClient.call( WalletApiOperation.TestingWaitTransactionsFinal, @@ -156,14 +106,10 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { await delayMs(1200); ref = succeedOrThrow( - await merchantClient.addRefund( - merchantAdminAccessToken, - orderResp.order_id, - { - refund: "TESTKUDOS:5", - reason: "bar", - }, - ), + await merchantClient.addRefund(merchantAdminAccessToken, payment.orderId, { + refund: "TESTKUDOS:5", + reason: "bar", + }), ); console.log("second refund increase response", ref); @@ -173,21 +119,17 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { await delayMs(1200); ref = succeedOrThrow( - await merchantClient.addRefund( - merchantAdminAccessToken, - orderResp.order_id, - { - refund: "TESTKUDOS:10", - reason: "bar", - }, - ), + await merchantClient.addRefund(merchantAdminAccessToken, payment.orderId, { + refund: "TESTKUDOS:10", + reason: "bar", + }), ); console.log("third refund increase response", ref); { let wr = await walletClient.call(WalletApiOperation.StartRefundQuery, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, }); await walletClient.call( WalletApiOperation.TestingWaitTransactionsFinal, @@ -196,10 +138,10 @@ export async function runRefundIncrementalTest(t: GlobalTestState) { console.log(wr); } - orderStatus = succeedOrThrow( + const orderStatus = succeedOrThrow( await merchantClient.getOrderDetails( merchantAdminAccessToken, - orderResp.order_id, + payment.orderId, ), ); diff --git a/packages/taler-harness/src/integrationtests/test-refund.ts b/packages/taler-harness/src/integrationtests/test-refund.ts @@ -28,14 +28,14 @@ import { TalerUriAction, TalerUris, TransactionMajorState, - TransactionMinorState, TransactionType, WalletNotification, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + makeTestPaymentV2, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -43,8 +43,8 @@ export async function runRefundTest(t: GlobalTestState) { // Set up test environment const { + bank, walletClient: wallet, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -62,9 +62,9 @@ export async function runRefundTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const withdrawalRes = await withdrawViaBankV3(t, { + const withdrawalRes = await withdrawViaBankV4(t, { walletClient: wallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -72,61 +72,21 @@ export async function runRefundTest(t: GlobalTestState) { await withdrawalRes.withdrawalFinishedCond; // Set up order. - const orderResp = succeedOrThrow( - await merchantClient.createOrder(merchantAdminAccessToken, { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:5", - fulfillment_url: "taler://fulfillment-success/thx", - }, - refund_delay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 5 }), - ), - }), - ); - - let orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "unpaid"); - - // Make wallet pay for the order - - const r1 = await wallet.client.call(WalletApiOperation.PreparePayForUriV2, { - talerPayUri: orderStatus.taler_pay_uri, - }); - - await wallet.client.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: r1.transactionId, - txState: { - major: TransactionMajorState.Dialog, - minor: TransactionMinorState.Proposed, + const payment = await makeTestPaymentV2(t, { + merchant, + merchantAdminAccessToken, + walletClient: wallet, + order: { + summary: "Buy me!", + amount: "TESTKUDOS:5", + fulfillment_url: "taler://fulfillment-success/thx", }, + refundDelay: Duration.fromSpec({ minutes: 5 }), }); - await wallet.client.call(WalletApiOperation.ConfirmPay, { - transactionId: r1.transactionId, - choiceIndex: 0, - }); - - // Check if payment was successful. - - orderStatus = succeedOrThrow( - await merchantClient.getOrderDetails( - merchantAdminAccessToken, - orderResp.order_id, - ), - ); - - t.assertTrue(orderStatus.order_status === "paid"); - { const tx = await wallet.client.call(WalletApiOperation.GetTransactionById, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, }); t.assertTrue( @@ -135,14 +95,10 @@ export async function runRefundTest(t: GlobalTestState) { } const ref = succeedOrThrow( - await merchantClient.addRefund( - merchantAdminAccessToken, - orderResp.order_id, - { - refund: "TESTKUDOS:5", - reason: "foo", - }, - ), + await merchantClient.addRefund(merchantAdminAccessToken, payment.orderId, { + refund: "TESTKUDOS:5", + reason: "foo", + }), ); console.log(ref); @@ -151,11 +107,11 @@ export async function runRefundTest(t: GlobalTestState) { const refundFinishedCond = wallet.waitForNotificationCond( (x) => x.type === NotificationType.TransactionStateTransition && - x.transactionId === r1.transactionId && + x.transactionId === payment.transactionId && x.newTxState.major === TransactionMajorState.Done, ); await wallet.client.call(WalletApiOperation.StartRefundQuery, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, }); await refundFinishedCond; } @@ -172,7 +128,7 @@ export async function runRefundTest(t: GlobalTestState) { { const tx = await wallet.client.call(WalletApiOperation.GetTransactionById, { - transactionId: r1.transactionId, + transactionId: payment.transactionId, }); console.log(j2s(tx)); diff --git a/packages/taler-harness/src/integrationtests/test-repurchase.ts b/packages/taler-harness/src/integrationtests/test-repurchase.ts @@ -30,7 +30,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; @@ -38,17 +38,12 @@ import { GlobalTestState, harnessHttpLib, waitMs } from "../harness/harness.js"; * Check repurchase detection for legacy and version 1 contracts. */ export async function runRepurchaseTest(t: GlobalTestState) { - const { - walletClient, - exchange, - merchant, - merchantAdminAccessToken, - bankClient, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:30", }); diff --git a/packages/taler-harness/src/integrationtests/test-revocation.ts b/packages/taler-harness/src/integrationtests/test-revocation.ts @@ -17,10 +17,7 @@ /** * Imports. */ -import { - TalerCorebankApiClient, - TalerMerchantApi, -} from "@gnu-taler/taler-util"; +import { TalerMerchantApi } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig } from "../harness/denomStructures.js"; import { @@ -28,7 +25,10 @@ import { createBrowser, createWalletDaemonWithClient, makeTestPaymentV2, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -100,41 +100,27 @@ async function createTestEnvironment( let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, - accountPaytoUri: exchangePaytoUri, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + }); await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); + const bankClient = await startHarnessBank(bank); - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); const coin_u1: CoinConfig = { cipher: "RSA" as const, @@ -206,19 +192,14 @@ async function createTestEnvironment( export async function runRevocationTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createTestEnvironment(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createTestEnvironment(t); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:15", }); @@ -252,9 +233,9 @@ export async function runRevocationTest(t: GlobalTestState) { await walletClient.call(WalletApiOperation.ClearDb, {}); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:15", }); diff --git a/packages/taler-harness/src/integrationtests/test-simple-payment.ts b/packages/taler-harness/src/integrationtests/test-simple-payment.ts @@ -22,7 +22,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { makeTestPaymentV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -32,19 +32,14 @@ import { GlobalTestState } from "../harness/harness.js"; export async function runSimplePaymentTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - exchange, - merchant, - merchantAdminAccessToken, - bankClient, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts b/packages/taler-harness/src/integrationtests/test-timetravel-autorefresh.ts @@ -23,7 +23,6 @@ import { TransactionType, ExchangeUpdateStatus, NotificationType, - TalerCorebankApiClient, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, @@ -35,7 +34,10 @@ import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { applyTimeTravelV2, createWalletDaemonWithClient, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -89,39 +91,25 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addCoinConfigList(makeNoFeeCoinConfig("TESTKUDOS")); @@ -165,9 +153,9 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. t.logStep("Withdraw digital cash into the wallet."); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:15", }); @@ -238,9 +226,9 @@ export async function runTimetravelAutorefreshTest(t: GlobalTestState) { } t.logStep("withdrawing second time"); - const wres2 = await withdrawViaBankV3(t, { + const wres2 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts b/packages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts @@ -26,7 +26,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -60,14 +60,14 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) { "the test advances beyond the current seven denomination families and verifies that the pending withdrawal is redenominated", }); - const { walletClient, bankClient, exchange, merchant } = + const { bank, walletClient, exchange, merchant } = await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - const wres1 = await withdrawViaBankV3(t, { + const wres1 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:15", }); @@ -94,9 +94,9 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) { console.log("starting withdrawal via bank"); // This should fail, as the wallet didn't time travel yet. - const wres2 = await withdrawViaBankV3(t, { + const wres2 = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-basic.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-basic.ts @@ -30,10 +30,10 @@ import { TalerMerchantInstanceHttpClient, TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; -import { withdrawViaBankV3 } from "../harness/environments.js"; +import { withdrawViaBankV4 } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; -import { createTopsEnvironment } from "../harness/tops.js"; +import { createTopsEnvironment, doTopsAcceptTos } from "../harness/tops.js"; const logger = new Logger("test-tops-aml.ts"); @@ -42,7 +42,6 @@ export async function runTopsAmlBasicTest(t: GlobalTestState) { const { walletClient, - bankClient, exchange, merchant, merchantAdminAccessToken, @@ -61,9 +60,9 @@ export async function runTopsAmlBasicTest(t: GlobalTestState) { }); // Withdrawal below threshold succeeds! - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "CHF:20", - bankClient, + bank, exchange, walletClient, }); @@ -130,57 +129,13 @@ export async function runTopsAmlBasicTest(t: GlobalTestState) { } // Accept ToS - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - t.assertDeepEqual(kycInfo.case, "ok"); - t.assertDeepEqual(kycInfo.body.requirements.length, 1); - t.assertDeepEqual(kycInfo.body.requirements[0].form, "accept-tos"); - const requirementId = kycInfo.body.requirements[0].id; - t.assertTrue(typeof requirementId === "string"); - - const uploadRes = await exchangeClient.uploadKycForm(requirementId, { - FORM_ID: "accept-tos", - FORM_VERSION: 1, - ACCEPTED_TERMS_OF_SERVICE: "v1", - DOWNLOADED_TERMS_OF_SERVICE: true, - }); - console.log("upload res", uploadRes); - t.assertDeepEqual(uploadRes.case, "ok"); - } - - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - // FIXME: Do we expect volunary measures here? - // => not yet, see https://bugs.gnunet.org/view.php?id=9879 - } - - await merchant.runKyccheckOnce(); - - { - const kycStatus = await merchantClient.getCurrentInstanceKycStatus( - merchantAdminAccessToken, - { - longpoll: { - type: "state-enter", - status: MerchantAccountKycStatus.KYC_WIRE_REQUIRED, - timeout: 30000, - }, - }, - ); - logger.info(`kyc status after accept-tos: ${j2s(kycStatus)}`); - } + await doTopsAcceptTos(t, { + exchangeClient, + accessToken, + merchantClient, + merchantAdminAccessToken, + merchant, + }); // Trigger postal registration check // via AML officer. diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-postal.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-postal.ts @@ -32,7 +32,11 @@ import { } from "@gnu-taler/taler-util"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; -import { createTopsEnvironment, doFakeChallenger } from "../harness/tops.js"; +import { + createTopsEnvironment, + doFakeChallenger, + doTopsAcceptTos, +} from "../harness/tops.js"; const logger = new Logger("test-tops-aml.ts"); @@ -128,58 +132,13 @@ export async function runTopsAmlCustomAddrPostalTest(t: GlobalTestState) { }); // Accept ToS - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - t.assertDeepEqual(kycInfo.case, "ok"); - t.assertDeepEqual(kycInfo.body.requirements.length, 1); - t.assertDeepEqual(kycInfo.body.requirements[0].form, "accept-tos"); - const requirementId = kycInfo.body.requirements[0].id; - t.assertTrue(typeof requirementId === "string"); - - const uploadRes = await exchangeClient.uploadKycForm(requirementId, { - FORM_ID: "accept-tos", - FORM_VERSION: 1, - ACCEPTED_TERMS_OF_SERVICE: "v1", - DOWNLOADED_TERMS_OF_SERVICE: true, - }); - console.log("upload res", uploadRes); - t.assertDeepEqual(uploadRes.case, "ok"); - } - - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - // FIXME: Do we expect volunary measures here? - // => not yet, see https://bugs.gnunet.org/view.php?id=9879 - } - - await merchant.runKyccheckOnce(); - - { - const kycStatus = await merchantClient.getCurrentInstanceKycStatus( - merchantAdminAccessToken, - { - longpoll: { - type: "state-enter", - status: MerchantAccountKycStatus.KYC_WIRE_REQUIRED, - timeout: 30000, - }, - }, - ); - - logger.info(`kyc status after accept-tos: ${j2s(kycStatus)}`); - } + await doTopsAcceptTos(t, { + exchangeClient, + accessToken, + merchantClient, + merchantAdminAccessToken, + merchant, + }); // Trigger postal registration check // via AML officer. diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-sms.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-custom-addr-sms.ts @@ -35,7 +35,7 @@ import { } from "@gnu-taler/taler-util"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; -import { createTopsEnvironment } from "../harness/tops.js"; +import { createTopsEnvironment, doTopsAcceptTos } from "../harness/tops.js"; const logger = new Logger("test-tops-aml.ts"); @@ -132,57 +132,13 @@ export async function runTopsAmlCustomAddrSmsTest(t: GlobalTestState) { }); // Accept ToS - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - t.assertDeepEqual(kycInfo.case, "ok"); - t.assertDeepEqual(kycInfo.body.requirements.length, 1); - t.assertDeepEqual(kycInfo.body.requirements[0].form, "accept-tos"); - const requirementId = kycInfo.body.requirements[0].id; - t.assertTrue(typeof requirementId === "string"); - - const uploadRes = await exchangeClient.uploadKycForm(requirementId, { - FORM_ID: "accept-tos", - FORM_VERSION: 1, - ACCEPTED_TERMS_OF_SERVICE: "v1", - DOWNLOADED_TERMS_OF_SERVICE: true, - }); - console.log("upload res", uploadRes); - t.assertDeepEqual(uploadRes.case, "ok"); - } - - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - // FIXME: Do we expect volunary measures here? - // => not yet, see https://bugs.gnunet.org/view.php?id=9879 - } - - await merchant.runKyccheckOnce(); - - { - const kycStatus = await merchantClient.getCurrentInstanceKycStatus( - merchantAdminAccessToken, - { - longpoll: { - type: "state-enter", - status: MerchantAccountKycStatus.KYC_WIRE_REQUIRED, - timeout: 30000, - }, - }, - ); - logger.info(`kyc status after accept-tos: ${j2s(kycStatus)}`); - } + await doTopsAcceptTos(t, { + exchangeClient, + accessToken, + merchantClient, + merchantAdminAccessToken, + merchant, + }); const officerAcc: OfficerSession = { id: amlKeypair.pub as OfficerId, diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-p2p-fresh-wallet.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-p2p-fresh-wallet.ts @@ -54,29 +54,22 @@ * Imports. */ import { - AbsoluteTime, AccessToken, - AmountString, - Duration, j2s, Logger, succeedOrThrow, TalerExchangeHttpClient, TransactionMajorState, TransactionMinorState, - TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + doPeerPushDebit, + withdrawViaBankV4, } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { - GlobalTestState, - harnessHttpLib, - WalletClient, -} from "../harness/harness.js"; +import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -86,7 +79,7 @@ import { const logger = new Logger("test-tops-aml-p2p-fresh-wallet.ts"); export async function runTopsAmlP2pFreshWalletTest(t: GlobalTestState) { - const { walletClient, bankClient, exchange, officerAcc } = + const { bank, walletClient, exchange, officerAcc } = await createTopsEnvironment(t, { // The un-collapsed form of the inventory's "\\+41[0-9]+": one or more // literal backslashes followed by "41...", which no phone number @@ -108,8 +101,8 @@ export async function runTopsAmlP2pFreshWalletTest(t: GlobalTestState) { // Sending wallet. const w0 = await createWalletDaemonWithClient(t, { name: "w0" }); - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "CHF:20", exchange, walletClient: w0.walletClient, @@ -199,46 +192,5 @@ export async function runTopsAmlP2pFreshWalletTest(t: GlobalTestState) { t.assertTrue(stillPending == null); } -async function doPeerPushDebit( - t: GlobalTestState, - args: { - walletClient: WalletClient; - amount: AmountString; - summary?: string; - }, -): Promise<{ transactionId: string; talerUri: string }> { - const purse_expiration = AbsoluteTime.toProtocolTimestamp( - AbsoluteTime.addDuration( - AbsoluteTime.now(), - Duration.fromSpec({ days: 2 }), - ), - ); - const initRet = await args.walletClient.call( - WalletApiOperation.InitiatePeerPushDebit, - { - partialContractTerms: { - amount: args.amount, - summary: args.summary ?? "Test P2P Payment", - purse_expiration, - }, - }, - ); - await args.walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: initRet.transactionId, - txState: { - major: TransactionMajorState.Pending, - minor: TransactionMinorState.Ready, - }, - }); - const txDet = await args.walletClient.call( - WalletApiOperation.GetTransactionById, - { transactionId: initRet.transactionId }, - ); - t.assertTrue(txDet.type === TransactionType.PeerPushDebit); - const talerUri = txDet.talerUri; - t.assertTrue(!!talerUri); - return { transactionId: initRet.transactionId, talerUri }; -} - runTopsAmlP2pFreshWalletTest.suites = ["wallet"]; runTopsAmlP2pFreshWalletTest.timeoutMs = 120000; diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-sanction-preserves-rules.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-sanction-preserves-rules.ts @@ -56,30 +56,23 @@ * Imports. */ import { - AbsoluteTime, AccessToken, - AmountString, - Duration, j2s, Logger, succeedOrThrow, TalerExchangeHttpClient, TransactionMajorState, TransactionMinorState, - TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import * as fs from "node:fs"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + doPeerPushDebit, + withdrawViaBankV4, } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { - GlobalTestState, - harnessHttpLib, - WalletClient, -} from "../harness/harness.js"; +import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -116,7 +109,7 @@ export async function runTopsAmlSanctionPreservesRulesTest(t: GlobalTestState) { const setRating = (rating: string, confidence: string) => fs.writeFileSync(ratingFile, `${rating} ${confidence} fake-entry\n`); - const { walletClient, bankClient, exchange, officerAcc } = + const { bank, walletClient, exchange, officerAcc } = await createTopsEnvironment(t, { adjustExchangeConfig: (config) => { config.setString("exchange-sanctionscheck", "RATER_COMMAND", raterFile); @@ -171,8 +164,8 @@ export async function runTopsAmlSanctionPreservesRulesTest(t: GlobalTestState) { // p2p-domestic-identification-requirement (THRESHOLD = CHF:0). // ------------------------------------------------------------------ const w0 = await createWalletDaemonWithClient(t, { name: "w0" }); - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "CHF:20", exchange, walletClient: w0.walletClient, @@ -285,46 +278,5 @@ export async function runTopsAmlSanctionPreservesRulesTest(t: GlobalTestState) { t.assertTrue(!isFrozen(dec)); } -async function doPeerPushDebit( - t: GlobalTestState, - args: { - walletClient: WalletClient; - amount: AmountString; - summary?: string; - }, -): Promise<{ transactionId: string; talerUri: string }> { - const purse_expiration = AbsoluteTime.toProtocolTimestamp( - AbsoluteTime.addDuration( - AbsoluteTime.now(), - Duration.fromSpec({ days: 2 }), - ), - ); - const initRet = await args.walletClient.call( - WalletApiOperation.InitiatePeerPushDebit, - { - partialContractTerms: { - amount: args.amount, - summary: args.summary ?? "Test P2P Payment", - purse_expiration, - }, - }, - ); - await args.walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: initRet.transactionId, - txState: { - major: TransactionMajorState.Pending, - minor: TransactionMinorState.Ready, - }, - }); - const txDet = await args.walletClient.call( - WalletApiOperation.GetTransactionById, - { transactionId: initRet.transactionId }, - ); - t.assertTrue(txDet.type === TransactionType.PeerPushDebit); - const talerUri = txDet.talerUri; - t.assertTrue(!!talerUri); - return { transactionId: initRet.transactionId, talerUri }; -} - runTopsAmlSanctionPreservesRulesTest.suites = ["wallet"]; runTopsAmlSanctionPreservesRulesTest.timeoutMs = 120000; diff --git a/packages/taler-harness/src/integrationtests/test-tops-aml-stale-validation.ts b/packages/taler-harness/src/integrationtests/test-tops-aml-stale-validation.ts @@ -60,7 +60,6 @@ import { AbsoluteTime, AccessToken, - AmountString, Duration, j2s, Logger, @@ -68,19 +67,15 @@ import { TalerExchangeHttpClient, TransactionMajorState, TransactionMinorState, - TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + doPeerPushDebit, + withdrawViaBankV4, } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; -import { - GlobalTestState, - harnessHttpLib, - WalletClient, -} from "../harness/harness.js"; +import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; import { createTopsEnvironment, doFakeChallenger, @@ -90,7 +85,7 @@ import { const logger = new Logger("test-tops-aml-stale-validation.ts"); export async function runTopsAmlStaleValidationTest(t: GlobalTestState) { - const { walletClient, bankClient, exchange, officerAcc } = + const { bank, walletClient, exchange, officerAcc } = await createTopsEnvironment(t); // An address whose validation has already aged out. The regex is the @@ -111,8 +106,8 @@ export async function runTopsAmlStaleValidationTest(t: GlobalTestState) { }); const w0 = await createWalletDaemonWithClient(t, { name: "w0" }); - const wres = await withdrawViaBankV3(t, { - bankClient, + const wres = await withdrawViaBankV4(t, { + bank, amount: "CHF:20", exchange, walletClient: w0.walletClient, @@ -190,46 +185,5 @@ export async function runTopsAmlStaleValidationTest(t: GlobalTestState) { t.assertTrue(stillPending == null); } -async function doPeerPushDebit( - t: GlobalTestState, - args: { - walletClient: WalletClient; - amount: AmountString; - summary?: string; - }, -): Promise<{ transactionId: string; talerUri: string }> { - const purse_expiration = AbsoluteTime.toProtocolTimestamp( - AbsoluteTime.addDuration( - AbsoluteTime.now(), - Duration.fromSpec({ days: 2 }), - ), - ); - const initRet = await args.walletClient.call( - WalletApiOperation.InitiatePeerPushDebit, - { - partialContractTerms: { - amount: args.amount, - summary: args.summary ?? "Test P2P Payment", - purse_expiration, - }, - }, - ); - await args.walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: initRet.transactionId, - txState: { - major: TransactionMajorState.Pending, - minor: TransactionMinorState.Ready, - }, - }); - const txDet = await args.walletClient.call( - WalletApiOperation.GetTransactionById, - { transactionId: initRet.transactionId }, - ); - t.assertTrue(txDet.type === TransactionType.PeerPushDebit); - const talerUri = txDet.talerUri; - t.assertTrue(!!talerUri); - return { transactionId: initRet.transactionId, talerUri }; -} - runTopsAmlStaleValidationTest.suites = ["wallet"]; runTopsAmlStaleValidationTest.timeoutMs = 120000; diff --git a/packages/taler-harness/src/integrationtests/test-tops-merchant-tos.ts b/packages/taler-harness/src/integrationtests/test-tops-merchant-tos.ts @@ -26,7 +26,11 @@ import { TalerMerchantInstanceHttpClient, } from "@gnu-taler/taler-util"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; -import { createTopsEnvironment, doTopsKycAuth } from "../harness/tops.js"; +import { + createTopsEnvironment, + doTopsKycAuth, + acceptTopsTosForm, +} from "../harness/tops.js"; export const logger = new Logger("test-tops-aml.ts"); @@ -63,29 +67,7 @@ export async function runTopsMerchantTosTest(t: GlobalTestState) { bank, }); - { - const kycInfo = await exchangeClient.checkKycInfo( - accessToken, - undefined, - undefined, - ); - console.log(j2s(kycInfo)); - - t.assertDeepEqual(kycInfo.case, "ok"); - t.assertDeepEqual(kycInfo.body.requirements.length, 1); - t.assertDeepEqual(kycInfo.body.requirements[0].form, "accept-tos"); - const requirementId = kycInfo.body.requirements[0].id; - t.assertTrue(typeof requirementId === "string"); - - const uploadRes = await exchangeClient.uploadKycForm(requirementId, { - FORM_ID: "accept-tos", - FORM_VERSION: 1, - ACCEPTED_TERMS_OF_SERVICE: "v1", - DOWNLOADED_TERMS_OF_SERVICE: true, - }); - console.log("upload res", uploadRes); - t.assertDeepEqual(uploadRes.case, "ok"); - } + await acceptTopsTosForm(t, { exchangeClient, accessToken }); { const kycInfo = await exchangeClient.checkKycInfo( diff --git a/packages/taler-harness/src/integrationtests/test-tops-peer.ts b/packages/taler-harness/src/integrationtests/test-tops-peer.ts @@ -30,7 +30,7 @@ import { TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { withdrawViaBankV3 } from "../harness/environments.js"; +import { withdrawViaBankV4 } from "../harness/environments.js"; import { startFakeChallenger } from "../harness/fake-challenger.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; import { createTopsEnvironment } from "../harness/tops.js"; @@ -38,7 +38,7 @@ import { createTopsEnvironment } from "../harness/tops.js"; export async function runTopsPeerTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange, exchangeApi, officerAcc } = + const { bank, walletClient, exchange, exchangeApi, officerAcc } = await createTopsEnvironment(t); const challenger = await startFakeChallenger(t, { @@ -53,9 +53,9 @@ export async function runTopsPeerTest(t: GlobalTestState) { t.logStep("starting withdrawal"); // Withdrawal below threshold succeeds! - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "CHF:20", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-tops-transaction-risk-monitoring.ts b/packages/taler-harness/src/integrationtests/test-tops-transaction-risk-monitoring.ts @@ -32,13 +32,13 @@ import { TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { defaultCoinConfig } from "../harness/denomStructures.js"; import { configureCommonKyc, createKycTestkudosEnvironmentFull, postAmlDecision, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; -import { defaultCoinConfig } from "../harness/denomStructures.js"; import { GlobalTestState, runCommand } from "../harness/harness.js"; const DAY_MS = 24 * 60 * 60 * 1000; @@ -67,7 +67,6 @@ export async function runTopsTransactionRiskMonitoringTest(t: GlobalTestState) { // Keep denominations withdrawable as well as spendable across the jump. const { walletClient, - bankClient, exchange, bank, wireGatewayApi, @@ -93,8 +92,8 @@ export async function runTopsTransactionRiskMonitoringTest(t: GlobalTestState) { id: amlKeypair.pub as OfficerId, __signingKey: decodeCrock(amlKeypair.priv), }; - const withdrawal = await withdrawViaBankV3(t, { - bankClient, + const withdrawal = await withdrawViaBankV4(t, { + bank, exchange, walletClient, amount: "TESTKUDOS:500000", diff --git a/packages/taler-harness/src/integrationtests/test-tos-format.ts b/packages/taler-harness/src/integrationtests/test-tos-format.ts @@ -18,9 +18,9 @@ * Imports. */ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; import * as fs from "node:fs"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -38,7 +38,7 @@ export async function runTermOfServiceFormatTest(t: GlobalTestState) { fs.writeFileSync(langDir + "v1.html", "html content"); }); - const { walletClient, exchange } = await createSimpleTestkudosEnvironmentV2( + const { walletClient, exchange } = await createSimpleTestkudosEnvironmentV3( t, undefined, { diff --git a/packages/taler-harness/src/integrationtests/test-transaction-final-amounts.ts b/packages/taler-harness/src/integrationtests/test-transaction-final-amounts.ts @@ -15,18 +15,18 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; /** Fee-bearing push cancellation and expiry must match the real balance loss. */ export async function runTransactionFinalAmountsTest(t: GlobalTestState) { const env = await createSimpleTestkudosEnvironmentV3(t); - const { bankClient, exchange } = env; + const { bank, exchange } = env; let { walletClient: wallet, walletService } = env; - const w = await withdrawViaBankV3(t, { + const w = await withdrawViaBankV4(t, { walletClient: wallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:40", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-bad-network.ts b/packages/taler-harness/src/integrationtests/test-wallet-bad-network.ts @@ -17,16 +17,12 @@ /** * Imports. */ -import { - TalerCorebankApiClient, - TransactionMajorState, - TransactionType, -} from "@gnu-taler/taler-util"; +import { TransactionMajorState, TransactionType } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -39,7 +35,7 @@ import { GlobalTestState } from "../harness/harness.js"; * first time, which is the half of it that cannot go wrong. */ export async function runWalletBadNetworkTest(t: GlobalTestState) { - const { bankClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); const { walletClient } = await createWalletDaemonWithClient(t, { name: "w-bad-net", @@ -52,9 +48,9 @@ export async function runWalletBadNetworkTest(t: GlobalTestState) { // Set the withdrawal up over a working network: these are foreground // requests from the test itself, and nothing retries those. - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient, - bankClient: bankClient as TalerCorebankApiClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance-zero.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance-zero.ts @@ -20,12 +20,12 @@ import { j2s } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; -import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; /** * Related bugs: @@ -36,17 +36,12 @@ export async function runWalletBalanceZeroTest(t: GlobalTestState) { const coinConfig = makeNoFeeCoinConfig("TESTKUDOS"); console.log(`coin config ${j2s(coinConfig)}`); - const { - merchant, - walletClient, - exchange, - bankClient, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t, coinConfig); + const { bank, merchant, walletClient, exchange, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t, coinConfig); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:10", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-balance.ts @@ -25,7 +25,6 @@ import { Duration, j2s, succeedOrThrow, - TalerCorebankApiClient, TalerMerchantApi, TalerMerchantInstanceHttpClient, TransactionMajorState, @@ -35,7 +34,10 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -54,7 +56,6 @@ import { interface MyTestEnvironment { commonDb: DbInfo; bank: BankService; - bankClient: TalerCorebankApiClient; exchange: ExchangeService; exchangeBankAccount: HarnessExchangeBankAccount; merchant: MerchantService; @@ -98,44 +99,30 @@ async function createMyEnvironment( const exchangeBankUsername = "exchange"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; + const wireGatewayAuth: BasicAuth = { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }; - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth, - accountPaytoUri: exchangePaytoUri, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: wireGatewayAuth, + accountPaytoUri: exchangePaytoUri, + }); await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); - await bank.start(); + const bankClient = await startHarnessBank(bank); - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addOfferedCoins(defaultCoinConfig); @@ -188,7 +175,6 @@ async function createMyEnvironment( walletClient, walletService, bank, - bankClient, merchantAdminAccessToken, exchangeBankAccount, }; @@ -215,13 +201,8 @@ export async function runWalletBalanceTest(t: GlobalTestState) { "the test configures a second, healthy IBAN exchange while deliberately creating a void-target order to test receiver-specific balance diagnostics", }); - const { - merchant, - walletClient, - exchange, - bankClient, - merchantAdminAccessToken, - } = await createMyEnvironment(t); + const { bank, merchant, walletClient, exchange, merchantAdminAccessToken } = + await createMyEnvironment(t); const merchantClient = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), @@ -229,9 +210,9 @@ export async function runWalletBalanceTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts @@ -37,7 +37,7 @@ import { topupReserveWithBank, withdrawCoin, } from "@gnu-taler/taler-wallet-core/dbless"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; /** @@ -46,7 +46,7 @@ import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; export async function runWalletDblessTest(t: GlobalTestState) { // Set up test environment - const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); const http = harnessHttpLib; const cryptiDisp = new CryptoDispatcher( diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dd48.ts b/packages/taler-harness/src/integrationtests/test-wallet-dd48.ts @@ -21,7 +21,6 @@ import { BasicAuth, ExchangeEntryStatus, NotificationType, - TalerCorebankApiClient, TalerError, TalerErrorCode, WalletNotification, @@ -29,13 +28,15 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; -import { withdrawViaBankV3 } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + startHarnessBank, + withdrawViaBankV4, +} from "../harness/environments.js"; import { BankService, ExchangeService, GlobalTestState, - WalletClient, - WalletService, getTestHarnessPaytoForLabel, setupDb, } from "../harness/harness.js"; @@ -83,16 +84,7 @@ export async function runWalletDd48Test(t: GlobalTestState) { bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); await bankClient.registerAccountExtended({ name: receiverName, @@ -108,25 +100,13 @@ export async function runWalletDd48Test(t: GlobalTestState) { await exchange.start(); await exchange.pingUntilAvailable(); - const walletService = new WalletService(t, { - name: "wallet", - useInMemoryDb: true, - }); - await walletService.start(); - await walletService.pingUntilAvailable(); - const allNotifications: WalletNotification[] = []; - - const walletClient = new WalletClient({ + const { walletClient } = await createWalletDaemonWithClient(t, { name: "wallet", - unixPath: walletService.socketPath, - onNotification(n) { + handleNotification(n) { console.log("got notification", n); allNotifications.push(n); }, - }); - await walletClient.connect(); - await walletClient.client.call(WalletApiOperation.InitWallet, { config: { testing: { skipDefaults: true, @@ -161,10 +141,10 @@ export async function runWalletDd48Test(t: GlobalTestState) { t.assertDeepEqual(resources.hasResources, false); } - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, amount: "TESTKUDOS:20", - bankClient, + bank, exchange, }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-denom-expire.ts b/packages/taler-harness/src/integrationtests/test-wallet-denom-expire.ts @@ -23,7 +23,7 @@ import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, setupDb } from "../harness/harness.js"; @@ -46,14 +46,14 @@ export async function runWalletDenomExpireTest(t: GlobalTestState) { const coinConfig = makeNoFeeCoinConfig("TESTKUDOS"); - const { walletClient, bankClient, exchange, merchant } = + const { bank, walletClient, exchange, merchant } = await createSimpleTestkudosEnvironmentV3(t, coinConfig, {}); // Withdraw digital cash into the wallet. - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:15", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-deposit-large.ts b/packages/taler-harness/src/integrationtests/test-wallet-deposit-large.ts @@ -23,33 +23,13 @@ import { UserAndToken, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig } from "../harness/denomStructures.js"; +import { makeLargeCoinTestConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, waitMs } from "../harness/harness.js"; -const coinCommon = { - cipher: "RSA" as const, - durationLegal: "3 years", - durationSpend: "2 years", - durationWithdraw: "7 days", - feeDeposit: "TESTKUDOS:0", - feeRefresh: "TESTKUDOS:0", - feeRefund: "TESTKUDOS:0", - feeWithdraw: "TESTKUDOS:0", - rsaKeySize: 1024, -}; - -const coinConfigList: CoinConfig[] = [ - { - ...coinCommon, - name: "n1", - value: "TESTKUDOS:1", - }, -]; - /** * Test deposit with a large number of coins. * @@ -61,8 +41,8 @@ const coinConfigList: CoinConfig[] = [ */ export async function runWalletDepositLargeTest(t: GlobalTestState) { // Set up test environment - const { walletClient, bankClient, exchange, bank } = - await createSimpleTestkudosEnvironmentV3(t, coinConfigList, { + const { walletClient, exchange, bank } = + await createSimpleTestkudosEnvironmentV3(t, makeLargeCoinTestConfig(), { // fakebank doesn't support /accounts/$ACCOUNT/transactions // needed for this test. forceLibeufin: true, @@ -72,9 +52,9 @@ export async function runWalletDepositLargeTest(t: GlobalTestState) { }); // Withdraw digital cash into the wallet. - const withdrawRes = await withdrawViaBankV3(t, { + const withdrawRes = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:200", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-devexp-fakeprotover.ts b/packages/taler-harness/src/integrationtests/test-wallet-devexp-fakeprotover.ts @@ -27,14 +27,14 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; const logger = new Logger("test-wallet-devexp-fakeprotover.ts"); export async function runWalletDevexpFakeprotoverTest(t: GlobalTestState) { - const { walletClient, exchange, bankClient } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3(t); const exchangeClient = new TalerExchangeHttpClient(exchange.baseUrl, { @@ -46,11 +46,11 @@ export async function runWalletDevexpFakeprotoverTest(t: GlobalTestState) { const newerVer = `${exchVer.current + 1}:0:0`; - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, exchange, amount: "TESTKUDOS:10", - bankClient, + bank, }); await wres.withdrawalFinishedCond; diff --git a/packages/taler-harness/src/integrationtests/test-wallet-exchange-features.ts b/packages/taler-harness/src/integrationtests/test-wallet-exchange-features.ts @@ -17,12 +17,15 @@ /** * Imports. */ -import { j2s, TalerCorebankApiClient } from "@gnu-taler/taler-util"; +import { j2s } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -61,43 +64,28 @@ export async function runWalletExchangeFeaturesTest(t: GlobalTestState) { const exchangeBankUsername = "exchange"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; - - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - accountPaytoUri: exchangePaytoUri, - }; + + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + }); await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchange.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); @@ -121,9 +109,9 @@ export async function runWalletExchangeFeaturesTest(t: GlobalTestState) { console.log("setup done!"); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:5", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-exchange-migration.ts b/packages/taler-harness/src/integrationtests/test-wallet-exchange-migration.ts @@ -28,7 +28,7 @@ import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, createWalletDaemonWithClient, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { ExchangeService, GlobalTestState } from "../harness/harness.js"; @@ -54,15 +54,15 @@ export async function runWalletExchangeMigrationTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient: newTargetWallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient: existingTargetWallet, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -97,9 +97,9 @@ export async function runWalletExchangeMigrationTest(t: GlobalTestState) { await exchange2.start(); - const targetWithdrawal = await withdrawViaBankV3(t, { + const targetWithdrawal = await withdrawViaBankV4(t, { walletClient: existingTargetWallet, - bankClient, + bank, exchange: exchange2, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts b/packages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts @@ -28,7 +28,8 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createWalletDaemonWithClient, - withdrawViaBankV3, + registerHarnessExchangeBankAccount, + withdrawViaBankV4, } from "../harness/environments.js"; import { BankService, @@ -117,13 +118,7 @@ export async function runWalletExchangeUpdateTest( await bank.start(); - bankClient.registerAccountExtended({ - name: exchangeBankAccount.wireGatewayAuth.username, - username: exchangeBankAccount.wireGatewayAuth.username, - password: exchangeBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeBankAccount.accountPaytoUri, - }); + registerHarnessExchangeBankAccount(bankClient, exchangeBankAccount); exchangeOne.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); exchangeTwo.addCoinConfigList(defaultCoinConfig.map((x) => x("TESTKUDOS"))); @@ -145,9 +140,9 @@ export async function runWalletExchangeUpdateTest( t.assertDeepEqual(exchangesListResult.exchanges.length, 0); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange: exchangeOne, amount: "TESTKUDOS:10", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-gendb.ts b/packages/taler-harness/src/integrationtests/test-wallet-gendb.ts @@ -26,12 +26,12 @@ import { TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { GlobalTestState } from "../harness/harness.js"; import { createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; +import { GlobalTestState } from "../harness/harness.js"; /** * Test that creates various transactions and exports the resulting @@ -41,19 +41,14 @@ import { export async function runWalletGenDbTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:50", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts b/packages/taler-harness/src/integrationtests/test-wallet-insufficient-balance.ts @@ -34,7 +34,9 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + withdrawViaBankV4, } from "../harness/environments.js"; import { ExchangeService, @@ -76,10 +78,6 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { const exchangeBankUsername = "exchange2"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; const wireGatewayAuth: BasicAuth = { type: "basic", @@ -87,22 +85,20 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { password: exchangeBankPassword, }; - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth, - accountPaytoUri: exchangePaytoUri, - skipWireFeeCreation: true, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: wireGatewayAuth, + accountPaytoUri: exchangePaytoUri, + skipWireFeeCreation: true, + }); await exchangeTwo.addBankAccount("1", exchangeBankAccount); - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); exchangeTwo.addCoinConfigList(coinConfig); @@ -119,9 +115,9 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { t.logStep("setup-done"); - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:10", - bankClient, + bank, exchange, walletClient, }); @@ -196,9 +192,9 @@ export async function runWalletInsufficientBalanceTest(t: GlobalTestState) { // Now check for p2p-push { - const wres2 = await withdrawViaBankV3(t, { + const wres2 = await withdrawViaBankV4(t, { amount: "TESTKUDOS:5", - bankClient, + bank, exchange: exchangeTwo, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-network-availability.ts b/packages/taler-harness/src/integrationtests/test-wallet-network-availability.ts @@ -31,7 +31,7 @@ import { } from "@gnu-taler/taler-wallet-core"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -43,15 +43,15 @@ import { */ export async function runWalletNetworkAvailabilityTest(t: GlobalTestState) { // Set up test environment - const { bankClient, walletClient, exchange } = + const { bank, walletClient, exchange } = await createSimpleTestkudosEnvironmentV3(t, undefined, { // We need this to listen to the network-required observability event walletTestObservability: true, }); - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts b/packages/taler-harness/src/integrationtests/test-wallet-notifications.ts @@ -21,7 +21,6 @@ import { BasicAuth, Duration, NotificationType, - TalerCorebankApiClient, TransactionMajorState, TransactionMinorState, TransactionType, @@ -30,12 +29,14 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { + createWalletDaemonWithClient, + startHarnessBank, +} from "../harness/environments.js"; +import { BankService, ExchangeService, GlobalTestState, MerchantService, - WalletClient, - WalletService, generateRandomTestIban, getTestHarnessPaytoForLabel, setupDb, @@ -91,16 +92,7 @@ export async function runWalletNotificationsTest(t: GlobalTestState) { bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); await bankClient.registerAccountExtended({ name: receiverName, @@ -138,31 +130,23 @@ export async function runWalletNotificationsTest(t: GlobalTestState) { console.log("setup done!"); - const walletService = new WalletService(t, { - name: "wallet", - useInMemoryDb: true, - }); - await walletService.start(); - await walletService.pingUntilAvailable(); - const allNotifications: WalletNotification[] = []; - const walletClient = new WalletClient({ - name: "wallet", - unixPath: walletService.socketPath, - onNotification(n) { - console.log("got notification", n); - allNotifications.push(n); - }, - }); - await walletClient.connect(); - await walletClient.client.call(WalletApiOperation.InitWallet, { - config: { - testing: { - skipDefaults: true, - emitObservabilityEvents: true, + const { walletClient, walletService } = await createWalletDaemonWithClient( + t, + { + name: "wallet", + handleNotification(n) { + console.log("got notification", n); + allNotifications.push(n); + }, + config: { + testing: { + skipDefaults: true, + emitObservabilityEvents: true, + }, }, }, - }); + ); const user = await bankClient.createRandomBankUser(); bankClient.setAuth(user); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh-errors.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh-errors.ts @@ -17,12 +17,12 @@ /** * Imports. */ -import { AmountString, TalerCorebankApiClient } from "@gnu-taler/taler-util"; +import { AmountString } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig } from "../harness/denomStructures.js"; import { - createSimpleTestkudosEnvironmentV2, - withdrawViaBankV3, + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -84,13 +84,11 @@ export async function runWalletRefreshErrorsTest(t: GlobalTestState) { ]; const { walletClient, bank, exchange } = - await createSimpleTestkudosEnvironmentV2(t, coinConfigList); + await createSimpleTestkudosEnvironmentV3(t, coinConfigList); - const bankClient = new TalerCorebankApiClient(bank.baseUrl); - - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:5", - bankClient, + bank, exchange, walletClient, }); @@ -134,9 +132,9 @@ export async function runWalletRefreshErrorsTest(t: GlobalTestState) { await walletClient.call(WalletApiOperation.ClearDb, {}); { - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { amount: "TESTKUDOS:5", - bankClient, + bank, exchange, walletClient, }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh-redenominate.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh-redenominate.ts @@ -30,7 +30,7 @@ import { applyTimeTravelV2, createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -64,29 +64,24 @@ export async function runWalletRefreshRedenominateTest(t: GlobalTestState) { "the test time-travels past a blocked refresh denomination and verifies the wallet's MELT_GONE recovery path", }); - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3( - t, - defaultCoinConfig.map((x) => x("TESTKUDOS")), - { - walletConfig: { - testing: { - devModeActive: true, + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3( + t, + defaultCoinConfig.map((x) => x("TESTKUDOS")), + { + walletConfig: { + testing: { + devModeActive: true, + }, }, }, - }, - ); + ); // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts @@ -33,7 +33,7 @@ import { import { createSimpleTestkudosEnvironmentV3, makeTestPaymentV2, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, @@ -46,19 +46,14 @@ import { export async function runWalletRefreshTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - bankClient, - exchange, - merchant, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); @@ -154,9 +149,9 @@ export async function runWalletRefreshTest(t: GlobalTestState) { ); } - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens-discount.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens-discount.ts @@ -38,37 +38,32 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState, WalletClient } from "../harness/harness.js"; const logger = new Logger("test-wallet-tokens-discount.ts"); export async function runWalletTokensDiscountTest(t: GlobalTestState) { - let { - bankClient, - exchange, - merchant, - walletClient, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3( - t, - defaultCoinConfig.map((x) => x("TESTKUDOS")), - { - walletConfig: { - features: {}, + let { bank, exchange, merchant, walletClient, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3( + t, + defaultCoinConfig.map((x) => x("TESTKUDOS")), + { + walletConfig: { + features: {}, + }, }, - }, - ); + ); const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); // withdraw some test money - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:40", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts @@ -40,7 +40,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; @@ -56,30 +56,25 @@ export async function runWalletTokensTest(t: GlobalTestState) { "the test deliberately confirms a choice without the required token and asserts that confirmation is rejected", }); - let { - bankClient, - exchange, - merchant, - walletClient, - merchantAdminAccessToken, - } = await createSimpleTestkudosEnvironmentV3( - t, - defaultCoinConfig.map((x) => x("TESTKUDOS")), - { - walletConfig: { - features: {}, + let { bank, exchange, merchant, walletClient, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3( + t, + defaultCoinConfig.map((x) => x("TESTKUDOS")), + { + walletConfig: { + features: {}, + }, }, - }, - ); + ); const merchantApi = new TalerMerchantInstanceHttpClient( merchant.makeInstanceBaseUrl(), ); // withdraw some test money - const wres = await withdrawViaBankV3(t, { + const wres = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:40", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-transactions.ts b/packages/taler-harness/src/integrationtests/test-wallet-transactions.ts @@ -31,20 +31,15 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { makeTestPaymentV2, createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; export async function runWalletTransactionsTest(t: GlobalTestState) { // Set up test environment - const { - walletClient, - exchange, - merchant, - merchantAdminAccessToken, - bankClient, - } = await createSimpleTestkudosEnvironmentV3(t); + const { bank, walletClient, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t); { const txRes = await walletClient.call( @@ -56,9 +51,9 @@ export async function runWalletTransactionsTest(t: GlobalTestState) { // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-chrome-extension-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-chrome-extension-withdrawal.ts @@ -15,8 +15,6 @@ */ import fs from "node:fs"; -import http from "node:http"; -import net from "node:net"; import path from "node:path"; import * as nodeUrl from "node:url"; import type { BrowserContext, Page } from "playwright-core"; @@ -27,45 +25,10 @@ import { findBrowserBinary } from "../stagefright/stage.js"; import { findWalletWebUiDirectory, walletWebUiArtifactPath, + reserveTcpPort, + waitForWalletWebUi, } from "./wallet-web-ui-test-support.js"; -async function reserveTcpPort(): Promise<number> { - const server = net.createServer(); - await new Promise<void>((resolve, reject) => { - server.once("error", reject); - server.listen(0, "127.0.0.1", resolve); - }); - const address = server.address(); - if (!address || typeof address === "string") - throw Error("could not reserve a TCP port"); - await new Promise<void>((resolve, reject) => - server.close((error) => (error ? reject(error) : resolve())), - ); - return address.port; -} - -async function waitForBuild(url: string, timeoutMs = 90_000): Promise<void> { - const deadline = Date.now() + timeoutMs; - while (Date.now() < deadline) { - try { - const status = await new Promise<number | undefined>( - (resolve, reject) => { - const request = http.get(url, (response) => { - response.resume(); - resolve(response.statusCode); - }); - request.once("error", reject); - }, - ); - if (status && status >= 200 && status < 300) return; - } catch { - // The build server is not listening yet. - } - await new Promise((resolve) => setTimeout(resolve, 250)); - } - throw Error("wallet-webui extension build did not become ready"); -} - async function screenshot( page: Page, directory: string, @@ -120,7 +83,11 @@ export async function runWalletWebUiChromeExtensionWithdrawalTest( [path.join(walletWebUiDirectory, "test-server.mjs"), `--port=${buildPort}`], "wallet-webui-build", ); - await waitForBuild(`http://127.0.0.1:${buildPort}/`); + await waitForWalletWebUi( + `http://127.0.0.1:${buildPort}/`, + 90_000, + "extension build", + ); const extensionDirectory = walletWebUiArtifactPath( walletWebUiDirectory, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-integration.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-extension-integration.ts @@ -9,7 +9,6 @@ import assert from "node:assert/strict"; import http from "node:http"; -import net from "node:net"; import path from "node:path"; import * as nodeUrl from "node:url"; import type { BrowserContext, Page } from "playwright-core"; @@ -23,6 +22,8 @@ import { findBrowserBinary } from "../stagefright/stage.js"; import { findWalletWebUiDirectory, walletWebUiArtifactPath, + reserveTcpPort, + waitForWalletWebUi, } from "./wallet-web-ui-test-support.js"; const SETTINGS_KEY = "gnu-taler-wallet-browser-integration-v1"; @@ -40,42 +41,6 @@ interface IntegrationSettings { hijackLinks: boolean; } -async function reserveTcpPort(): Promise<number> { - const server = net.createServer(); - await new Promise<void>((resolve, reject) => { - server.once("error", reject); - server.listen(0, "127.0.0.1", resolve); - }); - const address = server.address(); - if (!address || typeof address === "string") throw Error("no test port"); - await new Promise<void>((resolve, reject) => - server.close((error) => (error ? reject(error) : resolve())), - ); - return address.port; -} - -async function waitForBuild(url: string): Promise<void> { - const deadline = Date.now() + 90_000; - while (Date.now() < deadline) { - try { - const status = await new Promise<number | undefined>( - (resolve, reject) => { - const request = http.get(url, (response) => { - response.resume(); - resolve(response.statusCode); - }); - request.once("error", reject); - }, - ); - if (status && status >= 200 && status < 300) return; - } catch { - // Build server has not started yet. - } - await new Promise((resolve) => setTimeout(resolve, 250)); - } - throw Error("wallet-webui extension build did not become ready"); -} - function fixtureHtml(url: URL): string { const support = url.searchParams.get("support") ?? ""; const metadata = url.searchParams.get("metadata"); @@ -147,7 +112,11 @@ function startBuild( [path.join(walletDirectory, "test-server.mjs"), `--port=${port}`], "wallet-webui-integration-build", ); - await waitForBuild(`http://127.0.0.1:${port}/`); + await waitForWalletWebUi( + `http://127.0.0.1:${port}/`, + 90_000, + "extension build", + ); }); } diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-firefox-extension-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-firefox-extension-withdrawal.ts @@ -15,8 +15,6 @@ */ import fs from "node:fs"; -import http from "node:http"; -import net from "node:net"; import path from "node:path"; import { loadSelenium, @@ -27,6 +25,8 @@ import { GlobalTestState } from "../harness/harness.js"; import { findWalletWebUiDirectory, walletWebUiArtifactPath, + reserveTcpPort, + waitForWalletWebUi, } from "./wallet-web-ui-test-support.js"; const EXTENSION_ID = "wallet@taler.net"; @@ -35,43 +35,6 @@ type FirefoxDriver = import("selenium-webdriver/firefox.js").Driver; let selenium: typeof import("selenium-webdriver"); let Firefox: typeof import("selenium-webdriver/firefox.js"); -async function reserveTcpPort(): Promise<number> { - const server = net.createServer(); - await new Promise<void>((resolve, reject) => { - server.once("error", reject); - server.listen(0, "127.0.0.1", resolve); - }); - const address = server.address(); - if (!address || typeof address === "string") - throw Error("could not reserve a TCP port"); - await new Promise<void>((resolve, reject) => - server.close((error) => (error ? reject(error) : resolve())), - ); - return address.port; -} - -async function waitForBuild(url: string, timeoutMs = 90_000): Promise<void> { - const deadline = Date.now() + timeoutMs; - while (Date.now() < deadline) { - try { - const status = await new Promise<number | undefined>( - (resolve, reject) => { - const request = http.get(url, (response) => { - response.resume(); - resolve(response.statusCode); - }); - request.once("error", reject); - }, - ); - if (status && status >= 200 && status < 300) return; - } catch { - // The build server is not listening yet. - } - await new Promise((resolve) => setTimeout(resolve, 250)); - } - throw Error("wallet-webui extension build did not become ready"); -} - async function screenshot( driver: FirefoxDriver, directory: string, @@ -128,7 +91,11 @@ export async function runWalletWebUiFirefoxExtensionWithdrawalTest( [path.join(walletWebUiDirectory, "test-server.mjs"), `--port=${buildPort}`], "wallet-webui-build", ); - await waitForBuild(`http://127.0.0.1:${buildPort}/`); + await waitForWalletWebUi( + `http://127.0.0.1:${buildPort}/`, + 90_000, + "extension build", + ); const extensionDirectory = walletWebUiArtifactPath( walletWebUiDirectory, diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-peer-tos.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-peer-tos.ts @@ -7,8 +7,6 @@ Foundation; either version 3, or (at your option) any later version. */ -import fs from "node:fs"; -import path from "node:path"; import { AbsoluteTime, Duration, @@ -17,9 +15,11 @@ import { TransactionType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import fs from "node:fs"; +import path from "node:path"; import { createSimpleTestkudosEnvironmentV3, - withdrawViaBankV3, + withdrawViaBankV4, } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; import { Stage } from "../stagefright/stage.js"; @@ -39,7 +39,7 @@ export async function runWalletWebUiPwaPeerTosTest(t: GlobalTestState) { path.join(englishTermsDirectory, "v1.txt"), "Local exchange terms for the wallet-webui peer request test.\n", ); - const { exchange, walletClient, bankClient } = + const { bank, exchange, walletClient } = await createSimpleTestkudosEnvironmentV3(t, undefined, { additionalExchangeConfig: (localExchange) => { localExchange.changeConfig((config) => { @@ -54,9 +54,9 @@ export async function runWalletWebUiPwaPeerTosTest(t: GlobalTestState) { await walletClient.call(WalletApiOperation.SetExchangeTosAccepted, { exchangeBaseUrl: exchange.baseUrl, }); - const senderWithdrawal = await withdrawViaBankV3(t, { + const senderWithdrawal = await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:10", }); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-sqlite.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-sqlite.ts @@ -7,16 +7,14 @@ Foundation; either version 3, or (at your option) any later version. */ -import assert from "node:assert"; -import fs from "node:fs"; -import http from "node:http"; -import net from "node:net"; -import path from "node:path"; -import type { Page } from "playwright-core"; import { TALER_WALLET_MAIN_DB_NAME, TALER_WALLET_META_DB_NAME, } from "@gnu-taler/taler-wallet-core"; +import assert from "node:assert"; +import fs from "node:fs"; +import path from "node:path"; +import type { Page } from "playwright-core"; import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState } from "../harness/harness.js"; import { Stage } from "../stagefright/stage.js"; @@ -24,6 +22,8 @@ import { WebDriverStage } from "../stagefright/webdriver-stage.js"; import { findWalletWebUiDirectory, walletWebUiArtifactPath, + reserveTcpPort, + waitForPwa, } from "./wallet-web-ui-test-support.js"; async function createPwaStage( @@ -35,46 +35,6 @@ async function createPwaStage( : Stage.create(scenarioName, options); } -async function reserveTcpPort(): Promise<number> { - const server = net.createServer(); - await new Promise<void>((resolve, reject) => { - server.once("error", reject); - server.listen(0, "127.0.0.1", resolve); - }); - const address = server.address(); - if (!address || typeof address === "string") { - throw Error("could not reserve a TCP port"); - } - await new Promise<void>((resolve, reject) => - server.close((error) => (error ? reject(error) : resolve())), - ); - return address.port; -} - -async function waitForPwa(url: string, timeoutMs = 90_000): Promise<void> { - const deadline = Date.now() + timeoutMs; - let lastError: unknown; - while (Date.now() < deadline) { - try { - const status = await new Promise<number | undefined>( - (resolve, reject) => { - const request = http.get(url, (response) => { - response.resume(); - resolve(response.statusCode); - }); - request.once("error", reject); - }, - ); - if (status && status >= 200 && status < 300) return; - lastError = Error(`HTTP ${status ?? "unknown"}`); - } catch (cause) { - lastError = cause; - } - await new Promise((resolve) => setTimeout(resolve, 250)); - } - throw Error(`wallet-webui PWA did not become ready: ${lastError}`); -} - async function injectInterruptedStorageState(page: Page): Promise<void> { await page.evaluate(async () => { const browser = globalThis as any; diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts @@ -14,10 +14,6 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import fs from "node:fs"; -import http from "node:http"; -import net from "node:net"; -import path from "node:path"; import { AbsoluteTime, Duration, @@ -32,8 +28,10 @@ import { TemplateType, TokenFamilyKind, } from "@gnu-taler/taler-util"; -import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; +import fs from "node:fs"; +import path from "node:path"; import { defaultCoinConfig } from "../harness/denomStructures.js"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { ExchangeService, GlobalTestState, @@ -45,47 +43,10 @@ import { acknowledgeBestEffortStorageForTest, findWalletWebUiDirectory, startCorsBridge, + reserveTcpPort, + waitForPwa, } from "./wallet-web-ui-test-support.js"; -async function reserveTcpPort(): Promise<number> { - const server = net.createServer(); - await new Promise<void>((resolve, reject) => { - server.once("error", reject); - server.listen(0, "127.0.0.1", resolve); - }); - const address = server.address(); - if (!address || typeof address === "string") - throw Error("could not reserve a TCP port"); - await new Promise<void>((resolve, reject) => - server.close((error) => (error ? reject(error) : resolve())), - ); - return address.port; -} - -async function waitForPwa(url: string, timeoutMs = 90_000): Promise<void> { - const deadline = Date.now() + timeoutMs; - let lastError: unknown; - while (Date.now() < deadline) { - try { - const status = await new Promise<number | undefined>( - (resolve, reject) => { - const request = http.get(url, (response) => { - response.resume(); - resolve(response.statusCode); - }); - request.once("error", reject); - }, - ); - if (status && status >= 200 && status < 300) return; - lastError = Error(`HTTP ${status ?? "unknown"}`); - } catch (cause) { - lastError = cause; - } - await new Promise((resolve) => setTimeout(resolve, 250)); - } - throw Error(`wallet-webui PWA did not become ready: ${lastError}`); -} - function withdrawExchangeUri(baseUrl: string, amount?: string): string { const exchangeUrl = new URL(baseUrl); const talerScheme = exchangeUrl.protocol === "http:" ? "taler+http" : "taler"; diff --git a/packages/taler-harness/src/integrationtests/test-wallet-wirefees.ts b/packages/taler-harness/src/integrationtests/test-wallet-wirefees.ts @@ -18,30 +18,19 @@ * Imports. */ import { - BasicAuth, ChoiceSelectionDetailType, - Duration, succeedOrThrow, - TalerCorebankApiClient, TalerMerchantApi, TalerMerchantInstanceHttpClient, TransactionMajorState, TransactionMinorState, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; -import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { - createWalletDaemonWithClient, - withdrawViaBankV3, + createSimpleTestkudosEnvironmentV3, + withdrawViaBankV4, } from "../harness/environments.js"; -import { - BankService, - ExchangeService, - getTestHarnessPaytoForLabel, - GlobalTestState, - MerchantService, - setupDb, -} from "../harness/harness.js"; +import { GlobalTestState } from "../harness/harness.js"; /** * Test payment where the exchange charges wire fees. @@ -49,115 +38,16 @@ import { export async function runWalletWirefeesTest(t: GlobalTestState) { // Set up test environment - const db = await setupDb(t); - - const bank = await BankService.create(t, { - allowRegistrations: true, - currency: "TESTKUDOS", - database: db.connStr, - httpPort: 8082, - }); - - const exchange = ExchangeService.create(t, { - name: "testexchange-1", - currency: "TESTKUDOS", - httpPort: 8081, - database: db.connStr, - // Ridiculously high wire fees! - overrideWireFee: "TESTKUDOS:5", - }); - - const merchant = await MerchantService.create(t, { - name: "testmerchant-1", - httpPort: 8083, - database: db.connStr, - }); - - let receiverName = "Exchange"; - let exchangeBankUsername = "exchange"; - let exchangeBankPassword = "mypw-password"; - let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayAuth: BasicAuth = { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }; - - await exchange.addBankAccount("1", { - wireGatewayAuth, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, - accountPaytoUri: exchangePaytoUri, - }); - - bank.setSuggestedExchange(exchange, exchangePaytoUri); - - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); - - const coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")); - exchange.addCoinConfigList(coinConfig); - - await exchange.start(); - await exchange.pingUntilAvailable(); - - merchant.addExchange(exchange); - - await merchant.start(); - await merchant.pingUntilAvailable(); - - const { accessToken: adminAccessToken } = - await merchant.addInstanceWithWireAccount({ - id: "admin", - name: "Default Instance", - paytoUris: [getTestHarnessPaytoForLabel("merchant-default")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), + const { walletClient, bank, exchange, merchant, merchantAdminAccessToken } = + await createSimpleTestkudosEnvironmentV3(t, undefined, { + exchangeConfig: { overrideWireFee: "TESTKUDOS:5" }, }); - await merchant.addInstanceWithWireAccount( - { - id: "minst1", - name: "minst1", - paytoUris: [getTestHarnessPaytoForLabel("minst1")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), - }, - { adminAccessToken }, - ); - - const { walletClient } = await createWalletDaemonWithClient(t, { - name: "wallet", - persistent: true, - }); - const merchantAdminAccessToken = adminAccessToken; - console.log("setup done!"); - // Withdraw digital cash into the wallet. - await withdrawViaBankV3(t, { + await withdrawViaBankV4(t, { walletClient, - bankClient, + bank, exchange, amount: "TESTKUDOS:20", }); diff --git a/packages/taler-harness/src/integrationtests/test-wire-metadata.ts b/packages/taler-harness/src/integrationtests/test-wire-metadata.ts @@ -38,6 +38,7 @@ import { applyTimeTravelV2, createWalletDaemonWithClient, withdrawViaBankV4, + makeHarnessExchangeBankAccount, } from "../harness/environments.js"; import { BankService, @@ -76,20 +77,16 @@ export async function runWireMetadataTest(t: GlobalTestState) { const exchangeBankUsername = "exchange"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; - - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - accountPaytoUri: exchangePaytoUri, - }; + + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + }); exchange.addOfferedCoins(defaultCoinConfig); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-conversion.ts @@ -32,7 +32,11 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import * as http from "node:http"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, +} from "../harness/environments.js"; import { BankService, ExchangeService, @@ -154,19 +158,16 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { database: db.connStr, }); - let exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl: new URL( - "accounts/myexchange/taler-wire-gateway/", - bank.corebankApiBaseUrl, - ).href, - wireGatewayAuth: { - type: "basic", - username: "myexchange", - password: "password", - }, - accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), - conversionUrl: "http://localhost:8071/", - }; + let exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: "myexchange", + password: "password", + }, + accountPaytoUri: getTestHarnessPaytoForLabel("myexchange"), + conversionUrl: "http://localhost:8071/", + }); await exchange.addBankAccount("1", exchangeBankAccount); @@ -183,13 +184,7 @@ export async function runWithdrawalConversionTest(t: GlobalTestState) { auth: bankClientAuth, }); - await bankClient.registerAccountExtended({ - name: exchangeBankAccount.wireGatewayAuth.username, - username: exchangeBankAccount.wireGatewayAuth.username, - password: exchangeBankAccount.wireGatewayAuth.password, - is_taler_exchange: true, - payto_uri: exchangeBankAccount.accountPaytoUri, - }); + await registerHarnessExchangeBankAccount(bankClient, exchangeBankAccount); exchange.addOfferedCoins(defaultCoinConfig); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fakebank.ts @@ -17,9 +17,10 @@ /** * Imports. */ -import { AmountString, PaytoString, URL } from "@gnu-taler/taler-util"; +import { AmountString, PaytoString } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; +import { makeHarnessExchangeBankAccount } from "../harness/environments.js"; import { ExchangeService, FakebankService, @@ -51,19 +52,16 @@ export async function runWithdrawalFakebankTest(t: GlobalTestState) { database: db.connStr, }); - exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: "exchange", password: "password", }, - wireGatewayApiBaseUrl: new URL( - "/accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: "payto://x-taler-bank/localhost/exchange?receiver-name=Exchange" as PaytoString, }); + await exchange.addBankAccount("1", exchangeBankAccount); await bank.createExchangeAccount("exchange", "password"); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-fees.ts @@ -18,7 +18,6 @@ * Imports. */ import { - TalerCorebankApiClient, TransactionMajorState, TransactionMinorState, j2s, @@ -26,6 +25,11 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig } from "../harness/denomStructures.js"; import { + makeHarnessExchangeBankAccount, + registerHarnessExchangeBankAccount, + startHarnessBank, +} from "../harness/environments.js"; +import { BankService, ExchangeService, GlobalTestState, @@ -92,39 +96,25 @@ export async function runWithdrawalFeesTest(t: GlobalTestState) { let exchangeBankPassword = "mypw-password"; let exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: exchangeBankUsername, password: exchangeBankPassword, }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: exchangePaytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, exchangePaytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); + const bankClient = await startHarnessBank(bank); - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); - - await bankClient.registerAccountExtended({ - name: receiverName, - password: exchangeBankPassword, - username: exchangeBankUsername, - is_taler_exchange: true, - payto_uri: exchangePaytoUri, - }); + await registerHarnessExchangeBankAccount( + bankClient, + exchangeBankAccount, + receiverName, + ); const coinConfig: CoinConfig[] = weirdCoinConfig.map((x) => x("TESTKUDOS")); exchange.addCoinConfigList(coinConfig); diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-huge.ts @@ -21,13 +21,15 @@ import { AmountString, NotificationType, PaytoString, - TalerCorebankApiClient, TransactionMajorState, - URL, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { + makeHarnessExchangeBankAccount, + startHarnessBank, +} from "../harness/environments.js"; +import { BankService, ExchangeService, getTestHarnessPaytoForLabel, @@ -65,31 +67,19 @@ export async function runWithdrawalHugeTest(t: GlobalTestState) { const paytoUri = getTestHarnessPaytoForLabel("exchange") as PaytoString; - await exchange.addBankAccount("1", { - wireGatewayAuth: { + const exchangeBankAccount = makeHarnessExchangeBankAccount(bank, { + auth: { type: "basic", username: "exchange", password: "password", }, - wireGatewayApiBaseUrl: new URL( - "accounts/exchange/taler-wire-gateway/", - bank.baseUrl, - ).href, accountPaytoUri: paytoUri, }); + await exchange.addBankAccount("1", exchangeBankAccount); bank.setSuggestedExchange(exchange, paytoUri); - await bank.start(); - - await bank.pingUntilAvailable(); - - const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, { - auth: { - username: "admin", - password: "admin-password", - }, - }); + const bankClient = await startHarnessBank(bank); await bankClient.registerAccountExtended({ name: "Exchange", diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-idempotent.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-idempotent.ts @@ -42,7 +42,7 @@ import { ReserveKeypair, topupReserveWithBank, } from "@gnu-taler/taler-wallet-core/dbless"; -import { createSimpleTestkudosEnvironmentV2 } from "../harness/environments.js"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/environments.js"; import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; /** @@ -51,7 +51,7 @@ import { GlobalTestState, harnessHttpLib } from "../harness/harness.js"; export async function runWithdrawalIdempotentTest(t: GlobalTestState) { // Set up test environment - const { bank, exchange } = await createSimpleTestkudosEnvironmentV2(t); + const { bank, exchange } = await createSimpleTestkudosEnvironmentV3(t); const http = harnessHttpLib; const cryptiDisp = new CryptoDispatcher( diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-shorten.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-shorten.ts @@ -26,7 +26,10 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { defaultCoinConfig } from "../harness/denomStructures.js"; -import { createWalletDaemonWithClient } from "../harness/environments.js"; +import { + createWalletDaemonWithClient, + makeHarnessExchangeBankAccount, +} from "../harness/environments.js"; import { BankService, ExchangeService, @@ -62,23 +65,19 @@ export async function runWithdrawalShortenTest(t: GlobalTestState) { const exchangeBankUsername = "exchange"; const exchangeBankPassword = "mypw-password"; const exchangePaytoUri = getTestHarnessPaytoForLabel(exchangeBankUsername); - const wireGatewayApiBaseUrl = new URL( - `accounts/${exchangeBankUsername}/taler-wire-gateway/`, - bank.corebankApiBaseUrl, - ).href; const prepBaseUrl = bank.corebankApiBaseUrl + "/taler-prepared-transfer/"; - const exchangeBankAccount: HarnessExchangeBankAccount = { - wireGatewayApiBaseUrl, - wireGatewayAuth: { - type: "basic", - username: exchangeBankUsername, - password: exchangeBankPassword, - }, - accountPaytoUri: exchangePaytoUri, - preparedTransferUrl: prepBaseUrl, - }; + const exchangeBankAccount: HarnessExchangeBankAccount = + makeHarnessExchangeBankAccount(bank, { + auth: { + type: "basic", + username: exchangeBankUsername, + password: exchangeBankPassword, + }, + accountPaytoUri: exchangePaytoUri, + preparedTransferUrl: prepBaseUrl, + }); bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); diff --git a/packages/taler-harness/src/integrationtests/wallet-web-ui-test-support.ts b/packages/taler-harness/src/integrationtests/wallet-web-ui-test-support.ts @@ -7,8 +7,8 @@ Foundation; either version 3, or (at your option) any later version. */ -import fs from "node:fs"; import { execFileSync } from "node:child_process"; +import fs from "node:fs"; import http from "node:http"; import net from "node:net"; import path from "node:path"; @@ -93,6 +93,14 @@ export async function waitForPwa( url: string, timeoutMs = 90_000, ): Promise<void> { + return waitForWalletWebUi(url, timeoutMs, "PWA"); +} + +export async function waitForWalletWebUi( + url: string, + timeoutMs = 90_000, + description = "PWA", +): Promise<void> { const deadline = Date.now() + timeoutMs; let lastError: unknown; while (Date.now() < deadline) { @@ -113,7 +121,7 @@ export async function waitForPwa( } await delayMs(250); } - throw Error(`wallet-webui PWA did not become ready: ${lastError}`); + throw Error(`wallet-webui ${description} did not become ready: ${lastError}`); } /** Add browser CORS responses in front of a local harness daemon. */