wallet-core/packages/taler-harness/src/integrationtests/test-age-restrictions-merchant.ts

261 lines
6.4 KiB
TypeScript
Raw Normal View History

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