2020-09-03 19:09:07 +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.
|
|
|
|
*/
|
|
|
|
import {
|
2021-01-05 11:26:29 +01:00
|
|
|
ConfirmPayResultType,
|
|
|
|
Duration,
|
|
|
|
durationFromSpec,
|
2023-09-06 11:44:07 +02:00
|
|
|
MerchantApiClient,
|
2021-01-05 11:26:29 +01:00
|
|
|
PreparePayResultType,
|
2021-03-17 17:56:37 +01:00
|
|
|
} from "@gnu-taler/taler-util";
|
2021-06-17 13:34:59 +02:00
|
|
|
import {
|
|
|
|
PendingOperationsResponse,
|
|
|
|
WalletApiOperation,
|
|
|
|
} from "@gnu-taler/taler-wallet-core";
|
2022-10-13 15:14:49 +02:00
|
|
|
import { makeNoFeeCoinConfig } from "../harness/denomStructures.js";
|
2021-01-05 11:26:29 +01:00
|
|
|
import {
|
|
|
|
BankService,
|
|
|
|
ExchangeService,
|
2023-09-06 11:44:07 +02:00
|
|
|
getPayto,
|
2020-09-03 19:09:07 +02:00
|
|
|
GlobalTestState,
|
|
|
|
MerchantService,
|
2020-09-08 19:14:01 +02:00
|
|
|
setupDb,
|
2021-10-20 13:06:31 +02:00
|
|
|
} from "../harness/harness.js";
|
2023-09-06 11:23:33 +02:00
|
|
|
import {
|
|
|
|
applyTimeTravelV2,
|
|
|
|
createWalletDaemonWithClient,
|
|
|
|
withdrawViaBankV2,
|
|
|
|
} from "../harness/helpers.js";
|
2020-09-03 19:09:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic time travel test.
|
|
|
|
*/
|
2021-01-12 20:04:16 +01:00
|
|
|
export async function runTimetravelAutorefreshTest(t: GlobalTestState) {
|
2020-09-03 19:09:07 +02:00
|
|
|
// Set up test environment
|
|
|
|
|
2020-09-08 19:14:01 +02:00
|
|
|
const db = await setupDb(t);
|
|
|
|
|
|
|
|
const bank = await BankService.create(t, {
|
|
|
|
allowRegistrations: true,
|
|
|
|
currency: "TESTKUDOS",
|
|
|
|
database: db.connStr,
|
|
|
|
httpPort: 8082,
|
|
|
|
});
|
|
|
|
|
|
|
|
const exchange = ExchangeService.create(t, {
|
|
|
|
name: "testexchange-1",
|
|
|
|
currency: "TESTKUDOS",
|
|
|
|
httpPort: 8081,
|
|
|
|
database: db.connStr,
|
|
|
|
});
|
|
|
|
|
|
|
|
const merchant = await MerchantService.create(t, {
|
|
|
|
name: "testmerchant-1",
|
|
|
|
currency: "TESTKUDOS",
|
|
|
|
httpPort: 8083,
|
|
|
|
database: db.connStr,
|
|
|
|
});
|
|
|
|
|
|
|
|
const exchangeBankAccount = await bank.createExchangeAccount(
|
2021-11-13 12:53:48 +01:00
|
|
|
"myexchange",
|
2020-09-08 19:14:01 +02:00
|
|
|
"x",
|
|
|
|
);
|
|
|
|
exchange.addBankAccount("1", exchangeBankAccount);
|
|
|
|
|
|
|
|
bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
|
|
|
|
|
|
|
|
await bank.start();
|
|
|
|
|
|
|
|
await bank.pingUntilAvailable();
|
|
|
|
|
|
|
|
exchange.addCoinConfigList(makeNoFeeCoinConfig("TESTKUDOS"));
|
|
|
|
|
|
|
|
await exchange.start();
|
|
|
|
await exchange.pingUntilAvailable();
|
|
|
|
|
|
|
|
merchant.addExchange(exchange);
|
|
|
|
|
|
|
|
await merchant.start();
|
|
|
|
await merchant.pingUntilAvailable();
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await merchant.addInstanceWithWireAccount({
|
2020-09-08 19:14:01 +02:00
|
|
|
id: "default",
|
|
|
|
name: "Default Instance",
|
2021-11-13 12:53:48 +01:00
|
|
|
paytoUris: [getPayto("merchant-default")],
|
2020-09-08 19:14:01 +02:00
|
|
|
});
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await merchant.addInstanceWithWireAccount({
|
2021-06-10 10:37:49 +02:00
|
|
|
id: "minst1",
|
|
|
|
name: "minst1",
|
2021-11-13 12:53:48 +01:00
|
|
|
paytoUris: [getPayto("minst1")],
|
2021-06-10 10:37:49 +02:00
|
|
|
});
|
|
|
|
|
2020-09-08 19:14:01 +02:00
|
|
|
console.log("setup done!");
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
const { walletClient } = await createWalletDaemonWithClient(t, {
|
|
|
|
name: "w1",
|
|
|
|
});
|
2020-09-03 19:09:07 +02:00
|
|
|
|
2023-09-06 11:23:33 +02:00
|
|
|
const merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl());
|
|
|
|
|
2020-09-03 19:09:07 +02:00
|
|
|
// Withdraw digital cash into the wallet.
|
|
|
|
|
2023-09-06 11:23:33 +02:00
|
|
|
const wres = await withdrawViaBankV2(t, {
|
|
|
|
walletClient,
|
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
amount: "TESTKUDOS:15",
|
|
|
|
});
|
2023-09-05 10:46:06 +02:00
|
|
|
await wres.withdrawalFinishedCond;
|
2020-09-03 19:09:07 +02:00
|
|
|
|
|
|
|
// Travel into the future, the deposit expiration is two years
|
|
|
|
// into the future.
|
2021-08-19 15:12:33 +02:00
|
|
|
console.log("applying first time travel");
|
2023-09-06 11:23:33 +02:00
|
|
|
await applyTimeTravelV2(
|
|
|
|
Duration.toMilliseconds(durationFromSpec({ days: 400 })),
|
|
|
|
{
|
|
|
|
walletClient,
|
|
|
|
exchange,
|
|
|
|
merchant,
|
|
|
|
},
|
|
|
|
);
|
2020-09-03 19:09:07 +02:00
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
|
2020-09-06 15:59:12 +02:00
|
|
|
|
2020-09-03 19:09:07 +02:00
|
|
|
let p: PendingOperationsResponse;
|
2023-09-05 10:46:06 +02:00
|
|
|
p = await walletClient.call(WalletApiOperation.GetPendingOperations, {});
|
2020-09-03 19:09:07 +02:00
|
|
|
|
|
|
|
console.log("pending operations after first time travel");
|
|
|
|
console.log(JSON.stringify(p, undefined, 2));
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await withdrawViaBankV2(t, {
|
|
|
|
walletClient,
|
2020-09-03 19:09:07 +02:00
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
amount: "TESTKUDOS:20",
|
|
|
|
});
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
|
2020-09-03 19:09:07 +02:00
|
|
|
|
|
|
|
// Travel into the future, the deposit expiration is two years
|
|
|
|
// into the future.
|
2021-08-19 15:12:33 +02:00
|
|
|
console.log("applying second time travel");
|
2023-09-06 11:23:33 +02:00
|
|
|
await applyTimeTravelV2(
|
|
|
|
Duration.toMilliseconds(durationFromSpec({ years: 2, months: 6 })),
|
|
|
|
{
|
|
|
|
walletClient,
|
|
|
|
exchange,
|
|
|
|
merchant,
|
|
|
|
},
|
|
|
|
);
|
2020-09-03 19:09:07 +02:00
|
|
|
|
2021-06-10 16:32:37 +02:00
|
|
|
// At this point, the original coins should've been refreshed.
|
|
|
|
// It would be too late to refresh them now, as we're past
|
|
|
|
// the two year deposit expiration.
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
|
2020-09-03 19:09:07 +02:00
|
|
|
|
2023-09-06 11:23:33 +02:00
|
|
|
const orderResp = await merchantClient.createOrder({
|
2020-09-03 19:09:07 +02:00
|
|
|
order: {
|
|
|
|
fulfillment_url: "http://example.com",
|
|
|
|
summary: "foo",
|
|
|
|
amount: "TESTKUDOS:30",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-09-06 11:23:33 +02:00
|
|
|
const orderStatus = await merchantClient.queryPrivateOrderStatus({
|
|
|
|
orderId: orderResp.order_id,
|
|
|
|
instance: "default",
|
|
|
|
});
|
2020-09-03 19:09:07 +02:00
|
|
|
|
|
|
|
t.assertTrue(orderStatus.order_status === "unpaid");
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
const r = await walletClient.call(WalletApiOperation.PreparePayForUri, {
|
2020-09-03 19:09:07 +02:00
|
|
|
talerPayUri: orderStatus.taler_pay_uri,
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(r);
|
|
|
|
|
|
|
|
t.assertTrue(r.status === PreparePayResultType.PaymentPossible);
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
const cpr = await walletClient.call(WalletApiOperation.ConfirmPay, {
|
2020-09-03 19:09:07 +02:00
|
|
|
proposalId: r.proposalId,
|
|
|
|
});
|
|
|
|
|
|
|
|
t.assertTrue(cpr.type === ConfirmPayResultType.Done);
|
2021-01-12 20:04:16 +01:00
|
|
|
}
|
2021-05-21 11:47:20 +02:00
|
|
|
|
|
|
|
runTimetravelAutorefreshTest.suites = ["wallet"];
|