get basic test cases to work with new exchange

This commit is contained in:
Florian Dold 2021-01-05 17:59:50 +01:00
parent 981ef46267
commit c032931f22
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 109 additions and 31 deletions

View File

@ -414,6 +414,7 @@ export interface BankConfig {
function setPaths(config: Configuration, home: string) {
config.setString("paths", "taler_home", home);
config.setString("paths", "taler_runtime_dir", "$TALER_HOME/taler-runtime/");
config.setString(
"paths",
"taler_data_home",
@ -851,7 +852,7 @@ export class ExchangeService implements ExchangeServiceInterface {
config.setString("exchange", "max_keys_caching", "forever");
config.setString("exchange", "db", "postgres");
config.setString(
"exchange",
"exchange-offline",
"master_priv_file",
"${TALER_DATA_HOME}/exchange/offline-keys/master.priv",
);
@ -862,19 +863,6 @@ export class ExchangeService implements ExchangeServiceInterface {
config.setString("exchange", "lookahead_sign", "32 weeks 1 day");
config.setString("exchange", "lookahead_provide", "4 weeks 1 day");
for (let i = 2020; i < 2029; i++) {
config.setString(
"fees-x-taler-bank",
`wire-fee-${i}`,
`${e.currency}:0.01`,
);
config.setString(
"fees-x-taler-bank",
`closing-fee-${i}`,
`${e.currency}:0.01`,
);
}
config.setString("exchangedb-postgres", "config", e.database);
const exchangeMasterKey = createEddsaKeyPair();
@ -886,7 +874,7 @@ export class ExchangeService implements ExchangeServiceInterface {
);
const masterPrivFile = config
.getPath("exchange", "master_priv_file")
.getPath("exchange-offline", "master_priv_file")
.required();
fs.mkdirSync(path.dirname(masterPrivFile), { recursive: true });
@ -963,6 +951,9 @@ export class ExchangeService implements ExchangeServiceInterface {
exchangeHttpProc: ProcessWrapper | undefined;
exchangeWirewatchProc: ProcessWrapper | undefined;
helperCryptoRsaProc: ProcessWrapper | undefined;
helperCryptoEddsaProc: ProcessWrapper | undefined;
constructor(
private globalState: GlobalTestState,
private exchangeConfig: ExchangeConfig,
@ -995,14 +986,85 @@ export class ExchangeService implements ExchangeServiceInterface {
await httpd.wait();
this.exchangeHttpProc = undefined;
}
const cryptoRsa = this.helperCryptoRsaProc;
if (cryptoRsa) {
cryptoRsa.proc.kill("SIGTERM");
await cryptoRsa.wait();
this.helperCryptoRsaProc = undefined;
}
const cryptoEddsa = this.helperCryptoEddsaProc;
if (cryptoEddsa) {
cryptoEddsa.proc.kill("SIGTERM");
await cryptoEddsa.wait();
this.helperCryptoRsaProc = undefined;
}
}
/**
* Update keys signing the keys generated by the security module
* with the offline signing key.
*/
async keyup(): Promise<void> {
await sh(
await runCommand(
this.globalState,
"exchange-keyup",
`taler-exchange-keyup ${this.timetravelArg} -c "${this.configFilename}"`,
"exchange-offline",
"taler-exchange-offline",
[
"-c",
this.configFilename,
...this.timetravelArgArr,
"download",
"sign",
"upload",
],
);
const accounts: string[] = [];
const config = Configuration.load(this.configFilename);
for (const sectionName of config.getSectionNames()) {
if (sectionName.startsWith("exchange-account")) {
accounts.push(config.getString(sectionName, "payto_uri").required());
}
}
console.log("configuring bank accounts", accounts);
for (const acc of accounts) {
await runCommand(
this.globalState,
"exchange-offline",
"taler-exchange-offline",
[
"-c",
this.configFilename,
...this.timetravelArgArr,
"enable-account",
acc,
"upload",
],
);
}
const year = new Date().getFullYear();
for (let i = year; i < year+5; i++) {
await runCommand(
this.globalState,
"exchange-offline",
"taler-exchange-offline",
[
"-c",
this.configFilename,
...this.timetravelArgArr,
"wire-fee",
`${i}`,
"x-taler-bank",
`${this.exchangeConfig.currency}:0.01`,
`${this.exchangeConfig.currency}:0.01`,
"upload",
],
);
}
}
async revokeDenomination(denomPubHash: string) {
@ -1032,11 +1094,17 @@ export class ExchangeService implements ExchangeServiceInterface {
"exchange-dbinit",
`taler-exchange-dbinit -c "${this.configFilename}"`,
);
await this.keyup();
await sh(
this.globalState,
"exchange-wire",
`taler-exchange-wire ${this.timetravelArg} -c "${this.configFilename}"`,
this.helperCryptoEddsaProc = this.globalState.spawnService(
"taler-helper-crypto-eddsa",
["-c", this.configFilename, ...this.timetravelArgArr],
`exchange-crypto-eddsa-${this.name}`,
);
this.helperCryptoRsaProc = this.globalState.spawnService(
"taler-helper-crypto-rsa",
["-c", this.configFilename, ...this.timetravelArgArr],
`exchange-crypto-rsa-${this.name}`,
);
this.exchangeWirewatchProc = this.globalState.spawnService(
@ -1056,6 +1124,8 @@ export class ExchangeService implements ExchangeServiceInterface {
],
`exchange-httpd-${this.name}`,
);
await this.keyup();
}
async pingUntilAvailable(): Promise<void> {

View File

@ -19,7 +19,7 @@
*
* Uses libtool's current:revision:age versioning.
*/
export const WALLET_EXCHANGE_PROTOCOL_VERSION = "8:0:0";
export const WALLET_EXCHANGE_PROTOCOL_VERSION = "9:0:0";
/**
* Protocol version spoken with the merchant.

View File

@ -1508,12 +1508,12 @@ class PurchasesStore extends Store<"purchases", PurchaseRecord> {
"fulfillmentUrlIndex",
string,
PurchaseRecord
>(this, "fulfillmentUrlIndex", "contractData.fulfillmentUrl");
>(this, "fulfillmentUrlIndex", "download.contractData.fulfillmentUrl");
orderIdIndex = new Index<"purchases", "orderIdIndex", string, PurchaseRecord>(
this,
"orderIdIndex",
["contractData.merchantBaseUrl", "contractData.orderId"],
["download.contractData.merchantBaseUrl", "download.contractData.orderId"],
);
}
@ -1602,11 +1602,12 @@ class PlanchetsStore extends Store<"planchets", PlanchetRecord> {
PlanchetRecord
>(this, "withdrawalGroupIndex", "withdrawalGroupId");
coinEvHashIndex = new Index<"planchets", "coinEvHashIndex", string, PlanchetRecord>(
this,
coinEvHashIndex = new Index<
"planchets",
"coinEvHashIndex",
"coinEvHash",
);
string,
PlanchetRecord
>(this, "coinEvHashIndex", "coinEvHash");
}
/**

View File

@ -213,6 +213,13 @@ export class Configuration {
sec[option.toUpperCase()] = value;
}
/**
* Get lower-cased section names.
*/
getSectionNames(): string[] {
return Object.keys(this.sectionMap).map((x) => x.toLowerCase());
}
getString(section: string, option: string): ConfigValue<string> {
const secNorm = section.toUpperCase();
const optNorm = option.toUpperCase();