summaryrefslogtreecommitdiff
path: root/packages/taler-harness/src/harness/helpers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-harness/src/harness/helpers.ts')
-rw-r--r--packages/taler-harness/src/harness/helpers.ts262
1 files changed, 254 insertions, 8 deletions
diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts
index ea9047d0b..d194b0d36 100644
--- a/packages/taler-harness/src/harness/helpers.ts
+++ b/packages/taler-harness/src/harness/helpers.ts
@@ -29,11 +29,11 @@ import {
Duration,
Logger,
MerchantApiClient,
- MerchantContractTerms,
NotificationType,
PartialWalletRunConfig,
PreparePayResultType,
TalerCorebankApiClient,
+ TalerMerchantApi,
TransactionMajorState,
WalletNotification,
} from "@gnu-taler/taler-util";
@@ -51,6 +51,7 @@ import {
FakebankService,
GlobalTestState,
HarnessExchangeBankAccount,
+ LibeufinBankService,
MerchantService,
MerchantServiceInterface,
WalletCli,
@@ -60,6 +61,7 @@ import {
generateRandomPayto,
setupDb,
setupSharedDb,
+ useLibeufinBank,
} from "./harness.js";
import * as fs from "fs";
@@ -84,7 +86,21 @@ export interface SimpleTestEnvironment {
*/
export interface SimpleTestEnvironmentNg {
commonDb: DbInfo;
- bank: BankService;
+ bank: FakebankService;
+ exchange: ExchangeService;
+ exchangeBankAccount: HarnessExchangeBankAccount;
+ merchant: MerchantService;
+ walletClient: WalletClient;
+ walletService: WalletService;
+}
+
+/**
+ * Improved version of the simple test environment,
+ * passing bankClient instead of bank service.
+ */
+export interface SimpleTestEnvironmentNg3 {
+ commonDb: DbInfo;
+ bankClient: TalerCorebankApiClient;
exchange: ExchangeService;
exchangeBankAccount: HarnessExchangeBankAccount;
merchant: MerchantService;
@@ -100,6 +116,8 @@ export interface EnvOptions {
mixedAgeRestriction?: boolean;
+ skipWireFeeCreation?: boolean;
+
additionalExchangeConfig?(e: ExchangeService): void;
additionalMerchantConfig?(m: MerchantService): void;
additionalBankConfig?(b: BankService): void;
@@ -130,12 +148,12 @@ export async function useSharedTestkudosEnvironment(t: GlobalTestState) {
if (fs.existsSync(sharedDir + "/bank.conf")) {
logger.info("reusing existing bank");
- bank = BankService.fromExistingConfig(t, {
+ bank = FakebankService.fromExistingConfig(t, {
overridePath: sharedDir,
});
} else {
logger.info("creating new bank config");
- bank = await BankService.create(t, {
+ bank = await FakebankService.create(t, {
allowRegistrations: true,
currency: "TESTKUDOS",
database: db.connStr,
@@ -294,7 +312,7 @@ export async function createSimpleTestkudosEnvironmentV2(
): Promise<SimpleTestEnvironmentNg> {
const db = await setupDb(t);
- const bank = await BankService.create(t, {
+ const bank = await FakebankService.create(t, {
allowRegistrations: true,
currency: "TESTKUDOS",
database: db.connStr,
@@ -402,6 +420,160 @@ export async function createSimpleTestkudosEnvironmentV2(
};
}
+/**
+ * Run a test case with a simple TESTKUDOS Taler environment, consisting
+ * of one exchange, one bank and one merchant.
+ *
+ * V3 uses the unified Corebank API and allows to choose between
+ * Fakebank and Libeufin-bank.
+ */
+export async function createSimpleTestkudosEnvironmentV3(
+ t: GlobalTestState,
+ coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")),
+ opts: EnvOptions = {},
+): Promise<SimpleTestEnvironmentNg3> {
+ const db = await setupDb(t);
+
+ const bc = {
+ allowRegistrations: true,
+ currency: "TESTKUDOS",
+ database: db.connStr,
+ httpPort: 8082,
+ };
+
+ const bank: BankService = useLibeufinBank
+ ? await LibeufinBankService.create(t, bc)
+ : await FakebankService.create(t, bc);
+
+ 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 receiverName = "Exchange";
+ const exchangeBankUsername = "exchange";
+ const exchangeBankPassword = "mypw";
+ const exchangePaytoUri = generateRandomPayto(exchangeBankUsername);
+ const wireGatewayApiBaseUrl = new URL(
+ "accounts/exchange/taler-wire-gateway/",
+ bank.corebankApiBaseUrl,
+ ).href;
+
+ const exchangeBankAccount: HarnessExchangeBankAccount = {
+ wireGatewayApiBaseUrl,
+ accountName: exchangeBankUsername,
+ accountPassword: exchangeBankPassword,
+ accountPaytoUri: exchangePaytoUri,
+ skipWireFeeCreation: opts.skipWireFeeCreation === true,
+ };
+
+ await exchange.addBankAccount("1", exchangeBankAccount);
+
+ bank.setSuggestedExchange(exchange, exchangeBankAccount.accountPaytoUri);
+
+ if (opts.additionalBankConfig) {
+ opts.additionalBankConfig(bank);
+ }
+ await bank.start();
+
+ await bank.pingUntilAvailable();
+
+ const bankClient = new TalerCorebankApiClient(bank.corebankApiBaseUrl, {
+ auth: {
+ username: "admin",
+ password: "adminpw",
+ },
+ });
+
+ await bankClient.registerAccountExtended({
+ name: receiverName,
+ password: exchangeBankPassword,
+ username: exchangeBankUsername,
+ is_taler_exchange: true,
+ payto_uri: exchangePaytoUri,
+ });
+
+ 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);
+ }
+
+ if (opts.additionalExchangeConfig) {
+ opts.additionalExchangeConfig(exchange);
+ }
+ await exchange.start();
+ await exchange.pingUntilAvailable();
+
+ merchant.addExchange(exchange);
+
+ if (opts.additionalMerchantConfig) {
+ opts.additionalMerchantConfig(merchant);
+ }
+ await merchant.start();
+ await merchant.pingUntilAvailable();
+
+ await merchant.addInstanceWithWireAccount({
+ id: "default",
+ name: "Default Instance",
+ paytoUris: [generateRandomPayto("merchant-default")],
+ defaultWireTransferDelay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 1 }),
+ ),
+ });
+
+ await merchant.addInstanceWithWireAccount({
+ id: "minst1",
+ name: "minst1",
+ paytoUris: [generateRandomPayto("minst1")],
+ defaultWireTransferDelay: Duration.toTalerProtocolDuration(
+ Duration.fromSpec({ minutes: 1 }),
+ ),
+ });
+
+ const { walletClient, walletService } = await createWalletDaemonWithClient(
+ t,
+ { name: "wallet", persistent: true },
+ );
+
+ console.log("setup done!");
+
+ return {
+ commonDb: db,
+ exchange,
+ merchant,
+ walletClient,
+ walletService,
+ bankClient,
+ exchangeBankAccount,
+ };
+}
+
export interface CreateWalletArgs {
handleNotification?(wn: WalletNotification): void;
name: string;
@@ -457,7 +629,7 @@ export async function createWalletDaemonWithClient(
export interface FaultyMerchantTestEnvironment {
commonDb: DbInfo;
- bank: BankService;
+ bank: FakebankService;
exchange: ExchangeService;
faultyExchange: FaultInjectedExchangeService;
exchangeBankAccount: HarnessExchangeBankAccount;
@@ -466,6 +638,16 @@ export interface FaultyMerchantTestEnvironment {
walletClient: WalletClient;
}
+export interface FaultyMerchantTestEnvironmentNg {
+ commonDb: DbInfo;
+ bankClient: TalerCorebankApiClient;
+ exchange: ExchangeService;
+ faultyExchange: FaultInjectedExchangeService;
+ merchant: MerchantService;
+ faultyMerchant: FaultInjectedMerchantService;
+ walletClient: WalletClient;
+}
+
/**
* Run a test case with a simple TESTKUDOS Taler environment, consisting
* of one exchange, one bank and one merchant.
@@ -475,7 +657,7 @@ export async function createFaultInjectedMerchantTestkudosEnvironment(
): Promise<FaultyMerchantTestEnvironment> {
const db = await setupDb(t);
- const bank = await BankService.create(t, {
+ const bank = await FakebankService.create(t, {
allowRegistrations: true,
currency: "TESTKUDOS",
database: db.connStr,
@@ -621,6 +803,70 @@ export async function withdrawViaBankV2(
};
}
+/**
+ * Withdraw via a bank with the testing API enabled.
+ * Uses the new Corebank API.
+ */
+export async function withdrawViaBankV3(
+ t: GlobalTestState,
+ p: {
+ walletClient: WalletClient;
+ bankClient: TalerCorebankApiClient;
+ exchange: ExchangeServiceInterface;
+ amount: AmountString | string;
+ restrictAge?: number;
+ },
+): Promise<WithdrawViaBankResult> {
+ const { walletClient: wallet, bankClient, exchange, amount } = p;
+
+ const user = await bankClient.createRandomBankUser();
+ const bankClient2 = new TalerCorebankApiClient(bankClient.baseUrl);
+ bankClient2.setAuth({
+ username: user.username,
+ password: user.password,
+ });
+
+ const wop = await bankClient2.createWithdrawalOperation(
+ user.username,
+ amount,
+ );
+
+ // Hand it to the wallet
+
+ await wallet.client.call(WalletApiOperation.GetWithdrawalDetailsForUri, {
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ restrictAge: p.restrictAge,
+ });
+
+ // Withdraw (AKA select)
+
+ const acceptRes = await wallet.client.call(
+ WalletApiOperation.AcceptBankIntegratedWithdrawal,
+ {
+ exchangeBaseUrl: exchange.baseUrl,
+ talerWithdrawUri: wop.taler_withdraw_uri,
+ restrictAge: p.restrictAge,
+ },
+ );
+
+ const withdrawalFinishedCond = wallet.waitForNotificationCond(
+ (x) =>
+ x.type === NotificationType.TransactionStateTransition &&
+ x.newTxState.major === TransactionMajorState.Done &&
+ x.transactionId === acceptRes.transactionId,
+ );
+
+ // Confirm it
+
+ await bankClient2.confirmWithdrawalOperation(user.username, {
+ withdrawalOperationId: wop.withdrawal_id,
+ });
+
+ return {
+ withdrawalFinishedCond,
+ };
+}
+
export async function applyTimeTravelV2(
timetravelOffsetMs: number,
s: {
@@ -658,7 +904,7 @@ export async function makeTestPaymentV2(
args: {
merchant: MerchantServiceInterface;
walletClient: WalletClient;
- order: Partial<MerchantContractTerms>;
+ order: TalerMerchantApi.Order;
instance?: string;
},
auth: WithAuthorization = {},