diff options
author | Florian Dold <florian@dold.me> | 2024-05-15 23:31:09 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-05-15 23:31:09 +0200 |
commit | 6529421a5c09dec082f33ea80b1df2861e0bf5c9 (patch) | |
tree | 94188eb6f0889d48d790151496b26d934e260ed0 /packages/taler-harness | |
parent | 2b1e808d553d21beba3bafa09ef606035fcdb378 (diff) | |
download | wallet-core-6529421a5c09dec082f33ea80b1df2861e0bf5c9.tar.xz |
wallet-core: withdraw actual amount from reserve even if instructed amount differs
Diffstat (limited to 'packages/taler-harness')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-withdrawal-amount.ts | 94 | ||||
-rw-r--r-- | packages/taler-harness/src/integrationtests/testrunner.ts | 2 |
2 files changed, 96 insertions, 0 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-withdrawal-amount.ts b/packages/taler-harness/src/integrationtests/test-withdrawal-amount.ts new file mode 100644 index 000000000..cd6a1e325 --- /dev/null +++ b/packages/taler-harness/src/integrationtests/test-withdrawal-amount.ts @@ -0,0 +1,94 @@ +/* + 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 { + AmountString, + Logger, + WireGatewayApiClient, + j2s, +} from "@gnu-taler/taler-util"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { GlobalTestState } from "../harness/harness.js"; +import { createSimpleTestkudosEnvironmentV3 } from "../harness/helpers.js"; + +const logger = new Logger("test-withdrawal-manual.ts"); + +/** + * Check what happens when the withdrawal amount unexpectedly changes. + */ +export async function runWithdrawalAmountTest(t: GlobalTestState) { + // Set up test environment + + const { walletClient, bankClient, exchange, exchangeBankAccount } = + await createSimpleTestkudosEnvironmentV3(t); + + const wireGatewayApiClient = new WireGatewayApiClient( + exchangeBankAccount.wireGatewayApiBaseUrl, + { + auth: { + username: "admin", + password: "adminpw", + }, + }, + ); + + // Create a withdrawal operation + + const user = await bankClient.createRandomBankUser(); + + await walletClient.call(WalletApiOperation.AddExchange, { + exchangeBaseUrl: exchange.baseUrl, + }); + + logger.info("starting AcceptManualWithdrawal request"); + + const wres = await walletClient.call( + WalletApiOperation.AcceptManualWithdrawal, + { + exchangeBaseUrl: exchange.baseUrl, + amount: "TESTKUDOS:10" as AmountString, + }, + ); + + logger.info("AcceptManualWithdrawal finished"); + logger.info(`result: ${j2s(wres)}`); + + const reservePub: string = wres.reservePub; + + await wireGatewayApiClient.adminAddIncoming({ + amount: "TESTKUDOS:5", + debitAccountPayto: user.accountPaytoUri, + reservePub: reservePub, + }); + + await exchange.runWirewatchOnce(); + + await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {}); + + // Check balance + + const balResp = await walletClient.call(WalletApiOperation.GetBalances, {}); + + // We managed to withdraw the actually transferred amount! + t.assertAmountEquals(balResp.balances[0].available, "TESTKUDOS:4.85"); + + await t.shutdown(); +} + +runWithdrawalAmountTest.suites = ["wallet"]; diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts index 4b23d7762..eb2ae7fa6 100644 --- a/packages/taler-harness/src/integrationtests/testrunner.ts +++ b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -120,6 +120,7 @@ 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"; +import { runWithdrawalAmountTest } from "./test-withdrawal-amount.js"; /** * Test runner. @@ -230,6 +231,7 @@ const allTests: TestMainFunction[] = [ runPeerPullLargeTest, runPeerPushLargeTest, runWithdrawalHandoverTest, + runWithdrawalAmountTest, ]; export interface TestRunSpec { |