aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-harness
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-01-15 19:38:34 +0100
committerFlorian Dold <florian@dold.me>2024-01-15 19:38:41 +0100
commitcc07d767abb0c1ba37be92014b06a94d3a3206d9 (patch)
treedbd037f08b4a438a3cc786778876b83762fc175e /packages/taler-harness
parent728bab6584ee5632def40f22103dc7578ec3d64c (diff)
downloadwallet-core-cc07d767abb0c1ba37be92014b06a94d3a3206d9.tar.xz
wallet-core: fix pay state machine when order is deleted
Diffstat (limited to 'packages/taler-harness')
-rw-r--r--packages/taler-harness/src/integrationtests/test-payment-deleted.ts106
-rw-r--r--packages/taler-harness/src/integrationtests/testrunner.ts2
2 files changed, 108 insertions, 0 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-payment-deleted.ts b/packages/taler-harness/src/integrationtests/test-payment-deleted.ts
new file mode 100644
index 000000000..3796c3e2b
--- /dev/null
+++ b/packages/taler-harness/src/integrationtests/test-payment-deleted.ts
@@ -0,0 +1,106 @@
+/*
+ This file is part of GNU Taler
+ (C) 2020 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+ * Imports.
+ */
+import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
+import { GlobalTestState } from "../harness/harness.js";
+import {
+ createSimpleTestkudosEnvironmentV2,
+ withdrawViaBankV2,
+ makeTestPaymentV2,
+} from "../harness/helpers.js";
+import {
+ ConfirmPayResultType,
+ MerchantApiClient,
+ PreparePayResultType,
+ TransactionMajorState,
+ j2s,
+} from "@gnu-taler/taler-util";
+
+/**
+ * Test behavior when an order is deleted while the wallet is paying for it.
+ */
+export async function runPaymentDeletedTest(t: GlobalTestState) {
+ // Set up test environment
+
+ const { walletClient, bank, exchange, merchant } =
+ await createSimpleTestkudosEnvironmentV2(t);
+
+ // First, make a "free" payment when we don't even have
+ // any money in the
+
+ // Withdraw digital cash into the wallet.
+ await withdrawViaBankV2(t, {
+ walletClient,
+ bank,
+ exchange,
+ amount: "TESTKUDOS:20",
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
+
+ const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
+
+ const orderResp = await merchantClient.createOrder({
+ order: {
+ summary: "Hello",
+ amount: "TESTKUDOS:2",
+ },
+ });
+
+ let orderStatus = await merchantClient.queryPrivateOrderStatus({
+ orderId: orderResp.order_id,
+ });
+
+ t.assertTrue(orderStatus.order_status === "unpaid");
+
+ // Make wallet pay for the order
+
+ const preparePayResult = await walletClient.call(
+ WalletApiOperation.PreparePayForUri,
+ {
+ talerPayUri: orderStatus.taler_pay_uri,
+ },
+ );
+
+ t.assertTrue(
+ preparePayResult.status === PreparePayResultType.PaymentPossible,
+ );
+
+ await merchantClient.deleteOrder({
+ orderId: orderResp.order_id,
+ force: true,
+ });
+
+ const r2 = await walletClient.call(WalletApiOperation.ConfirmPay, {
+ transactionId: preparePayResult.transactionId,
+ });
+
+ t.assertTrue(r2.type === ConfirmPayResultType.Pending);
+
+ await walletClient.call(WalletApiOperation.AbortTransaction, {
+ transactionId: preparePayResult.transactionId,
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
+
+ const bal = await walletClient.call(WalletApiOperation.GetBalances, {});
+ console.log(j2s(bal));
+}
+
+runPaymentDeletedTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
index b363e58a9..1d8353acf 100644
--- a/packages/taler-harness/src/integrationtests/testrunner.ts
+++ b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -96,6 +96,7 @@ import { runLibeufinBankTest } from "./test-libeufin-bank.js";
import { runMultiExchangeTest } from "./test-multiexchange.js";
import { runAgeRestrictionsDepositTest } from "./test-age-restrictions-deposit.js";
import { runWithdrawalConversionTest } from "./test-withdrawal-conversion.js";
+import { runPaymentDeletedTest } from "./test-payment-deleted.js";
/**
* Test runner.
@@ -181,6 +182,7 @@ const allTests: TestMainFunction[] = [
runPaymentExpiredTest,
runWalletGenDbTest,
runLibeufinBankTest,
+ runPaymentDeletedTest,
];
export interface TestRunSpec {