TWG, payments reversal testing.

Up to the point where the payments to be reversed get
created via the native Sandbox API, instead of the add-incoming
API, that got recently removed from the Nexus implementation.
This commit is contained in:
MS 2021-02-15 20:28:09 +01:00
parent 7a2ab04da8
commit d384bd5c62
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
3 changed files with 76 additions and 8 deletions

View File

@ -60,6 +60,16 @@ export interface SimpleTestEnvironment {
wallet: WalletCli;
}
export function getRandomIban(countryCode: string): string {
return `${countryCode}715001051796${(Math.random() * 100000000)
.toString()
.substring(0, 8)}`;
}
export function getRandomString(): string {
return Math.random().toString(36).substring(2);
}
/**
* Run a test case with a simple TESTKUDOS Taler environment, consisting
* of one exchange, one bank and one merchant.

View File

@ -19,6 +19,7 @@
*/
import axios from "axios";
import { URL } from "@gnu-taler/taler-wallet-core";
import { getRandomIban, getRandomString } from "./helpers";
import {
GlobalTestState,
DbInfo,
@ -113,6 +114,20 @@ export interface LibeufinPreparedPaymentDetails {
nexusBankAccountName: string;
}
export interface LibeufinSandboxAddIncomingRequest {
creditorIban: string;
creditorBic: string;
creditorName: string;
debitorIban: string;
debitorBic: string;
debitorName: string;
subject: string;
amount: string;
currency: string;
uid: string;
direction: string;
}
export class LibeufinSandboxService implements LibeufinSandboxServiceInterface {
static async create(
gc: GlobalTestState,
@ -221,6 +236,12 @@ export interface CreateEbicsSubscriberRequest {
systemID?: string;
}
export interface TwgAddIncomingRequest {
amount: string;
reserve_pub: string;
debit_account: string;
}
interface CreateEbicsBankAccountRequest {
subscriber: {
hostID: string;
@ -266,6 +287,7 @@ export class NexusUserBundle {
twgReq: CreateTalerWireGatewayFacadeRequest;
twgTransferPermission: PostNexusPermissionRequest;
twgHistoryPermission: PostNexusPermissionRequest;
twgAddIncomingPermission: PostNexusPermissionRequest;
localAccountName: string;
remoteAccountName: string;
@ -295,8 +317,8 @@ export class NexusUserBundle {
this.twgTransferPermission = {
action: "grant",
permission: {
subjectType: `username-${salt}`,
subjectId: "twguser",
subjectId: `username-${salt}`,
subjectType: "user",
resourceType: "facade",
resourceId: `twg-${salt}`,
permissionName: "facade.talerWireGateway.transfer",
@ -305,8 +327,8 @@ export class NexusUserBundle {
this.twgHistoryPermission = {
action: "grant",
permission: {
subjectType: `username-${salt}`,
subjectId: "twguser",
subjectId: `username-${salt}`,
subjectType: "user",
resourceType: "facade",
resourceId: `twg-${salt}`,
permissionName: "facade.talerWireGateway.history",
@ -327,9 +349,7 @@ export class SandboxUserBundle {
this.ebicsBankAccount = {
currency: "EUR",
bic: "BELADEBEXXX",
iban: `DE715001051796${(Math.random() * 100000000)
.toString()
.substring(0, 8)}`,
iban: getRandomIban("DE"),
label: `remote-account-${salt}`,
name: `Taler Exchange: ${salt}`,
subscriber: {
@ -630,6 +650,32 @@ export namespace LibeufinSandboxApi {
await axios.post(url.href, req);
}
export async function bookPayment(
libeufinSandboxService: LibeufinSandboxServiceInterface,
creditorBundle: SandboxUserBundle,
debitorBundle: SandboxUserBundle,
subject: string,
amount: string,
currency: string,
) {
let req: LibeufinSandboxAddIncomingRequest = {
creditorIban: creditorBundle.ebicsBankAccount.iban,
creditorBic: creditorBundle.ebicsBankAccount.bic,
creditorName: creditorBundle.ebicsBankAccount.name,
debitorIban: debitorBundle.ebicsBankAccount.iban,
debitorBic: debitorBundle.ebicsBankAccount.bic,
debitorName: debitorBundle.ebicsBankAccount.name,
subject: subject,
amount: amount,
currency: currency,
uid: getRandomString(),
direction: "CRDT",
};
const baseUrl = libeufinSandboxService.baseUrl;
let url = new URL("admin/payments", baseUrl);
await axios.post(url.href, req);
}
export async function simulateIncomingTransaction(
libeufinSandboxService: LibeufinSandboxServiceInterface,
accountLabel: string,

View File

@ -20,10 +20,13 @@
import { CoreApiResponse } from "@gnu-taler/taler-wallet-core";
import { CoinConfig, defaultCoinConfig } from "./denomStructures";
import { GlobalTestState } from "./harness";
import { getRandomIban } from "./helpers";
import {
SandboxUserBundle,
NexusUserBundle,
launchLibeufinServices,
LibeufinNexusApi,
LibeufinSandboxApi,
} from "./libeufin";
/**
@ -41,9 +44,18 @@ export async function runLibeufinRefundTest(t: GlobalTestState) {
);
const user02sandbox = new SandboxUserBundle("02");
await launchLibeufinServices(
const libeufinServices = await launchLibeufinServices(
t,
[user01nexus, user02nexus],
[user01sandbox, user02sandbox],
);
await LibeufinSandboxApi.bookPayment(
libeufinServices.libeufinSandbox,
user02sandbox,
user01sandbox,
"not a public key",
"1",
"EUR",
);
}