diff options
author | Florian Dold <florian@dold.me> | 2021-01-13 01:19:23 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-01-13 01:19:23 +0100 |
commit | 94e35ca70a53df81e513ca068eb71fd28a239c18 (patch) | |
tree | c6ac9122f4c9d058969672884d8a600dde4e4663 /packages | |
parent | 096d21189c39a410935c63f1af0e4dd8cd7d4582 (diff) | |
download | wallet-core-94e35ca70a53df81e513ca068eb71fd28a239c18.tar.xz |
fix pay-abort integration test
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-wallet-cli/src/integrationtests/helpers.ts | 9 | ||||
-rw-r--r-- | packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts | 130 |
2 files changed, 45 insertions, 94 deletions
diff --git a/packages/taler-wallet-cli/src/integrationtests/helpers.ts b/packages/taler-wallet-cli/src/integrationtests/helpers.ts index f4e676b61..c51c306c9 100644 --- a/packages/taler-wallet-cli/src/integrationtests/helpers.ts +++ b/packages/taler-wallet-cli/src/integrationtests/helpers.ts @@ -45,7 +45,7 @@ import { ConfirmPayResultType, ContractTerms, } from "taler-wallet-core"; -import { FaultInjectedMerchantService } from "./faultInjection"; +import { FaultInjectedExchangeService, FaultInjectedMerchantService } from "./faultInjection"; import { defaultCoinConfig } from "./denomStructures"; export interface SimpleTestEnvironment { @@ -139,6 +139,7 @@ export interface FaultyMerchantTestEnvironment { commonDb: DbInfo; bank: BankService; exchange: ExchangeService; + faultyExchange: FaultInjectedExchangeService, exchangeBankAccount: ExchangeBankAccount; merchant: MerchantService; faultyMerchant: FaultInjectedMerchantService; @@ -176,6 +177,7 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( }); const faultyMerchant = new FaultInjectedMerchantService(t, merchant, 9083); + const faultyExchange = new FaultInjectedExchangeService(t, exchange, 9081); const exchangeBankAccount = await bank.createExchangeAccount( "MyExchange", @@ -183,7 +185,7 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( ); exchange.addBankAccount("1", exchangeBankAccount); - bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); + bank.setSuggestedExchange(faultyExchange, exchangeBankAccount.accountPaytoUri); await bank.start(); @@ -194,7 +196,7 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( await exchange.start(); await exchange.pingUntilAvailable(); - merchant.addExchange(exchange); + merchant.addExchange(faultyExchange); await merchant.start(); await merchant.pingUntilAvailable(); @@ -223,6 +225,7 @@ export async function createFaultInjectedMerchantTestkudosEnvironment( bank, exchangeBankAccount, faultyMerchant, + faultyExchange, }; } diff --git a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts index 4fd6edc92..ae8a28b83 100644 --- a/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts +++ b/packages/taler-wallet-cli/src/integrationtests/test-pay-abort.ts @@ -22,89 +22,26 @@ /** * Imports. */ +import { PreparePayResultType, TalerErrorCode, URL } from "taler-wallet-core"; +import { FaultInjectionRequestContext, FaultInjectionResponseContext } from "./faultInjection"; +import { GlobalTestState, MerchantPrivateApi, setupDb } from "./harness"; import { - GlobalTestState, - MerchantService, - ExchangeService, - setupDb, - BankService, - WalletCli, - MerchantPrivateApi, -} from "./harness"; -import { - FaultInjectedExchangeService, - FaultInjectionRequestContext, - FaultInjectionResponseContext, -} from "./faultInjection"; -import { PreparePayResultType, URL, TalerErrorCode } from "taler-wallet-core"; -import { defaultCoinConfig } from "./denomStructures"; -import { withdrawViaBank, makeTestPayment } from "./helpers"; + createFaultInjectedMerchantTestkudosEnvironment, + withdrawViaBank, +} from "./helpers"; /** * Run test for basic, bank-integrated withdrawal. */ export async function runPayAbortTest(t: GlobalTestState) { + const { + bank, + faultyExchange, + wallet, + faultyMerchant, + } = await createFaultInjectedMerchantTestkudosEnvironment(t); // 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, - }); - - const exchangeBankAccount = await bank.createExchangeAccount( - "MyExchange", - "x", - ); - - bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri); - - await bank.start(); - - await bank.pingUntilAvailable(); - - await exchange.addBankAccount("1", exchangeBankAccount); - exchange.addOfferedCoins(defaultCoinConfig); - - await exchange.start(); - await exchange.pingUntilAvailable(); - - const faultyExchange = new FaultInjectedExchangeService(t, exchange, 8091); - - const merchant = await MerchantService.create(t, { - name: "testmerchant-1", - currency: "TESTKUDOS", - httpPort: 8083, - database: db.connStr, - }); - - merchant.addExchange(faultyExchange); - - await merchant.start(); - await merchant.pingUntilAvailable(); - - await merchant.addInstance({ - id: "default", - name: "Default Instance", - paytoUris: [`payto://x-taler-bank/merchant-default`], - }); - - console.log("setup done!"); - - const wallet = new WalletCli(t); - - // Create withdrawal operation - await withdrawViaBank(t, { wallet, exchange: faultyExchange, @@ -112,23 +49,24 @@ export async function runPayAbortTest(t: GlobalTestState) { bank, }); - // faultyExchange.faultProxy.addFault({ - // modifyRequest(ctx: FaultInjectionRequestContext) { - // console.log("proxy request to", ctx.requestUrl); - // } - // }); - - const orderResp = await MerchantPrivateApi.createOrder(merchant, "default", { - order: { - summary: "Buy me!", - amount: "TESTKUDOS:15", - fulfillment_url: "taler://fulfillment-success/thx", + const orderResp = await MerchantPrivateApi.createOrder( + faultyMerchant, + "default", + { + order: { + summary: "Buy me!", + amount: "TESTKUDOS:15", + fulfillment_url: "taler://fulfillment-success/thx", + }, }, - }); + ); - let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus(merchant, { - orderId: orderResp.order_id, - }); + let orderStatus = await MerchantPrivateApi.queryPrivateOrderStatus( + faultyMerchant, + { + orderId: orderResp.order_id, + }, + ); t.assertTrue(orderStatus.order_status === "unpaid"); @@ -168,6 +106,16 @@ export async function runPayAbortTest(t: GlobalTestState) { }, }); + faultyMerchant.faultProxy.addFault({ + modifyResponse(ctx: FaultInjectionResponseContext) { + const url = new URL(ctx.request.requestUrl); + if (url.pathname.endsWith("/pay") && url.href != firstDepositUrl) { + ctx.responseBody = Buffer.from("{}"); + ctx.statusCode = 400; + } + }, + }); + await t.assertThrowsOperationErrorAsync(async () => { await wallet.confirmPay({ proposalId: preparePayResult.proposalId, @@ -181,7 +129,7 @@ export async function runPayAbortTest(t: GlobalTestState) { t.assertDeepEqual(txr.transactions[1].pending, true); t.assertDeepEqual( txr.transactions[1].error?.code, - TalerErrorCode.WALLET_UNEXPECTED_REQUEST_ERROR, + TalerErrorCode.WALLET_RECEIVED_MALFORMED_RESPONSE, ); await wallet.abortFailedPayWithRefund({ |