summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-04-30 13:23:23 +0200
committerFlorian Dold <florian@dold.me>2024-04-30 13:23:23 +0200
commit84adb1e78e49057cdcee15c71ad788f56bb0fff9 (patch)
treec8ab545301c61a03dd5759135f647070cc62c121
parent8b5d1276b9d9043e85cba91704c908ff544916e0 (diff)
downloadwallet-core-84adb1e78e49057cdcee15c71ad788f56bb0fff9.tar.gz
wallet-core-84adb1e78e49057cdcee15c71ad788f56bb0fff9.tar.bz2
wallet-core-84adb1e78e49057cdcee15c71ad788f56bb0fff9.zip
harness: test for withdrawal handover
-rw-r--r--packages/taler-harness/src/integrationtests/test-withdrawal-handover.ts191
-rw-r--r--packages/taler-harness/src/integrationtests/testrunner.ts2
-rw-r--r--packages/taler-util/src/wallet-types.ts5
-rw-r--r--packages/taler-wallet-core/src/wallet.ts1
-rw-r--r--packages/taler-wallet-core/src/withdraw.ts4
5 files changed, 194 insertions, 9 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-handover.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-handover.ts
new file mode 100644
index 000000000..23c0f938c
--- /dev/null
+++ b/packages/taler-harness/src/integrationtests/test-withdrawal-handover.ts
@@ -0,0 +1,191 @@
+/*
+ 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 {
+ TalerCorebankApiClient,
+ TransactionIdStr,
+ TransactionMajorState,
+ TransactionMinorState,
+ j2s,
+} from "@gnu-taler/taler-util";
+import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
+import { GlobalTestState } from "../harness/harness.js";
+import {
+ createSimpleTestkudosEnvironmentV2,
+ createWalletDaemonWithClient,
+} from "../harness/helpers.js";
+
+/**
+ * Test handing over a withdrawal to another wallet.
+ */
+export async function runWithdrawalHandoverTest(t: GlobalTestState) {
+ // Set up test environment
+
+ const { walletClient, bank, exchange } =
+ await createSimpleTestkudosEnvironmentV2(t);
+
+ // Do one normal withdrawal with the new split API
+ {
+ // Create a withdrawal operation
+
+ const bankAccessApiClient = new TalerCorebankApiClient(
+ bank.corebankApiBaseUrl,
+ );
+ const user = await bankAccessApiClient.createRandomBankUser();
+ bankAccessApiClient.setAuth(user);
+ const wop = await bankAccessApiClient.createWithdrawalOperation(
+ user.username,
+ "TESTKUDOS:10",
+ );
+
+ const checkResp = await walletClient.call(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ {
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ },
+ );
+
+ t.assertTrue(!!checkResp.defaultExchangeBaseUrl);
+
+ const prepareResp = await walletClient.call(
+ WalletApiOperation.PrepareBankIntegratedWithdrawal,
+ {
+ exchangeBaseUrl: checkResp.defaultExchangeBaseUrl,
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ },
+ );
+
+ console.log(`prepareResp: ${j2s(prepareResp)}`);
+
+ const txns1 = await walletClient.call(WalletApiOperation.GetTransactions, {
+ sort: "stable-ascending",
+ });
+ console.log(j2s(txns1));
+
+ await walletClient.call(WalletApiOperation.ConfirmWithdrawal, {
+ transactionId: prepareResp.transactionId,
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: prepareResp.transactionId as TransactionIdStr,
+ txState: {
+ major: TransactionMajorState.Pending,
+ minor: TransactionMinorState.BankConfirmTransfer,
+ },
+ });
+
+ await bankAccessApiClient.confirmWithdrawalOperation(user.username, {
+ withdrawalOperationId: wop.withdrawal_id,
+ });
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: prepareResp.transactionId as TransactionIdStr,
+ txState: {
+ major: TransactionMajorState.Done,
+ },
+ });
+ }
+
+ // Do one another withdrawal with handover.
+ {
+ t.logStep("start-subtest-handover");
+
+ const w2 = await createWalletDaemonWithClient(t, {
+ name: "w2",
+ });
+
+ // Create a withdrawal operation
+
+ const bankAccessApiClient = new TalerCorebankApiClient(
+ bank.corebankApiBaseUrl,
+ );
+ const user = await bankAccessApiClient.createRandomBankUser();
+ bankAccessApiClient.setAuth(user);
+ const wop = await bankAccessApiClient.createWithdrawalOperation(
+ user.username,
+ "TESTKUDOS:10",
+ );
+
+ const checkResp = await walletClient.call(
+ WalletApiOperation.GetWithdrawalDetailsForUri,
+ {
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ },
+ );
+
+ t.assertTrue(!!checkResp.defaultExchangeBaseUrl);
+
+ const prepareRespW1 = await walletClient.call(
+ WalletApiOperation.PrepareBankIntegratedWithdrawal,
+ {
+ exchangeBaseUrl: checkResp.defaultExchangeBaseUrl,
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ },
+ );
+
+ const prepareRespW2 = await w2.walletClient.call(
+ WalletApiOperation.PrepareBankIntegratedWithdrawal,
+ {
+ exchangeBaseUrl: checkResp.defaultExchangeBaseUrl,
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ },
+ );
+
+ await w2.walletClient.call(WalletApiOperation.ConfirmWithdrawal, {
+ transactionId: prepareRespW2.transactionId,
+ });
+
+ await w2.walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: prepareRespW2.transactionId as TransactionIdStr,
+ txState: {
+ major: TransactionMajorState.Pending,
+ minor: TransactionMinorState.BankConfirmTransfer,
+ },
+ });
+
+ await bankAccessApiClient.confirmWithdrawalOperation(user.username, {
+ withdrawalOperationId: wop.withdrawal_id,
+ });
+
+ console.log(`wopid is ${wop.withdrawal_id}`);
+
+ t.logStep("start-wait-w2-done");
+ await w2.walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: prepareRespW2.transactionId as TransactionIdStr,
+ txState: {
+ major: TransactionMajorState.Done,
+ },
+ });
+ t.logStep("done-wait-w2-done");
+
+ t.logStep("start-wait-w1-done");
+
+ await walletClient.call(WalletApiOperation.TestingWaitTransactionState, {
+ transactionId: prepareRespW1.transactionId as TransactionIdStr,
+ txState: {
+ major: TransactionMajorState.Aborted,
+ minor: TransactionMinorState.CompletedByOtherWallet,
+ },
+ });
+
+ t.logStep("done-wait-w1-done");
+ }
+}
+
+runWithdrawalHandoverTest.suites = ["wallet"];
diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts
index 2f6304773..4b23d7762 100644
--- a/packages/taler-harness/src/integrationtests/testrunner.ts
+++ b/packages/taler-harness/src/integrationtests/testrunner.ts
@@ -117,6 +117,7 @@ import { runWithdrawalBankIntegratedTest } from "./test-withdrawal-bank-integrat
import { runWithdrawalConversionTest } from "./test-withdrawal-conversion.js";
import { runWithdrawalFakebankTest } from "./test-withdrawal-fakebank.js";
import { runWithdrawalFeesTest } from "./test-withdrawal-fees.js";
+import { runWithdrawalHandoverTest } from "./test-withdrawal-handover.js";
import { runWithdrawalHugeTest } from "./test-withdrawal-huge.js";
import { runWithdrawalManualTest } from "./test-withdrawal-manual.js";
@@ -228,6 +229,7 @@ const allTests: TestMainFunction[] = [
runWalletRefreshErrorsTest,
runPeerPullLargeTest,
runPeerPushLargeTest,
+ runWithdrawalHandoverTest,
];
export interface TestRunSpec {
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts
index ccf3c230a..a52b3e6ba 100644
--- a/packages/taler-util/src/wallet-types.ts
+++ b/packages/taler-util/src/wallet-types.ts
@@ -1980,7 +1980,6 @@ export const codecForApplyRefundFromPurchaseIdRequest =
export interface GetWithdrawalDetailsForUriRequest {
talerWithdrawUri: string;
restrictAge?: number;
- notifyChangeFromPendingTimeoutMs?: number;
}
export const codecForGetWithdrawalDetailsForUri =
@@ -1988,10 +1987,6 @@ export const codecForGetWithdrawalDetailsForUri =
buildCodecForObject<GetWithdrawalDetailsForUriRequest>()
.property("talerWithdrawUri", codecForString())
.property("restrictAge", codecOptional(codecForNumber()))
- .property(
- "notifyChangeFromPendingTimeoutMs",
- codecOptional(codecForNumber()),
- )
.build("GetWithdrawalDetailsForUriRequest");
export interface ListKnownBankAccountsRequest {
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 8bfb6772f..fc612b189 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -904,7 +904,6 @@ async function dispatchRequestInternal(
case WalletApiOperation.GetWithdrawalDetailsForUri: {
const req = codecForGetWithdrawalDetailsForUri().decode(payload);
return await getWithdrawalDetailsForUri(wex, req.talerWithdrawUri, {
- notifyChangeFromPendingTimeoutMs: req.notifyChangeFromPendingTimeoutMs,
restrictAge: req.restrictAge,
});
}
diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts
index 0597c051f..106bd93a4 100644
--- a/packages/taler-wallet-core/src/withdraw.ts
+++ b/packages/taler-wallet-core/src/withdraw.ts
@@ -2885,9 +2885,7 @@ export async function confirmWithdrawal(
const withdrawalGroup = await wex.db.runReadOnlyTx(
{ storeNames: ["withdrawalGroups"] },
async (tx) => {
- return await tx.withdrawalGroups.indexes.byTalerWithdrawUri.get(
- parsedTx.withdrawalGroupId,
- );
+ return await tx.withdrawalGroups.get(parsedTx.withdrawalGroupId);
},
);