2022-04-19 17:12:43 +02:00
|
|
|
/*
|
|
|
|
This file is part of GNU Taler
|
2023-09-06 11:44:07 +02:00
|
|
|
(C) 2022-2023 Taler Systems S.A.
|
2022-04-19 17:12:43 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2023-09-06 13:24:34 +02:00
|
|
|
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
2022-04-19 17:12:43 +02:00
|
|
|
import { defaultCoinConfig } from "../harness/denomStructures.js";
|
2023-09-06 11:44:07 +02:00
|
|
|
import { getWireMethodForTest, GlobalTestState } from "../harness/harness.js";
|
2022-04-19 17:12:43 +02:00
|
|
|
import {
|
2023-09-05 10:46:06 +02:00
|
|
|
createSimpleTestkudosEnvironmentV2,
|
|
|
|
createWalletDaemonWithClient,
|
|
|
|
makeTestPaymentV2,
|
|
|
|
withdrawViaBankV2,
|
2022-04-19 17:12:43 +02:00
|
|
|
} from "../harness/helpers.js";
|
2023-09-06 13:24:34 +02:00
|
|
|
import {
|
|
|
|
BankAccessApiClient,
|
|
|
|
MerchantApiClient,
|
|
|
|
WireGatewayApiClient,
|
|
|
|
} from "@gnu-taler/taler-util";
|
2022-04-19 17:12:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run test for basic, bank-integrated withdrawal and payment.
|
|
|
|
*/
|
2022-09-05 12:29:32 +02:00
|
|
|
export async function runAgeRestrictionsMerchantTest(t: GlobalTestState) {
|
2022-04-19 17:12:43 +02:00
|
|
|
// Set up test environment
|
|
|
|
|
2022-09-19 17:08:04 +02:00
|
|
|
const {
|
2023-09-05 10:46:06 +02:00
|
|
|
walletClient: walletClientOne,
|
2022-09-19 17:08:04 +02:00
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
merchant,
|
|
|
|
exchangeBankAccount,
|
2023-09-05 10:46:06 +02:00
|
|
|
} = await createSimpleTestkudosEnvironmentV2(
|
2022-09-19 17:08:04 +02:00
|
|
|
t,
|
|
|
|
defaultCoinConfig.map((x) => x("TESTKUDOS")),
|
|
|
|
{
|
|
|
|
ageMaskSpec: "8:10:12:14:16:18:21",
|
|
|
|
},
|
|
|
|
);
|
2022-04-19 17:12:43 +02:00
|
|
|
|
2023-05-05 14:56:28 +02:00
|
|
|
const merchantClient = new MerchantApiClient(
|
|
|
|
merchant.makeInstanceBaseUrl("default"),
|
|
|
|
);
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
const { walletClient: walletClientTwo } = await createWalletDaemonWithClient(
|
|
|
|
t,
|
|
|
|
{
|
|
|
|
name: "w2",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
const { walletClient: walletClientThree } =
|
|
|
|
await createWalletDaemonWithClient(t, {
|
|
|
|
name: "w3",
|
|
|
|
});
|
2022-05-05 17:59:43 +02:00
|
|
|
|
2022-09-08 14:02:09 +02:00
|
|
|
{
|
2023-09-05 10:46:06 +02:00
|
|
|
const { walletClient: walletClientZero } =
|
|
|
|
await createWalletDaemonWithClient(t, {
|
|
|
|
name: "w0",
|
|
|
|
});
|
2022-09-08 14:02:09 +02:00
|
|
|
|
2023-09-06 10:48:44 +02:00
|
|
|
const wres = await withdrawViaBankV2(t, {
|
2023-09-05 10:46:06 +02:00
|
|
|
walletClient: walletClientZero,
|
2022-09-08 14:02:09 +02:00
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
amount: "TESTKUDOS:20",
|
|
|
|
restrictAge: 13,
|
|
|
|
});
|
2023-09-06 10:48:44 +02:00
|
|
|
await wres.withdrawalFinishedCond;
|
2022-09-08 14:02:09 +02:00
|
|
|
|
|
|
|
const order = {
|
|
|
|
summary: "Buy me!",
|
|
|
|
amount: "TESTKUDOS:5",
|
|
|
|
fulfillment_url: "taler://fulfillment-success/thx",
|
|
|
|
minimum_age: 9,
|
|
|
|
};
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await makeTestPaymentV2(t, {
|
|
|
|
walletClient: walletClientZero,
|
|
|
|
merchant,
|
|
|
|
order,
|
|
|
|
});
|
|
|
|
await walletClientZero.call(
|
|
|
|
WalletApiOperation.TestingWaitTransactionsFinal,
|
|
|
|
{},
|
|
|
|
);
|
2022-09-08 14:02:09 +02:00
|
|
|
}
|
|
|
|
|
2022-05-05 17:59:43 +02:00
|
|
|
{
|
2023-09-05 10:46:06 +02:00
|
|
|
const walletClient = walletClientOne;
|
2022-05-05 17:59:43 +02:00
|
|
|
|
2023-09-06 10:48:44 +02:00
|
|
|
const wres = await withdrawViaBankV2(t, {
|
2023-09-05 10:46:06 +02:00
|
|
|
walletClient,
|
2022-05-05 17:59:43 +02:00
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
amount: "TESTKUDOS:20",
|
|
|
|
restrictAge: 13,
|
|
|
|
});
|
2023-09-06 10:48:44 +02:00
|
|
|
await wres.withdrawalFinishedCond;
|
2022-05-05 17:59:43 +02:00
|
|
|
|
|
|
|
const order = {
|
|
|
|
summary: "Buy me!",
|
|
|
|
amount: "TESTKUDOS:5",
|
|
|
|
fulfillment_url: "taler://fulfillment-success/thx",
|
|
|
|
minimum_age: 9,
|
|
|
|
};
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await makeTestPaymentV2(t, { walletClient, merchant, order });
|
|
|
|
await walletClient.call(
|
|
|
|
WalletApiOperation.TestingWaitTransactionsFinal,
|
|
|
|
{},
|
|
|
|
);
|
2022-05-05 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-09-05 10:46:06 +02:00
|
|
|
const walletClient = walletClientTwo;
|
2022-05-05 17:59:43 +02:00
|
|
|
|
2023-09-06 10:48:44 +02:00
|
|
|
const wres = await withdrawViaBankV2(t, {
|
2023-09-05 10:46:06 +02:00
|
|
|
walletClient,
|
2022-05-05 17:59:43 +02:00
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
amount: "TESTKUDOS:20",
|
|
|
|
restrictAge: 13,
|
|
|
|
});
|
2023-09-06 10:48:44 +02:00
|
|
|
await wres.withdrawalFinishedCond;
|
2022-05-05 17:59:43 +02:00
|
|
|
|
|
|
|
const order = {
|
|
|
|
summary: "Buy me!",
|
|
|
|
amount: "TESTKUDOS:5",
|
|
|
|
fulfillment_url: "taler://fulfillment-success/thx",
|
|
|
|
};
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await makeTestPaymentV2(t, { walletClient, merchant, order });
|
|
|
|
await walletClient.call(
|
|
|
|
WalletApiOperation.TestingWaitTransactionsFinal,
|
|
|
|
{},
|
|
|
|
);
|
2022-05-05 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-09-05 10:46:06 +02:00
|
|
|
const walletClient = walletClientThree;
|
2022-05-05 17:59:43 +02:00
|
|
|
|
2023-09-06 10:48:44 +02:00
|
|
|
const wres = await withdrawViaBankV2(t, {
|
2023-09-05 10:46:06 +02:00
|
|
|
walletClient,
|
2022-05-05 17:59:43 +02:00
|
|
|
bank,
|
|
|
|
exchange,
|
|
|
|
amount: "TESTKUDOS:20",
|
|
|
|
});
|
2023-09-06 10:48:44 +02:00
|
|
|
await wres.withdrawalFinishedCond;
|
2022-05-05 17:59:43 +02:00
|
|
|
|
|
|
|
const order = {
|
|
|
|
summary: "Buy me!",
|
|
|
|
amount: "TESTKUDOS:5",
|
|
|
|
fulfillment_url: "taler://fulfillment-success/thx",
|
|
|
|
minimum_age: 9,
|
|
|
|
};
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await makeTestPaymentV2(t, { walletClient, merchant, order });
|
|
|
|
await walletClient.call(
|
|
|
|
WalletApiOperation.TestingWaitTransactionsFinal,
|
|
|
|
{},
|
|
|
|
);
|
2022-05-05 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 17:08:04 +02:00
|
|
|
// Pay with coin from tipping
|
|
|
|
{
|
2023-09-06 12:32:31 +02:00
|
|
|
const bankClient = new BankAccessApiClient(bank.bankAccessApiBaseUrl);
|
|
|
|
const mbu = await bankClient.createRandomBankUser();
|
2023-09-05 10:46:06 +02:00
|
|
|
const tipReserveResp = await merchantClient.createTippingReserve({
|
|
|
|
exchange_url: exchange.baseUrl,
|
|
|
|
initial_balance: "TESTKUDOS:10",
|
|
|
|
wire_method: getWireMethodForTest(),
|
|
|
|
});
|
2022-09-19 17:08:04 +02:00
|
|
|
|
|
|
|
t.assertDeepEqual(
|
2023-05-05 14:56:28 +02:00
|
|
|
tipReserveResp.accounts[0].payto_uri,
|
2022-09-19 17:08:04 +02:00
|
|
|
exchangeBankAccount.accountPaytoUri,
|
|
|
|
);
|
|
|
|
|
2023-09-06 12:32:31 +02:00
|
|
|
const wireGatewayApiClient = new WireGatewayApiClient(
|
|
|
|
exchangeBankAccount.wireGatewayApiBaseUrl,
|
|
|
|
{
|
|
|
|
auth: {
|
|
|
|
username: exchangeBankAccount.accountName,
|
|
|
|
password: exchangeBankAccount.accountPassword,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2023-04-22 22:17:08 +02:00
|
|
|
|
|
|
|
await wireGatewayApiClient.adminAddIncoming({
|
2022-09-19 17:08:04 +02:00
|
|
|
amount: "TESTKUDOS:10",
|
|
|
|
debitAccountPayto: mbu.accountPaytoUri,
|
|
|
|
reservePub: tipReserveResp.reserve_pub,
|
|
|
|
});
|
|
|
|
|
|
|
|
await exchange.runWirewatchOnce();
|
|
|
|
|
2023-09-06 11:23:33 +02:00
|
|
|
const tip = await merchantClient.giveTip({
|
2022-09-19 17:08:04 +02:00
|
|
|
amount: "TESTKUDOS:5",
|
|
|
|
justification: "why not?",
|
|
|
|
next_url: "https://example.com/after-tip",
|
|
|
|
});
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
const { walletClient: walletClientTipping } =
|
|
|
|
await createWalletDaemonWithClient(t, {
|
|
|
|
name: "age-tipping",
|
|
|
|
});
|
2022-09-19 17:08:04 +02:00
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
const ptr = await walletClientTipping.call(
|
|
|
|
WalletApiOperation.PrepareReward,
|
|
|
|
{
|
|
|
|
talerRewardUri: tip.taler_reward_uri,
|
|
|
|
},
|
|
|
|
);
|
2022-09-19 17:08:04 +02:00
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await walletClientTipping.call(WalletApiOperation.AcceptReward, {
|
2023-08-03 18:35:07 +02:00
|
|
|
walletRewardId: ptr.walletRewardId,
|
2022-09-19 17:08:04 +02:00
|
|
|
});
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await walletClientTipping.call(
|
|
|
|
WalletApiOperation.TestingWaitTransactionsFinal,
|
|
|
|
{},
|
|
|
|
);
|
2022-09-19 17:08:04 +02:00
|
|
|
|
|
|
|
const order = {
|
|
|
|
summary: "Buy me!",
|
|
|
|
amount: "TESTKUDOS:4",
|
|
|
|
fulfillment_url: "taler://fulfillment-success/thx",
|
|
|
|
minimum_age: 9,
|
|
|
|
};
|
|
|
|
|
2023-09-05 10:46:06 +02:00
|
|
|
await makeTestPaymentV2(t, {
|
|
|
|
walletClient: walletClientTipping,
|
|
|
|
merchant,
|
|
|
|
order,
|
|
|
|
});
|
|
|
|
await walletClientTipping.call(
|
|
|
|
WalletApiOperation.TestingWaitTransactionsFinal,
|
|
|
|
{},
|
|
|
|
);
|
2022-09-19 17:08:04 +02:00
|
|
|
}
|
2022-04-19 17:12:43 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 12:29:32 +02:00
|
|
|
runAgeRestrictionsMerchantTest.suites = ["wallet"];
|
2022-09-19 17:08:04 +02:00
|
|
|
runAgeRestrictionsMerchantTest.timeoutMs = 120 * 1000;
|