commit ace105ad7de1ccdd93941c608925c3725b8240de
parent 5d3e7450d3b80b5e30e1a4febabab92e5b4a19e6
Author: Florian Dold <florian@dold.me>
Date: Thu, 12 Dec 2024 19:56:16 +0100
harness: test peer-push-debit abort
Diffstat:
4 files changed, 139 insertions(+), 2 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-peer-push-abort.ts b/packages/taler-harness/src/integrationtests/test-peer-push-abort.ts
@@ -0,0 +1,92 @@
+/*
+ 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 {
+ AbsoluteTime,
+ Duration,
+ TransactionMajorState,
+ TransactionMinorState,
+} from "@gnu-taler/taler-util";
+import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
+import {
+ createSimpleTestkudosEnvironmentV3,
+ withdrawViaBankV2,
+} from "../harness/environments.js";
+import { GlobalTestState } from "../harness/harness.js";
+
+/**
+ * Run a test for aborting peer-push payments.
+ */
+export async function runPeerPushAbortTest(t: GlobalTestState) {
+ const { bank, bankClient, exchange, walletClient } =
+ await createSimpleTestkudosEnvironmentV3(t);
+
+ const wres = await withdrawViaBankV2(t, {
+ walletClient,
+ bank,
+ exchange,
+ amount: "TESTKUDOS:20",
+ });
+
+ await wres.withdrawalFinishedCond;
+
+ const purse_expiration = AbsoluteTime.toProtocolTimestamp(
+ AbsoluteTime.addDuration(
+ AbsoluteTime.now(),
+ Duration.fromSpec({ days: 2 }),
+ ),
+ );
+
+ const pdi = await walletClient.call(
+ WalletApiOperation.InitiatePeerPushDebit,
+ {
+ partialContractTerms: {
+ amount: "TESTKUDOS:7",
+ summary: "Hi!",
+ purse_expiration,
+ },
+ },
+ );
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: pdi.transactionId,
+ txState: {
+ major: TransactionMajorState.Pending,
+ minor: TransactionMinorState.Ready,
+ },
+ });
+
+ await walletClient.call(WalletApiOperation.AbortTransaction, {
+ transactionId: pdi.transactionId,
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: pdi.transactionId,
+ txState: {
+ major: TransactionMajorState.Aborted,
+ },
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitRefreshesFinal, {});
+
+ const bal = await walletClient.call(WalletApiOperation.GetBalances, {});
+ t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:18.88");
+}
+
+runPeerPushAbortTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh-errors.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh-errors.ts
@@ -20,11 +20,11 @@
import { AmountString } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { CoinConfig } from "../harness/denomStructures.js";
-import { GlobalTestState } from "../harness/harness.js";
import {
createSimpleTestkudosEnvironmentV2,
withdrawViaBankV2,
} from "../harness/environments.js";
+import { GlobalTestState } from "../harness/harness.js";
const coinCommon = {
cipher: "RSA" as const,
@@ -102,6 +102,46 @@ export async function runWalletRefreshErrorsTest(t: GlobalTestState) {
});
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
+
+ // Now reset everything and do more tests
+
+ await walletClient.call(WalletApiOperation.ClearDb, {});
+ {
+ const wres = await withdrawViaBankV2(t, {
+ amount: "TESTKUDOS:5",
+ bank,
+ exchange,
+ walletClient,
+ });
+ await wres.withdrawalFinishedCond;
+
+ const coinDump = await walletClient.call(WalletApiOperation.DumpCoins, {});
+
+ t.assertDeepEqual(coinDump.coins[0].denomValue, "TESTKUDOS:5");
+
+ await walletClient.call(WalletApiOperation.ForceRefresh, {
+ refreshCoinSpecs: [
+ {
+ coinPub: coinDump.coins[0].coinPub,
+ amount: "TESTKUDOS:5" as AmountString,
+ },
+ ],
+ });
+ // Do it twice!
+ await walletClient.call(WalletApiOperation.ForceRefresh, {
+ refreshCoinSpecs: [
+ {
+ coinPub: coinDump.coins[0].coinPub,
+ amount: "TESTKUDOS:5" as AmountString,
+ },
+ ],
+ });
+
+ await walletClient.call(
+ WalletApiOperation.TestingWaitTransactionsFinal,
+ {},
+ );
+ }
}
runWalletRefreshErrorsTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts b/packages/taler-harness/src/integrationtests/test-wallet-refresh.ts
@@ -30,12 +30,15 @@ import {
WalletApiOperation,
parseTransactionIdentifier,
} from "@gnu-taler/taler-wallet-core";
-import { GlobalTestState, getTestHarnessPaytoForLabel } from "../harness/harness.js";
import {
createSimpleTestkudosEnvironmentV3,
makeTestPaymentV2,
withdrawViaBankV3,
} from "../harness/environments.js";
+import {
+ GlobalTestState,
+ getTestHarnessPaytoForLabel,
+} from "../harness/harness.js";
/**
* Run test for refreshe after a payment.
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -97,6 +97,7 @@ import { runPaymentZeroTest } from "./test-payment-zero.js";
import { runPaymentTest } from "./test-payment.js";
import { runPaywallFlowTest } from "./test-paywall-flow.js";
import { runPeerPullLargeTest } from "./test-peer-pull-large.js";
+import { runPeerPushAbortTest } from "./test-peer-push-abort.js";
import { runPeerPushLargeTest } from "./test-peer-push-large.js";
import { runPeerRepairTest } from "./test-peer-repair.js";
import { runPeerToPeerPullTest } from "./test-peer-to-peer-pull.js";
@@ -294,6 +295,7 @@ const allTests: TestMainFunction[] = [
runKycDepositAggregateImplicitAuthTest,
runKycAmpTimeoutTest,
runKycAmpFailureTest,
+ runPeerPushAbortTest,
];
export interface TestRunSpec {