diff options
author | Florian Dold <florian@dold.me> | 2024-04-30 13:23:23 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-04-30 13:23:23 +0200 |
commit | 84adb1e78e49057cdcee15c71ad788f56bb0fff9 (patch) | |
tree | c8ab545301c61a03dd5759135f647070cc62c121 /packages/taler-harness | |
parent | 8b5d1276b9d9043e85cba91704c908ff544916e0 (diff) | |
download | wallet-core-84adb1e78e49057cdcee15c71ad788f56bb0fff9.tar.xz |
harness: test for withdrawal handover
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-withdrawal-handover.ts | 191 | ||||
-rw-r--r-- | packages/taler-harness/src/integrationtests/testrunner.ts | 2 |
2 files changed, 193 insertions, 0 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 { |