use fakebank for integration tests
This commit is contained in:
parent
f3ff5a7225
commit
bc434ebb83
@ -42,6 +42,8 @@ import {
|
|||||||
TalerProtocolDuration,
|
TalerProtocolDuration,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
|
BankAccessApi,
|
||||||
|
BankApi,
|
||||||
BankServiceHandle,
|
BankServiceHandle,
|
||||||
HarnessExchangeBankAccount,
|
HarnessExchangeBankAccount,
|
||||||
NodeHttpLib,
|
NodeHttpLib,
|
||||||
@ -522,11 +524,17 @@ class LibEuFinBankService extends BankServiceBase implements BankServiceHandle {
|
|||||||
return url.href;
|
return url.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Duplicate? Where is this needed?
|
||||||
get baseUrlAccessApi(): string {
|
get baseUrlAccessApi(): string {
|
||||||
let url = new URL("access-api/", this.baseUrlDemobank);
|
let url = new URL("access-api/", this.baseUrlDemobank);
|
||||||
return url.href;
|
return url.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get bankAccessApiBaseUrl(): string {
|
||||||
|
let url = new URL("access-api/", this.baseUrlDemobank);
|
||||||
|
return url.href;
|
||||||
|
}
|
||||||
|
|
||||||
get baseUrlNetloc(): string {
|
get baseUrlNetloc(): string {
|
||||||
return `http://localhost:${this.bankConfig.httpPort}/`;
|
return `http://localhost:${this.bankConfig.httpPort}/`;
|
||||||
}
|
}
|
||||||
@ -796,10 +804,19 @@ class FakebankService extends BankServiceBase implements BankServiceHandle {
|
|||||||
return `http://localhost:${this.bankConfig.httpPort}/`;
|
return `http://localhost:${this.bankConfig.httpPort}/`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get bankAccessApiBaseUrl(): string {
|
||||||
|
let url = new URL("taler-bank-access/", this.baseUrl);
|
||||||
|
return url.href;
|
||||||
|
}
|
||||||
|
|
||||||
async createExchangeAccount(
|
async createExchangeAccount(
|
||||||
accountName: string,
|
accountName: string,
|
||||||
password: string,
|
password: string,
|
||||||
): Promise<HarnessExchangeBankAccount> {
|
): 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 {
|
return {
|
||||||
accountName: accountName,
|
accountName: accountName,
|
||||||
accountPassword: password,
|
accountPassword: password,
|
||||||
@ -813,6 +830,10 @@ class FakebankService extends BankServiceBase implements BankServiceHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async start(): Promise<void> {
|
async start(): Promise<void> {
|
||||||
|
if (this.proc) {
|
||||||
|
console.log("fakebank already running, not starting again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.proc = this.globalTestState.spawnService(
|
this.proc = this.globalTestState.spawnService(
|
||||||
"taler-fakebank-run",
|
"taler-fakebank-run",
|
||||||
["-c", this.configFile],
|
["-c", this.configFile],
|
||||||
@ -821,13 +842,13 @@ class FakebankService extends BankServiceBase implements BankServiceHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async pingUntilAvailable(): Promise<void> {
|
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");
|
await pingProc(this.proc, url, "bank");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use libeufin bank instead of pybank.
|
// Use libeufin bank instead of pybank.
|
||||||
const useLibeufinBank = true;
|
const useLibeufinBank = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a euFin or a pyBank implementation of
|
* Return a euFin or a pyBank implementation of
|
||||||
@ -2032,7 +2053,7 @@ export function getPayto(label: string): string {
|
|||||||
return `payto://iban/SANDBOXX/${getRandomIban(
|
return `payto://iban/SANDBOXX/${getRandomIban(
|
||||||
label,
|
label,
|
||||||
)}?receiver-name=${label}`;
|
)}?receiver-name=${label}`;
|
||||||
return `payto://x-taler-bank/${label}`;
|
return `payto://x-taler-bank/localhost/${label}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitMs(ms: number): Promise<void> {
|
function waitMs(ms: number): Promise<void> {
|
||||||
|
@ -34,6 +34,7 @@ export async function runPaymentDemoTest(t: GlobalTestState) {
|
|||||||
// Withdraw digital cash into the wallet.
|
// Withdraw digital cash into the wallet.
|
||||||
let bankInterface: BankServiceHandle = {
|
let bankInterface: BankServiceHandle = {
|
||||||
baseUrl: "https://bank.demo.taler.net/",
|
baseUrl: "https://bank.demo.taler.net/",
|
||||||
|
bankAccessApiBaseUrl: "https://bank.demo.taler.net/",
|
||||||
http: new NodeHttpLib(),
|
http: new NodeHttpLib(),
|
||||||
};
|
};
|
||||||
let user = await BankApi.createRandomBankUser(bankInterface);
|
let user = await BankApi.createRandomBankUser(bankInterface);
|
||||||
|
@ -56,6 +56,7 @@ export interface BankAccountBalanceResponse {
|
|||||||
|
|
||||||
export interface BankServiceHandle {
|
export interface BankServiceHandle {
|
||||||
readonly baseUrl: string;
|
readonly baseUrl: string;
|
||||||
|
readonly bankAccessApiBaseUrl: string;
|
||||||
readonly http: HttpRequestLibrary;
|
readonly http: HttpRequestLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,12 +97,13 @@ const codecForWithdrawalOperationInfo = (): Codec<WithdrawalOperationInfo> =>
|
|||||||
.build("WithdrawalOperationInfo");
|
.build("WithdrawalOperationInfo");
|
||||||
|
|
||||||
export namespace BankApi {
|
export namespace BankApi {
|
||||||
|
// FIXME: Move to BankAccessApi?!
|
||||||
export async function registerAccount(
|
export async function registerAccount(
|
||||||
bank: BankServiceHandle,
|
bank: BankServiceHandle,
|
||||||
username: string,
|
username: string,
|
||||||
password: string,
|
password: string,
|
||||||
): Promise<BankUser> {
|
): 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 });
|
const resp = await bank.http.postJson(url.href, { username, password });
|
||||||
let paytoUri = `payto://x-taler-bank/localhost/${username}`;
|
let paytoUri = `payto://x-taler-bank/localhost/${username}`;
|
||||||
if (resp.status !== 200 && resp.status !== 202) {
|
if (resp.status !== 200 && resp.status !== 202) {
|
||||||
@ -130,6 +132,7 @@ export namespace BankApi {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Move to BankAccessApi?!
|
||||||
export async function createRandomBankUser(
|
export async function createRandomBankUser(
|
||||||
bank: BankServiceHandle,
|
bank: BankServiceHandle,
|
||||||
): Promise<BankUser> {
|
): Promise<BankUser> {
|
||||||
@ -177,9 +180,10 @@ export namespace BankApi {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`accounts/${bankUser.username}/withdrawals/${wopi.withdrawal_id}/confirm`,
|
`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,
|
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(
|
export async function abortWithdrawalOperation(
|
||||||
@ -222,7 +234,10 @@ export namespace BankAccessApi {
|
|||||||
bank: BankServiceHandle,
|
bank: BankServiceHandle,
|
||||||
bankUser: BankUser,
|
bankUser: BankUser,
|
||||||
): Promise<BankAccountBalanceResponse> {
|
): 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, {
|
const resp = await bank.http.get(url.href, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: makeBasicAuthHeader(
|
Authorization: makeBasicAuthHeader(
|
||||||
@ -241,7 +256,7 @@ export namespace BankAccessApi {
|
|||||||
): Promise<WithdrawalOperationInfo> {
|
): Promise<WithdrawalOperationInfo> {
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`accounts/${bankUser.username}/withdrawals`,
|
`accounts/${bankUser.username}/withdrawals`,
|
||||||
bank.baseUrl,
|
bank.bankAccessApiBaseUrl,
|
||||||
);
|
);
|
||||||
const resp = await bank.http.postJson(
|
const resp = await bank.http.postJson(
|
||||||
url.href,
|
url.href,
|
||||||
|
@ -109,6 +109,7 @@ export async function topupReserveWithDemobank(
|
|||||||
) {
|
) {
|
||||||
const bankHandle: BankServiceHandle = {
|
const bankHandle: BankServiceHandle = {
|
||||||
baseUrl: bankBaseUrl,
|
baseUrl: bankBaseUrl,
|
||||||
|
bankAccessApiBaseUrl: "??", // FIXME!
|
||||||
http,
|
http,
|
||||||
};
|
};
|
||||||
const bankUser = await BankApi.createRandomBankUser(bankHandle);
|
const bankUser = await BankApi.createRandomBankUser(bankHandle);
|
||||||
|
Loading…
Reference in New Issue
Block a user