summaryrefslogtreecommitdiff
path: root/packages/taler-harness/src/integrationtests/test-kyc.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-01-10 17:31:01 +0100
committerFlorian Dold <florian@dold.me>2023-01-10 17:31:36 +0100
commita82d8fab696d3fca24c2f1c48a1646107e38cef8 (patch)
treecb493f6072ec4a761df214db920d709629a1eee1 /packages/taler-harness/src/integrationtests/test-kyc.ts
parent688518ec7311ea0dc68e1cce6d363a00609ef9f8 (diff)
downloadwallet-core-a82d8fab696d3fca24c2f1c48a1646107e38cef8.tar.gz
wallet-core-a82d8fab696d3fca24c2f1c48a1646107e38cef8.tar.bz2
wallet-core-a82d8fab696d3fca24c2f1c48a1646107e38cef8.zip
wallet-core: KYC mvp
Only hard withdrawal KYC is supporte so far, and no long-polling is done yet.
Diffstat (limited to 'packages/taler-harness/src/integrationtests/test-kyc.ts')
-rw-r--r--packages/taler-harness/src/integrationtests/test-kyc.ts204
1 files changed, 204 insertions, 0 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-kyc.ts b/packages/taler-harness/src/integrationtests/test-kyc.ts
new file mode 100644
index 000000000..40474fb6f
--- /dev/null
+++ b/packages/taler-harness/src/integrationtests/test-kyc.ts
@@ -0,0 +1,204 @@
+/*
+ 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 { Duration } from "@gnu-taler/taler-util";
+import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js";
+import {
+ BankService,
+ ExchangeService,
+ getPayto,
+ GlobalTestState,
+ MerchantService,
+ setupDb,
+ WalletCli,
+} from "../harness/harness.js";
+import {
+ withdrawViaBank,
+ makeTestPayment,
+ EnvOptions,
+ SimpleTestEnvironment,
+} from "../harness/helpers.js";
+
+export async function createKycTestkudosEnvironment(
+ t: GlobalTestState,
+ coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")),
+ opts: EnvOptions = {},
+): Promise<SimpleTestEnvironment> {
+ 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(
+ "myexchange",
+ "x",
+ );
+ exchange.addBankAccount("1", exchangeBankAccount);
+
+ bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
+
+ await bank.start();
+
+ await bank.pingUntilAvailable();
+
+ const ageMaskSpec = opts.ageMaskSpec;
+
+ if (ageMaskSpec) {
+ exchange.enableAgeRestrictions(ageMaskSpec);
+ // Enable age restriction for all coins.
+ exchange.addCoinConfigList(
+ coinConfig.map((x) => ({
+ ...x,
+ name: `${x.name}-age`,
+ ageRestricted: true,
+ })),
+ );
+ // For mixed age restrictions, we also offer coins without age restrictions
+ if (opts.mixedAgeRestriction) {
+ exchange.addCoinConfigList(
+ coinConfig.map((x) => ({ ...x, ageRestricted: false })),
+ );
+ }
+ } else {
+ exchange.addCoinConfigList(coinConfig);
+ }
+
+ await exchange.modifyConfig(async (config) => {
+ const myprov = "kyc-provider-myprov";
+ config.setString(myprov, "cost", "0");
+ config.setString(myprov, "logic", "oauth2");
+ config.setString(myprov, "provided_checks", "dummy1");
+ config.setString(myprov, "user_type", "individual");
+ config.setString(myprov, "kyc_oauth2_validity", "forever");
+ config.setString(
+ myprov,
+ "kyc_oauth2_auth_url",
+ "http://localhost:6666/oauth/v2/token",
+ );
+ config.setString(
+ myprov,
+ "kyc_oauth2_login_url",
+ "http://localhost:6666/oauth/v2/login",
+ );
+ config.setString(
+ myprov,
+ "kyc_oauth2_info_url",
+ "http://localhost:6666/oauth/v2/login",
+ );
+ config.setString(
+ myprov,
+ "kyc_oauth2_client_id",
+ "taler-exchange",
+ );
+ config.setString(
+ myprov,
+ "kyc_oauth2_client_secret",
+ "exchange-secret",
+ );
+ config.setString(
+ myprov,
+ "kyc_oauth2_post_url",
+ "https://taler.com",
+ );
+
+ config.setString("kyc-legitimization-withdraw1", "operation_type", "withdraw");
+ config.setString("kyc-legitimization-withdraw1", "required_checks", "dummy1");
+ config.setString("kyc-legitimization-withdraw1", "timeframe", "1d");
+ config.setString("kyc-legitimization-withdraw1", "threshold", "TESTKUDOS:5");
+ });
+
+ await exchange.start();
+ await exchange.pingUntilAvailable();
+
+ merchant.addExchange(exchange);
+
+ await merchant.start();
+ await merchant.pingUntilAvailable();
+
+ await merchant.addInstance({
+ id: "default",
+ name: "Default Instance",
+ paytoUris: [getPayto("merchant-default")],
+ defaultWireTransferDelay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 1 }),
+ ),
+ });
+
+ await merchant.addInstance({
+ id: "minst1",
+ name: "minst1",
+ paytoUris: [getPayto("minst1")],
+ defaultWireTransferDelay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 1 }),
+ ),
+ });
+
+ console.log("setup done!");
+
+ const wallet = new WalletCli(t);
+
+ return {
+ commonDb: db,
+ exchange,
+ merchant,
+ wallet,
+ bank,
+ exchangeBankAccount,
+ };
+}
+
+export async function runKycTest(t: GlobalTestState) {
+ // Set up test environment
+
+ const { wallet, bank, exchange, merchant } =
+ await createKycTestkudosEnvironment(t);
+
+ // Withdraw digital cash into the wallet.
+
+ await withdrawViaBank(t, { wallet, bank, exchange, amount: "TESTKUDOS:20" });
+
+ const order = {
+ summary: "Buy me!",
+ amount: "TESTKUDOS:5",
+ fulfillment_url: "taler://fulfillment-success/thx",
+ };
+
+ await makeTestPayment(t, { wallet, merchant, order });
+ await wallet.runUntilDone();
+}
+
+runKycTest.suites = ["wallet"];