2021-01-17 01:18:37 +01: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.
|
|
|
|
*/
|
2021-03-17 17:56:37 +01:00
|
|
|
import { CoreApiResponse } from "@gnu-taler/taler-util";
|
2021-06-17 13:34:59 +02:00
|
|
|
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
|
2021-01-17 01:18:37 +01:00
|
|
|
import { CoinConfig, defaultCoinConfig } from "./denomStructures";
|
|
|
|
import {
|
|
|
|
DbInfo,
|
2021-03-17 17:56:37 +01:00
|
|
|
HarnessExchangeBankAccount,
|
2021-01-17 01:18:37 +01:00
|
|
|
ExchangeService,
|
|
|
|
GlobalTestState,
|
|
|
|
MerchantService,
|
|
|
|
setupDb,
|
|
|
|
WalletCli,
|
|
|
|
} from "./harness";
|
|
|
|
import { makeTestPayment } from "./helpers";
|
|
|
|
import {
|
|
|
|
LibeufinNexusApi,
|
|
|
|
LibeufinNexusService,
|
|
|
|
LibeufinSandboxApi,
|
|
|
|
LibeufinSandboxService,
|
|
|
|
} from "./libeufin";
|
|
|
|
|
|
|
|
const exchangeIban = "DE71500105179674997361";
|
|
|
|
const customerIban = "DE84500105176881385584";
|
|
|
|
const customerBic = "BELADEBEXXX";
|
|
|
|
const merchantIban = "DE42500105171245624648";
|
|
|
|
|
|
|
|
export interface LibeufinTestEnvironment {
|
|
|
|
commonDb: DbInfo;
|
|
|
|
exchange: ExchangeService;
|
2021-03-17 17:56:37 +01:00
|
|
|
exchangeBankAccount: HarnessExchangeBankAccount;
|
2021-01-17 01:18:37 +01:00
|
|
|
merchant: MerchantService;
|
|
|
|
wallet: WalletCli;
|
|
|
|
libeufinSandbox: LibeufinSandboxService;
|
|
|
|
libeufinNexus: LibeufinNexusService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a Taler environment with LibEuFin and an EBICS account.
|
|
|
|
*/
|
|
|
|
export async function createLibeufinTestEnvironment(
|
|
|
|
t: GlobalTestState,
|
|
|
|
coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("EUR")),
|
|
|
|
): Promise<LibeufinTestEnvironment> {
|
|
|
|
const db = await setupDb(t);
|
|
|
|
|
|
|
|
const libeufinSandbox = await LibeufinSandboxService.create(t, {
|
|
|
|
httpPort: 5010,
|
|
|
|
databaseJdbcUri: `jdbc:sqlite:${t.testDir}/libeufin-sandbox.sqlite3`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await libeufinSandbox.start();
|
|
|
|
await libeufinSandbox.pingUntilAvailable();
|
|
|
|
|
|
|
|
const libeufinNexus = await LibeufinNexusService.create(t, {
|
|
|
|
httpPort: 5011,
|
|
|
|
databaseJdbcUri: `jdbc:sqlite:${t.testDir}/libeufin-nexus.sqlite3`,
|
|
|
|
});
|
|
|
|
|
|
|
|
await libeufinNexus.start();
|
|
|
|
await libeufinNexus.pingUntilAvailable();
|
|
|
|
|
|
|
|
await LibeufinSandboxApi.createEbicsHost(libeufinSandbox, "host01");
|
|
|
|
// Subscriber and bank Account for the exchange
|
|
|
|
await LibeufinSandboxApi.createEbicsSubscriber(libeufinSandbox, {
|
|
|
|
hostID: "host01",
|
|
|
|
partnerID: "partner01",
|
|
|
|
userID: "user01",
|
|
|
|
});
|
|
|
|
await LibeufinSandboxApi.createEbicsBankAccount(libeufinSandbox, {
|
|
|
|
bic: "DEUTDEBB101",
|
|
|
|
iban: exchangeIban,
|
|
|
|
label: "exchangeacct",
|
|
|
|
name: "Taler Exchange",
|
|
|
|
subscriber: {
|
|
|
|
hostID: "host01",
|
|
|
|
partnerID: "partner01",
|
|
|
|
userID: "user01",
|
|
|
|
},
|
|
|
|
currency: "EUR",
|
|
|
|
});
|
|
|
|
// Subscriber and bank Account for the merchant
|
|
|
|
// (Merchant doesn't need EBICS access, but sandbox right now only supports EBICS
|
|
|
|
// accounts.)
|
|
|
|
await LibeufinSandboxApi.createEbicsSubscriber(libeufinSandbox, {
|
|
|
|
hostID: "host01",
|
|
|
|
partnerID: "partner02",
|
|
|
|
userID: "user02",
|
|
|
|
});
|
|
|
|
await LibeufinSandboxApi.createEbicsBankAccount(libeufinSandbox, {
|
2021-08-07 22:09:46 +02:00
|
|
|
bic: "AUTOATW1XXX",
|
2021-01-17 01:18:37 +01:00
|
|
|
iban: merchantIban,
|
|
|
|
label: "merchantacct",
|
|
|
|
name: "Merchant",
|
|
|
|
subscriber: {
|
|
|
|
hostID: "host01",
|
|
|
|
partnerID: "partner02",
|
|
|
|
userID: "user02",
|
|
|
|
},
|
|
|
|
currency: "EUR",
|
|
|
|
});
|
|
|
|
|
|
|
|
await LibeufinNexusApi.createEbicsBankConnection(libeufinNexus, {
|
|
|
|
name: "myconn",
|
|
|
|
ebicsURL: "http://localhost:5010/ebicsweb",
|
|
|
|
hostID: "host01",
|
|
|
|
partnerID: "partner01",
|
|
|
|
userID: "user01",
|
|
|
|
});
|
|
|
|
await LibeufinNexusApi.connectBankConnection(libeufinNexus, "myconn");
|
|
|
|
await LibeufinNexusApi.fetchAccounts(libeufinNexus, "myconn");
|
|
|
|
await LibeufinNexusApi.importConnectionAccount(
|
|
|
|
libeufinNexus,
|
|
|
|
"myconn",
|
|
|
|
"exchangeacct",
|
|
|
|
"myacct",
|
|
|
|
);
|
|
|
|
|
|
|
|
await LibeufinNexusApi.createTwgFacade(libeufinNexus, {
|
|
|
|
name: "twg1",
|
|
|
|
accountName: "myacct",
|
|
|
|
connectionName: "myconn",
|
|
|
|
currency: "EUR",
|
|
|
|
reserveTransferLevel: "report",
|
|
|
|
});
|
|
|
|
|
2021-01-20 20:31:32 +01:00
|
|
|
await LibeufinNexusApi.createUser(libeufinNexus, {
|
|
|
|
username: "twguser",
|
|
|
|
password: "twgpw",
|
|
|
|
});
|
|
|
|
|
|
|
|
await LibeufinNexusApi.postPermission(libeufinNexus, {
|
|
|
|
action: "grant",
|
|
|
|
permission: {
|
2021-02-03 14:35:29 +01:00
|
|
|
subjectType: "user",
|
2021-01-20 20:31:32 +01:00
|
|
|
subjectId: "twguser",
|
|
|
|
resourceType: "facade",
|
|
|
|
resourceId: "twg1",
|
2021-02-03 14:35:29 +01:00
|
|
|
permissionName: "facade.talerWireGateway.history",
|
|
|
|
},
|
2021-01-20 20:31:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
await LibeufinNexusApi.postPermission(libeufinNexus, {
|
|
|
|
action: "grant",
|
|
|
|
permission: {
|
2021-02-03 14:35:29 +01:00
|
|
|
subjectType: "user",
|
2021-01-20 20:31:32 +01:00
|
|
|
subjectId: "twguser",
|
|
|
|
resourceType: "facade",
|
|
|
|
resourceId: "twg1",
|
2021-02-03 14:35:29 +01:00
|
|
|
permissionName: "facade.talerWireGateway.transfer",
|
|
|
|
},
|
2021-01-20 20:31:32 +01:00
|
|
|
});
|
|
|
|
|
2021-01-17 01:18:37 +01:00
|
|
|
const exchange = ExchangeService.create(t, {
|
|
|
|
name: "testexchange-1",
|
|
|
|
currency: "EUR",
|
|
|
|
httpPort: 8081,
|
|
|
|
database: db.connStr,
|
|
|
|
});
|
|
|
|
|
|
|
|
const merchant = await MerchantService.create(t, {
|
|
|
|
name: "testmerchant-1",
|
|
|
|
currency: "EUR",
|
|
|
|
httpPort: 8083,
|
|
|
|
database: db.connStr,
|
|
|
|
});
|
|
|
|
|
2021-03-17 17:56:37 +01:00
|
|
|
const exchangeBankAccount: HarnessExchangeBankAccount = {
|
2021-01-20 20:31:32 +01:00
|
|
|
accountName: "twguser",
|
|
|
|
accountPassword: "twgpw",
|
2021-01-17 01:18:37 +01:00
|
|
|
accountPaytoUri: `payto://iban/${exchangeIban}?receiver-name=Exchange`,
|
|
|
|
wireGatewayApiBaseUrl:
|
|
|
|
"http://localhost:5011/facades/twg1/taler-wire-gateway/",
|
|
|
|
};
|
|
|
|
|
|
|
|
exchange.addBankAccount("1", exchangeBankAccount);
|
|
|
|
|
|
|
|
exchange.addCoinConfigList(coinConfig);
|
|
|
|
|
|
|
|
await exchange.start();
|
|
|
|
await exchange.pingUntilAvailable();
|
|
|
|
|
|
|
|
merchant.addExchange(exchange);
|
|
|
|
|
|
|
|
await merchant.start();
|
|
|
|
await merchant.pingUntilAvailable();
|
|
|
|
|
|
|
|
await merchant.addInstance({
|
|
|
|
id: "default",
|
|
|
|
name: "Default Instance",
|
|
|
|
paytoUris: [`payto://iban/${merchantIban}?receiver-name=Merchant`],
|
|
|
|
defaultWireTransferDelay: { d_ms: 0 },
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("setup done!");
|
|
|
|
|
|
|
|
const wallet = new WalletCli(t);
|
|
|
|
|
|
|
|
return {
|
|
|
|
commonDb: db,
|
|
|
|
exchange,
|
|
|
|
merchant,
|
|
|
|
wallet,
|
|
|
|
exchangeBankAccount,
|
|
|
|
libeufinNexus,
|
|
|
|
libeufinSandbox,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run basic test with LibEuFin.
|
|
|
|
*/
|
|
|
|
export async function runLibeufinBasicTest(t: GlobalTestState) {
|
|
|
|
// Set up test environment
|
|
|
|
|
|
|
|
const {
|
|
|
|
wallet,
|
|
|
|
exchange,
|
|
|
|
merchant,
|
|
|
|
libeufinSandbox,
|
|
|
|
libeufinNexus,
|
|
|
|
} = await createLibeufinTestEnvironment(t);
|
|
|
|
|
2021-06-17 13:34:59 +02:00
|
|
|
await wallet.client.call(WalletApiOperation.AddExchange, {
|
2021-01-17 01:18:37 +01:00
|
|
|
exchangeBaseUrl: exchange.baseUrl,
|
|
|
|
});
|
|
|
|
|
2021-06-17 13:34:59 +02:00
|
|
|
const wr = await wallet.client.call(
|
|
|
|
WalletApiOperation.AcceptManualWithdrawal,
|
|
|
|
{
|
|
|
|
exchangeBaseUrl: exchange.baseUrl,
|
|
|
|
amount: "EUR:10",
|
|
|
|
},
|
|
|
|
);
|
2021-01-17 01:18:37 +01:00
|
|
|
|
2021-06-17 13:34:59 +02:00
|
|
|
const reservePub: string = wr.reservePub;
|
2021-01-17 01:18:37 +01:00
|
|
|
|
|
|
|
await LibeufinSandboxApi.simulateIncomingTransaction(
|
|
|
|
libeufinSandbox,
|
|
|
|
"exchangeacct",
|
|
|
|
{
|
|
|
|
amount: "15.00",
|
|
|
|
debtorBic: customerBic,
|
|
|
|
debtorIban: customerIban,
|
|
|
|
debtorName: "Jane Customer",
|
|
|
|
subject: `Taler Top-up ${reservePub}`,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
await LibeufinNexusApi.fetchAllTransactions(libeufinNexus, "myacct");
|
|
|
|
|
|
|
|
await exchange.runWirewatchOnce();
|
|
|
|
|
|
|
|
await wallet.runUntilDone();
|
|
|
|
|
2021-06-17 13:34:59 +02:00
|
|
|
const bal = await wallet.client.call(WalletApiOperation.GetBalances, {});
|
2021-01-17 01:18:37 +01:00
|
|
|
console.log("balances", JSON.stringify(bal, undefined, 2));
|
|
|
|
t.assertAmountEquals(bal.balances[0].available, "EUR:14.7");
|
|
|
|
|
|
|
|
const order = {
|
|
|
|
summary: "Buy me!",
|
|
|
|
amount: "EUR:5",
|
|
|
|
fulfillment_url: "taler://fulfillment-success/thx",
|
|
|
|
};
|
|
|
|
|
|
|
|
await makeTestPayment(t, { wallet, merchant, order });
|
|
|
|
|
|
|
|
await exchange.runAggregatorOnce();
|
|
|
|
await exchange.runTransferOnce();
|
|
|
|
|
|
|
|
await LibeufinNexusApi.submitAllPaymentInitiations(libeufinNexus, "myacct");
|
|
|
|
|
|
|
|
const exchangeTransactions = await LibeufinSandboxApi.getAccountTransactions(
|
|
|
|
libeufinSandbox,
|
|
|
|
"exchangeacct",
|
|
|
|
);
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
"exchange transactions:",
|
|
|
|
JSON.stringify(exchangeTransactions, undefined, 2),
|
|
|
|
);
|
|
|
|
|
|
|
|
t.assertDeepEqual(
|
|
|
|
exchangeTransactions.payments[0].creditDebitIndicator,
|
|
|
|
"credit",
|
|
|
|
);
|
|
|
|
t.assertDeepEqual(
|
|
|
|
exchangeTransactions.payments[1].creditDebitIndicator,
|
|
|
|
"debit",
|
|
|
|
);
|
|
|
|
t.assertDeepEqual(exchangeTransactions.payments[1].debtorIban, exchangeIban);
|
|
|
|
t.assertDeepEqual(
|
|
|
|
exchangeTransactions.payments[1].creditorIban,
|
|
|
|
merchantIban,
|
|
|
|
);
|
|
|
|
}
|
2021-05-21 19:24:17 +02:00
|
|
|
runLibeufinBasicTest.suites = ["libeufin"];
|