diff options
author | Florian Dold <florian@dold.me> | 2023-09-05 10:46:06 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-09-05 10:48:41 +0200 |
commit | a60a1d867cfe6a12f1e6fadfa037f022e9385107 (patch) | |
tree | bc77a92b327cd0e4933fa4b3fe15f1c775e24235 /packages/taler-harness/src/harness/helpers.ts | |
parent | e1d86816a7c07cb8ca2d54676d5cdbbe513f2ba7 (diff) | |
download | wallet-core-a60a1d867cfe6a12f1e6fadfa037f022e9385107.tar.xz |
harness: remove deprecated testing APIs
Diffstat (limited to 'packages/taler-harness/src/harness/helpers.ts')
-rw-r--r-- | packages/taler-harness/src/harness/helpers.ts | 326 |
1 files changed, 35 insertions, 291 deletions
diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index d1d0ea104..39d411a46 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -53,6 +53,7 @@ import { FakebankService, getPayto, GlobalTestState, + MerchantApiClient, MerchantPrivateApi, MerchantService, MerchantServiceInterface, @@ -107,114 +108,6 @@ 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. - * - * @deprecated use {@link createSimpleTestkudosEnvironmentV2} instead - */ -export async function createSimpleTestkudosEnvironment( - t: GlobalTestState, - coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")), - opts: EnvOptions = {}, -): Promise<SimpleTestEnvironment> { - 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, - }); - - const merchant = await MerchantService.create(t, { - name: "testmerchant-1", - currency: "TESTKUDOS", - httpPort: 8083, - database: db.connStr, - }); - - const exchangeBankAccount = await bank.createExchangeAccount( - "myexchange", - "x", - ); - await exchange.addBankAccount("1", exchangeBankAccount); - - bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); - - await bank.start(); - - await bank.pingUntilAvailable(); - - 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); - } - - await exchange.start(); - await exchange.pingUntilAvailable(); - - merchant.addExchange(exchange); - - await merchant.start(); - await merchant.pingUntilAvailable(); - - await merchant.addInstance({ - id: "default", - name: "Default Instance", - paytoUris: [getPayto("merchant-default")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), - }); - - await merchant.addInstance({ - id: "minst1", - name: "minst1", - paytoUris: [getPayto("minst1")], - defaultWireTransferDelay: Duration.toTalerProtocolDuration( - Duration.fromSpec({ minutes: 1 }), - ), - }); - - console.log("setup done!"); - - const wallet = new WalletCli(t); - - return { - commonDb: db, - exchange, - merchant, - wallet, - bank, - exchangeBankAccount, - }; -} - export function getSharedTestDir(): string { return `/tmp/taler-harness@${process.env.USER}`; } @@ -344,7 +237,7 @@ export async function useSharedTestkudosEnvironment(t: GlobalTestState) { await merchant.pingUntilAvailable(); if (!prevSetupDone) { - await merchant.addInstance({ + await merchant.addInstanceWithWireAccount({ id: "default", name: "Default Instance", paytoUris: [getPayto("merchant-default")], @@ -353,7 +246,7 @@ export async function useSharedTestkudosEnvironment(t: GlobalTestState) { ), }); - await merchant.addInstance({ + await merchant.addInstanceWithWireAccount({ id: "minst1", name: "minst1", paytoUris: [getPayto("minst1")], @@ -476,7 +369,7 @@ export async function createSimpleTestkudosEnvironmentV2( await merchant.start(); await merchant.pingUntilAvailable(); - await merchant.addInstance({ + await merchant.addInstanceWithWireAccount({ id: "default", name: "Default Instance", paytoUris: [getPayto("merchant-default")], @@ -485,7 +378,7 @@ export async function createSimpleTestkudosEnvironmentV2( ), }); - await merchant.addInstance({ + await merchant.addInstanceWithWireAccount({ id: "minst1", name: "minst1", paytoUris: [getPayto("minst1")], @@ -554,7 +447,7 @@ export interface FaultyMerchantTestEnvironment { exchangeBankAccount: HarnessExchangeBankAccount; merchant: MerchantService; faultyMerchant: FaultInjectedMerchantService; - wallet: WalletCli; + walletClient: WalletClient; } /** @@ -620,13 +513,13 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( await merchant.start(); await merchant.pingUntilAvailable(); - await merchant.addInstance({ + await merchant.addInstanceWithWireAccount({ id: "default", name: "Default Instance", paytoUris: [getPayto("merchant-default")], }); - await merchant.addInstance({ + await merchant.addInstanceWithWireAccount({ id: "minst1", name: "minst1", paytoUris: [getPayto("minst1")], @@ -634,13 +527,15 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( console.log("setup done!"); - const wallet = new WalletCli(t); + const { walletClient } = await createWalletDaemonWithClient(t, { + name: "default", + }); return { commonDb: db, exchange, merchant, - wallet, + walletClient, bank, exchangeBankAccount, faultyMerchant, @@ -648,51 +543,6 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( }; } -/** - * Start withdrawing into the wallet. - * - * Only starts the operation, does not wait for it to finish. - */ -export async function startWithdrawViaBank( - t: GlobalTestState, - p: { - wallet: WalletCli; - bank: BankService; - exchange: ExchangeServiceInterface; - amount: AmountString; - restrictAge?: number; - }, -): Promise<void> { - const { wallet, bank, exchange, amount } = p; - - const user = await BankApi.createRandomBankUser(bank); - const wop = await BankAccessApi.createWithdrawalOperation(bank, user, amount); - - // Hand it to the wallet - - await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, { - talerWithdrawUri: wop.taler_withdraw_uri, - restrictAge: p.restrictAge, - }); - - await wallet.runPending(); - - // Withdraw (AKA select) - - await wallet.client.call(WalletApiOperation.AcceptBankIntegratedWithdrawal, { - exchangeBaseUrl: exchange.baseUrl, - talerWithdrawUri: wop.taler_withdraw_uri, - restrictAge: p.restrictAge, - }); - - // Confirm it - - await BankApi.confirmWithdrawalOperation(bank, user, wop); - - // We do *not* call runPending / runUntilDone on the wallet here. - // Some tests rely on the final withdraw failing. -} - export interface WithdrawViaBankResult { withdrawalFinishedCond: Promise<true>; } @@ -751,133 +601,37 @@ export async function withdrawViaBankV2( }; } -/** - * Withdraw balance. - * - * @deprecated use {@link withdrawViaBankV2 instead} - */ -export async function withdrawViaBank( - t: GlobalTestState, - p: { - wallet: WalletCli; - bank: BankService; - exchange: ExchangeServiceInterface; - amount: AmountString; - restrictAge?: number; - }, -): Promise<void> { - const { wallet } = p; - - await startWithdrawViaBank(t, p); - - await wallet.runUntilDone(); - - // Check balance - - await wallet.client.call(WalletApiOperation.GetBalances, {}); -} - -export async function applyTimeTravel( - timetravelDuration: Duration, +export async function applyTimeTravelV2( + timetravelOffsetMs: number, s: { exchange?: ExchangeService; merchant?: MerchantService; - wallet?: WalletCli; + walletClient?: WalletClient; }, ): Promise<void> { if (s.exchange) { await s.exchange.stop(); - s.exchange.setTimetravel(timetravelDuration); + s.exchange.setTimetravel(timetravelOffsetMs); await s.exchange.start(); await s.exchange.pingUntilAvailable(); } if (s.merchant) { await s.merchant.stop(); - s.merchant.setTimetravel(timetravelDuration); + s.merchant.setTimetravel(timetravelOffsetMs); await s.merchant.start(); await s.merchant.pingUntilAvailable(); } - if (s.wallet) { - s.wallet.setTimetravel(timetravelDuration); + if (s.walletClient) { + s.walletClient.call(WalletApiOperation.TestingSetTimetravel, { + offsetMs: timetravelOffsetMs, + }); } } /** * Make a simple payment and check that it succeeded. - * - * @deprecated - */ -export async function makeTestPayment( - t: GlobalTestState, - args: { - merchant: MerchantServiceInterface; - wallet: WalletCli; - order: Partial<MerchantContractTerms>; - instance?: string; - }, - auth: WithAuthorization = {}, -): Promise<void> { - // Set up order. - - const { wallet, merchant } = args; - const instance = args.instance ?? "default"; - - const orderResp = await MerchantPrivateApi.createOrder( - merchant, - instance, - { - order: args.order, - }, - auth, - ); - - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - }, - auth, - ); - - t.assertTrue(orderStatus.order_status === "unpaid"); - - // Make wallet pay for the order - - const preparePayResult = await wallet.client.call( - WalletApiOperation.PreparePayForUri, - { - talerPayUri: orderStatus.taler_pay_uri, - }, - ); - - t.assertTrue( - preparePayResult.status === PreparePayResultType.PaymentPossible, - ); - - const r2 = await wallet.client.call(WalletApiOperation.ConfirmPay, { - proposalId: preparePayResult.proposalId, - }); - - t.assertTrue(r2.type === ConfirmPayResultType.Done); - - // Check if payment was successful. - - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - instance, - }, - auth, - ); - - t.assertTrue(orderStatus.order_status === "paid"); -} - -/** - * Make a simple payment and check that it succeeded. */ export async function makeTestPaymentV2( t: GlobalTestState, @@ -891,25 +645,19 @@ export async function makeTestPaymentV2( ): Promise<void> { // Set up order. - const { walletClient, merchant } = args; - const instance = args.instance ?? "default"; + const { walletClient, merchant, instance } = args; - const orderResp = await MerchantPrivateApi.createOrder( - merchant, - instance, - { - order: args.order, - }, - auth, + const merchantClient = new MerchantApiClient( + merchant.makeInstanceBaseUrl(instance), ); - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - }, - auth, - ); + const orderResp = await merchantClient.createOrder({ + order: args.order, + }); + + let orderStatus = await merchantClient.queryPrivateOrderStatus({ + orderId: orderResp.order_id, + }); t.assertTrue(orderStatus.order_status === "unpaid"); @@ -934,14 +682,10 @@ export async function makeTestPaymentV2( // Check if payment was successful. - orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( - merchant, - { - orderId: orderResp.order_id, - instance, - }, - auth, - ); + orderStatus = await merchantClient.queryPrivateOrderStatus({ + orderId: orderResp.order_id, + instance, + }); t.assertTrue(orderStatus.order_status === "paid"); } |