use fakebank for integration tests

This commit is contained in:
Florian Dold 2022-08-23 22:30:05 +02:00
parent f3ff5a7225
commit bc434ebb83
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 46 additions and 8 deletions

View File

@ -42,6 +42,8 @@ import {
TalerProtocolDuration,
} from "@gnu-taler/taler-util";
import {
BankAccessApi,
BankApi,
BankServiceHandle,
HarnessExchangeBankAccount,
NodeHttpLib,
@ -522,11 +524,17 @@ class LibEuFinBankService extends BankServiceBase implements BankServiceHandle {
return url.href;
}
// FIXME: Duplicate? Where is this needed?
get baseUrlAccessApi(): string {
let url = new URL("access-api/", this.baseUrlDemobank);
return url.href;
}
get bankAccessApiBaseUrl(): string {
let url = new URL("access-api/", this.baseUrlDemobank);
return url.href;
}
get baseUrlNetloc(): string {
return `http://localhost:${this.bankConfig.httpPort}/`;
}
@ -796,10 +804,19 @@ class FakebankService extends BankServiceBase implements BankServiceHandle {
return `http://localhost:${this.bankConfig.httpPort}/`;
}
get bankAccessApiBaseUrl(): string {
let url = new URL("taler-bank-access/", this.baseUrl);
return url.href;
}
async createExchangeAccount(
accountName: string,
password: string,
): Promise<HarnessExchangeBankAccount> {
// FIXME: Is there a better place to do this initialization?
await this.start();
await this.pingUntilAvailable();
await BankApi.registerAccount(this, accountName, password);
return {
accountName: accountName,
accountPassword: password,
@ -813,6 +830,10 @@ class FakebankService extends BankServiceBase implements BankServiceHandle {
}
async start(): Promise<void> {
if (this.proc) {
console.log("fakebank already running, not starting again");
return;
}
this.proc = this.globalTestState.spawnService(
"taler-fakebank-run",
["-c", this.configFile],
@ -821,13 +842,13 @@ class FakebankService extends BankServiceBase implements BankServiceHandle {
}
async pingUntilAvailable(): Promise<void> {
const url = `http://localhost:${this.bankConfig.httpPort}/config`;
const url = `http://localhost:${this.bankConfig.httpPort}/taler-bank-integration/config`;
await pingProc(this.proc, url, "bank");
}
}
// Use libeufin bank instead of pybank.
const useLibeufinBank = true;
const useLibeufinBank = false;
/**
* Return a euFin or a pyBank implementation of
@ -2032,7 +2053,7 @@ export function getPayto(label: string): string {
return `payto://iban/SANDBOXX/${getRandomIban(
label,
)}?receiver-name=${label}`;
return `payto://x-taler-bank/${label}`;
return `payto://x-taler-bank/localhost/${label}`;
}
function waitMs(ms: number): Promise<void> {

View File

@ -34,6 +34,7 @@ export async function runPaymentDemoTest(t: GlobalTestState) {
// Withdraw digital cash into the wallet.
let bankInterface: BankServiceHandle = {
baseUrl: "https://bank.demo.taler.net/",
bankAccessApiBaseUrl: "https://bank.demo.taler.net/",
http: new NodeHttpLib(),
};
let user = await BankApi.createRandomBankUser(bankInterface);

View File

@ -56,6 +56,7 @@ export interface BankAccountBalanceResponse {
export interface BankServiceHandle {
readonly baseUrl: string;
readonly bankAccessApiBaseUrl: string;
readonly http: HttpRequestLibrary;
}
@ -96,12 +97,13 @@ const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
.build("WithdrawalOperationInfo");
export namespace BankApi {
// FIXME: Move to BankAccessApi?!
export async function registerAccount(
bank: BankServiceHandle,
username: string,
password: string,
): Promise<BankUser> {
const url = new URL("testing/register", bank.baseUrl);
const url = new URL("testing/register", bank.bankAccessApiBaseUrl);
const resp = await bank.http.postJson(url.href, { username, password });
let paytoUri = `payto://x-taler-bank/localhost/${username}`;
if (resp.status !== 200 && resp.status !== 202) {
@ -130,6 +132,7 @@ export namespace BankApi {
};
}
// FIXME: Move to BankAccessApi?!
export async function createRandomBankUser(
bank: BankServiceHandle,
): Promise<BankUser> {
@ -177,9 +180,10 @@ export namespace BankApi {
): Promise<void> {
const url = new URL(
`accounts/${bankUser.username}/withdrawals/${wopi.withdrawal_id}/confirm`,
bank.baseUrl,
bank.bankAccessApiBaseUrl,
);
await bank.http.postJson(
logger.info(`confirming withdrawal operation via ${url.href}`);
const resp = await bank.http.postJson(
url.href,
{},
{
@ -191,6 +195,14 @@ export namespace BankApi {
},
},
);
logger.info(`response status ${resp.status}`);
const respJson = await readSuccessResponseJsonOrThrow(
resp,
codecForAny(),
);
// FIXME: We don't check the status here!
}
export async function abortWithdrawalOperation(
@ -222,7 +234,10 @@ export namespace BankAccessApi {
bank: BankServiceHandle,
bankUser: BankUser,
): Promise<BankAccountBalanceResponse> {
const url = new URL(`accounts/${bankUser.username}`, bank.baseUrl);
const url = new URL(
`accounts/${bankUser.username}`,
bank.bankAccessApiBaseUrl,
);
const resp = await bank.http.get(url.href, {
headers: {
Authorization: makeBasicAuthHeader(
@ -241,7 +256,7 @@ export namespace BankAccessApi {
): Promise<WithdrawalOperationInfo> {
const url = new URL(
`accounts/${bankUser.username}/withdrawals`,
bank.baseUrl,
bank.bankAccessApiBaseUrl,
);
const resp = await bank.http.postJson(
url.href,

View File

@ -109,6 +109,7 @@ export async function topupReserveWithDemobank(
) {
const bankHandle: BankServiceHandle = {
baseUrl: bankBaseUrl,
bankAccessApiBaseUrl: "??", // FIXME!
http,
};
const bankUser = await BankApi.createRandomBankUser(bankHandle);