Testing harness.

No need to import modules dynamically, in order to
provide the euFin implementation of the BankServiceInterface.
This commit is contained in:
ms 2021-11-01 14:25:43 +01:00
parent 404c8c8a73
commit ea2acd1d3c
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
2 changed files with 107 additions and 119 deletions

View File

@ -607,126 +607,114 @@ export namespace BankApi {
} }
} }
/** export class BankService implements BankServiceInterface {
* Method explained here: proc: ProcessWrapper | undefined;
* https://github.com/microsoft/TypeScript/issues/2552
*/
module BankServices {
export class PybankService implements BankServiceInterface {
proc: ProcessWrapper | undefined;
static fromExistingConfig(gc: GlobalTestState): BankService { static async create(
const cfgFilename = gc.testDir + "/bank.conf"; gc: GlobalTestState,
console.log("reading bank config from", cfgFilename); bc: BankConfig,
const config = Configuration.load(cfgFilename); ): Promise<BankService> {
const bc: BankConfig = { const config = new Configuration();
allowRegistrations: config setTalerPaths(config, gc.testDir + "/talerhome");
.getYesNo("bank", "allow_registrations") config.setString("taler", "currency", bc.currency);
.required(), config.setString("bank", "database", bc.database);
currency: config.getString("taler", "currency").required(), config.setString("bank", "http_port", `${bc.httpPort}`);
database: config.getString("bank", "database").required(), config.setString("bank", "serve", "http");
httpPort: config.getNumber("bank", "http_port").required(), config.setString("bank", "max_debt_bank", `${bc.currency}:999999`);
}; config.setString("bank", "max_debt", bc.maxDebt ?? `${bc.currency}:100`);
return new BankService(gc, bc, cfgFilename); config.setString(
} "bank",
"allow_registrations",
bc.allowRegistrations ? "yes" : "no",
);
const cfgFilename = gc.testDir + "/bank.conf";
config.write(cfgFilename);
static async create( await sh(
gc: GlobalTestState, gc,
bc: BankConfig, "taler-bank-manage_django",
): Promise<BankService> { `taler-bank-manage -c '${cfgFilename}' django migrate`,
const config = new Configuration(); );
setTalerPaths(config, gc.testDir + "/talerhome"); await sh(
config.setString("taler", "currency", bc.currency); gc,
config.setString("bank", "database", bc.database); "taler-bank-manage_django",
config.setString("bank", "http_port", `${bc.httpPort}`); `taler-bank-manage -c '${cfgFilename}' django provide_accounts`,
config.setString("bank", "serve", "http"); );
config.setString("bank", "max_debt_bank", `${bc.currency}:999999`);
config.setString("bank", "max_debt", bc.maxDebt ?? `${bc.currency}:100`);
config.setString(
"bank",
"allow_registrations",
bc.allowRegistrations ? "yes" : "no",
);
const cfgFilename = gc.testDir + "/bank.conf";
config.write(cfgFilename);
await sh( return new BankService(gc, bc, cfgFilename);
gc, }
"taler-bank-manage_django",
`taler-bank-manage -c '${cfgFilename}' django migrate`,
);
await sh(
gc,
"taler-bank-manage_django",
`taler-bank-manage -c '${cfgFilename}' django provide_accounts`,
);
return new BankService(gc, bc, cfgFilename); setSuggestedExchange(e: ExchangeServiceInterface, exchangePayto: string) {
} const config = Configuration.load(this.configFile);
config.setString("bank", "suggested_exchange", e.baseUrl);
config.setString("bank", "suggested_exchange_payto", exchangePayto);
}
setSuggestedExchange(e: ExchangeServiceInterface, exchangePayto: string) { get baseUrl(): string {
const config = Configuration.load(this.configFile); return `http://localhost:${this.bankConfig.httpPort}/`;
config.setString("bank", "suggested_exchange", e.baseUrl); }
config.setString("bank", "suggested_exchange_payto", exchangePayto);
}
get baseUrl(): string { async createExchangeAccount(
return `http://localhost:${this.bankConfig.httpPort}/`; accountName: string,
} password: string,
): Promise<HarnessExchangeBankAccount> {
await sh(
this.globalTestState,
"taler-bank-manage_django",
`taler-bank-manage -c '${this.configFile}' django add_bank_account ${accountName}`,
);
await sh(
this.globalTestState,
"taler-bank-manage_django",
`taler-bank-manage -c '${this.configFile}' django changepassword_unsafe ${accountName} ${password}`,
);
await sh(
this.globalTestState,
"taler-bank-manage_django",
`taler-bank-manage -c '${this.configFile}' django top_up ${accountName} ${this.bankConfig.currency}:100000`,
);
return {
accountName: accountName,
accountPassword: password,
accountPaytoUri: `payto://x-taler-bank/${accountName}`,
wireGatewayApiBaseUrl: `http://localhost:${this.bankConfig.httpPort}/taler-wire-gateway/${accountName}/`,
};
}
async createExchangeAccount( get port() {
accountName: string, return this.bankConfig.httpPort;
password: string, }
): Promise<HarnessExchangeBankAccount> {
await sh(
this.globalTestState,
"taler-bank-manage_django",
`taler-bank-manage -c '${this.configFile}' django add_bank_account ${accountName}`,
);
await sh(
this.globalTestState,
"taler-bank-manage_django",
`taler-bank-manage -c '${this.configFile}' django changepassword_unsafe ${accountName} ${password}`,
);
await sh(
this.globalTestState,
"taler-bank-manage_django",
`taler-bank-manage -c '${this.configFile}' django top_up ${accountName} ${this.bankConfig.currency}:100000`,
);
return {
accountName: accountName,
accountPassword: password,
accountPaytoUri: `payto://x-taler-bank/${accountName}`,
wireGatewayApiBaseUrl: `http://localhost:${this.bankConfig.httpPort}/taler-wire-gateway/${accountName}/`,
};
}
get port() { private constructor(
return this.bankConfig.httpPort; private globalTestState: GlobalTestState,
} private bankConfig: BankConfig,
private configFile: string,
) {}
private constructor( async start(): Promise<void> {
private globalTestState: GlobalTestState, this.proc = this.globalTestState.spawnService(
private bankConfig: BankConfig, "taler-bank-manage",
private configFile: string, ["-c", this.configFile, "serve"],
) {} "bank",
);
}
async start(): Promise<void> { async pingUntilAvailable(): Promise<void> {
this.proc = this.globalTestState.spawnService( const url = `http://localhost:${this.bankConfig.httpPort}/config`;
"taler-bank-manage", await pingProc(this.proc, url, "bank");
["-c", this.configFile, "serve"],
"bank",
);
}
async pingUntilAvailable(): Promise<void> {
const url = `http://localhost:${this.bankConfig.httpPort}/config`;
await pingProc(this.proc, url, "bank");
}
} }
} }
import BankService = BankServices.PybankService;
export { BankService }; /**
* euFin migration:
*
* if (process.env.WALLET_HARNESS_WITH_EUFIN) {
* BankService.prototype = {
* // methods from euFin ..
* };
* }
*
*/
export class FakeBankService { export class FakeBankService {
proc: ProcessWrapper | undefined; proc: ProcessWrapper | undefined;

View File

@ -63,7 +63,7 @@ export interface SimpleTestEnvironment {
} }
export function getRandomIban(countryCode: string): string { export function getRandomIban(countryCode: string): string {
return `${countryCode}715001051796${Math.floor(Math.random() * 1000000)}`; return `${countryCode}715001051796${(Math.random().toString().substring(2, 8))}`
} }
export function getRandomString(): string { export function getRandomString(): string {