2020-08-05 21:00:36 +02:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2022-03-14 18:31:30 +01:00
|
|
|
import { GlobalTestState } from "../harness/harness.js";
|
2023-02-13 13:15:47 +01:00
|
|
|
import { createSimpleTestkudosEnvironmentV2 } from "../harness/helpers.js";
|
2022-03-14 18:31:30 +01:00
|
|
|
import {
|
|
|
|
WalletApiOperation,
|
|
|
|
BankApi,
|
|
|
|
BankAccessApi,
|
|
|
|
} from "@gnu-taler/taler-wallet-core";
|
2023-02-13 13:15:47 +01:00
|
|
|
import { j2s, NotificationType, TransactionType, WithdrawalType } from "@gnu-taler/taler-util";
|
2020-08-05 21:00:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run test for basic, bank-integrated withdrawal.
|
|
|
|
*/
|
2021-01-12 20:04:16 +01:00
|
|
|
export async function runWithdrawalBankIntegratedTest(t: GlobalTestState) {
|
2020-08-05 21:00:36 +02:00
|
|
|
// Set up test environment
|
|
|
|
|
2023-02-13 13:15:47 +01:00
|
|
|
const { walletClient, bank, exchange } =
|
|
|
|
await createSimpleTestkudosEnvironmentV2(t);
|
2020-08-05 21:00:36 +02:00
|
|
|
|
|
|
|
// Create a withdrawal operation
|
|
|
|
|
2020-08-20 10:25:03 +02:00
|
|
|
const user = await BankApi.createRandomBankUser(bank);
|
2020-09-01 15:37:14 +02:00
|
|
|
const wop = await BankAccessApi.createWithdrawalOperation(
|
|
|
|
bank,
|
|
|
|
user,
|
|
|
|
"TESTKUDOS:10",
|
|
|
|
);
|
2020-08-05 21:00:36 +02:00
|
|
|
|
|
|
|
// Hand it to the wallet
|
|
|
|
|
2023-02-13 13:15:47 +01:00
|
|
|
const r1 = await walletClient.client.call(
|
2022-03-14 18:31:30 +01:00
|
|
|
WalletApiOperation.GetWithdrawalDetailsForUri,
|
|
|
|
{
|
|
|
|
talerWithdrawUri: wop.taler_withdraw_uri,
|
|
|
|
},
|
|
|
|
);
|
2020-08-05 21:00:36 +02:00
|
|
|
|
|
|
|
// Withdraw
|
|
|
|
|
2023-02-13 13:15:47 +01:00
|
|
|
const withdrawalBankConfirmedCond = walletClient.waitForNotificationCond(
|
|
|
|
(x) => {
|
|
|
|
return x.type === NotificationType.WithdrawalGroupBankConfirmed;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
const withdrawalFinishedCond = walletClient.waitForNotificationCond((x) => {
|
|
|
|
return x.type === NotificationType.WithdrawGroupFinished;
|
|
|
|
});
|
|
|
|
|
|
|
|
const withdrawalReserveReadyCond = walletClient.waitForNotificationCond(
|
|
|
|
(x) => {
|
|
|
|
return x.type === NotificationType.WithdrawalGroupReserveReady;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
const r2 = await walletClient.client.call(
|
2022-03-14 18:31:30 +01:00
|
|
|
WalletApiOperation.AcceptBankIntegratedWithdrawal,
|
|
|
|
{
|
|
|
|
exchangeBaseUrl: exchange.baseUrl,
|
|
|
|
talerWithdrawUri: wop.taler_withdraw_uri,
|
|
|
|
},
|
|
|
|
);
|
2023-02-13 13:15:47 +01:00
|
|
|
|
2022-08-24 19:44:24 +02:00
|
|
|
// Do it twice to check idempotency
|
2023-02-13 13:15:47 +01:00
|
|
|
const r3 = await walletClient.client.call(
|
2022-08-24 19:44:24 +02:00
|
|
|
WalletApiOperation.AcceptBankIntegratedWithdrawal,
|
|
|
|
{
|
|
|
|
exchangeBaseUrl: exchange.baseUrl,
|
|
|
|
talerWithdrawUri: wop.taler_withdraw_uri,
|
|
|
|
},
|
|
|
|
);
|
2023-02-13 13:15:47 +01:00
|
|
|
|
|
|
|
await exchange.stopWirewatch();
|
|
|
|
|
|
|
|
// Check status before withdrawal is confirmed by bank.
|
|
|
|
{
|
|
|
|
const txn = await walletClient.client.call(
|
|
|
|
WalletApiOperation.GetTransactions,
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
console.log("transactions before confirmation:", j2s(txn));
|
|
|
|
const tx0 = txn.transactions[0];
|
|
|
|
t.assertTrue(tx0.type === TransactionType.Withdrawal);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.type === WithdrawalType.TalerBankIntegrationApi);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.confirmed === false);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.reserveIsReady === false);
|
|
|
|
}
|
2021-11-13 12:53:48 +01:00
|
|
|
|
|
|
|
// Confirm it
|
|
|
|
|
|
|
|
await BankApi.confirmWithdrawalOperation(bank, user, wop);
|
|
|
|
|
2023-02-13 13:15:47 +01:00
|
|
|
await withdrawalBankConfirmedCond;
|
|
|
|
|
|
|
|
// Check status after withdrawal is confirmed by bank,
|
|
|
|
// but before funds are wired to the exchange.
|
|
|
|
{
|
|
|
|
const txn = await walletClient.client.call(
|
|
|
|
WalletApiOperation.GetTransactions,
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
console.log("transactions after confirmation:", j2s(txn));
|
|
|
|
const tx0 = txn.transactions[0];
|
|
|
|
t.assertTrue(tx0.type === TransactionType.Withdrawal);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.type === WithdrawalType.TalerBankIntegrationApi);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.confirmed === true);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.reserveIsReady === false);
|
|
|
|
}
|
|
|
|
|
|
|
|
await exchange.startWirewatch();
|
|
|
|
|
|
|
|
await withdrawalReserveReadyCond;
|
|
|
|
|
|
|
|
// Check status after funds were wired.
|
|
|
|
{
|
|
|
|
const txn = await walletClient.client.call(
|
|
|
|
WalletApiOperation.GetTransactions,
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
console.log("transactions after reserve ready:", j2s(txn));
|
|
|
|
const tx0 = txn.transactions[0];
|
|
|
|
t.assertTrue(tx0.type === TransactionType.Withdrawal);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.type === WithdrawalType.TalerBankIntegrationApi);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.confirmed === true);
|
|
|
|
t.assertTrue(tx0.withdrawalDetails.reserveIsReady === true);
|
|
|
|
}
|
|
|
|
|
|
|
|
await withdrawalFinishedCond;
|
2020-08-05 21:00:36 +02:00
|
|
|
|
|
|
|
// Check balance
|
|
|
|
|
2023-02-13 13:15:47 +01:00
|
|
|
const balResp = await walletClient.client.call(
|
|
|
|
WalletApiOperation.GetBalances,
|
|
|
|
{},
|
|
|
|
);
|
2020-08-12 09:11:00 +02:00
|
|
|
t.assertAmountEquals("TESTKUDOS:9.72", balResp.balances[0].available);
|
2020-08-05 21:00:36 +02:00
|
|
|
|
2023-02-13 13:15:47 +01:00
|
|
|
const txn = await walletClient.client.call(
|
|
|
|
WalletApiOperation.GetTransactions,
|
|
|
|
{},
|
|
|
|
);
|
2022-08-24 19:44:24 +02:00
|
|
|
console.log(`transactions: ${j2s(txn)}`);
|
2021-01-12 20:04:16 +01:00
|
|
|
}
|
2021-05-21 11:47:20 +02:00
|
|
|
|
|
|
|
runWithdrawalBankIntegratedTest.suites = ["wallet"];
|