2022-03-14 18:31:30 +01:00
|
|
|
/*
|
|
|
|
This file is part of GNU Taler
|
|
|
|
(C) 2022 Taler Systems S.A.
|
|
|
|
|
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
buildCodecForObject,
|
|
|
|
codecForNumber,
|
|
|
|
codecForString,
|
|
|
|
codecOptional,
|
|
|
|
Logger,
|
|
|
|
} from "@gnu-taler/taler-util";
|
2023-02-15 23:32:42 +01:00
|
|
|
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
|
2022-03-14 18:31:30 +01:00
|
|
|
import {
|
2022-03-15 17:51:05 +01:00
|
|
|
checkReserve,
|
|
|
|
createFakebankReserve,
|
2022-03-23 21:24:23 +01:00
|
|
|
CryptoDispatcher,
|
2022-03-15 17:51:05 +01:00
|
|
|
depositCoin,
|
2022-03-14 18:31:30 +01:00
|
|
|
downloadExchangeInfo,
|
2022-03-15 17:51:05 +01:00
|
|
|
findDenomOrThrow,
|
|
|
|
refreshCoin,
|
2023-02-15 23:32:42 +01:00
|
|
|
SynchronousCryptoWorkerFactoryPlain,
|
2023-04-24 18:13:20 +02:00
|
|
|
Wallet,
|
2022-03-15 17:51:05 +01:00
|
|
|
withdrawCoin,
|
2022-03-14 18:31:30 +01:00
|
|
|
} from "@gnu-taler/taler-wallet-core";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point for the benchmark.
|
|
|
|
*
|
|
|
|
* The benchmark runs against an existing Taler deployment and does not
|
|
|
|
* set up its own services.
|
|
|
|
*/
|
|
|
|
export async function runBench2(configJson: any): Promise<void> {
|
2022-05-09 14:28:12 +02:00
|
|
|
const logger = new Logger("Bench2");
|
2022-03-14 18:31:30 +01:00
|
|
|
|
|
|
|
// Validate the configuration file for this benchmark.
|
2022-03-15 17:51:05 +01:00
|
|
|
const benchConf = codecForBench2Config().decode(configJson);
|
|
|
|
const curr = benchConf.currency;
|
2023-01-19 20:16:42 +01:00
|
|
|
const cryptoDisp = new CryptoDispatcher(
|
2023-02-15 23:32:42 +01:00
|
|
|
new SynchronousCryptoWorkerFactoryPlain(),
|
2023-01-19 20:16:42 +01:00
|
|
|
);
|
2022-03-23 21:24:23 +01:00
|
|
|
const cryptoApi = cryptoDisp.cryptoApi;
|
2022-03-15 17:51:05 +01:00
|
|
|
|
2023-02-15 23:32:42 +01:00
|
|
|
const http = createPlatformHttpLib({
|
|
|
|
enableThrottling: false,
|
2023-04-24 18:13:20 +02:00
|
|
|
allowHttp: true,
|
2023-02-15 23:32:42 +01:00
|
|
|
});
|
2022-03-15 17:51:05 +01:00
|
|
|
|
|
|
|
const numIter = benchConf.iterations ?? 1;
|
|
|
|
const numDeposits = benchConf.deposits ?? 5;
|
|
|
|
|
|
|
|
const reserveAmount = (numDeposits + 1) * 10;
|
|
|
|
|
|
|
|
for (let i = 0; i < numIter; i++) {
|
|
|
|
const exchangeInfo = await downloadExchangeInfo(benchConf.exchange, http);
|
|
|
|
|
2022-03-24 01:59:08 +01:00
|
|
|
const reserveKeyPair = await cryptoApi.createEddsaKeypair({});
|
2022-03-15 17:51:05 +01:00
|
|
|
|
|
|
|
console.log("creating fakebank reserve");
|
|
|
|
|
|
|
|
await createFakebankReserve({
|
|
|
|
amount: `${curr}:${reserveAmount}`,
|
|
|
|
exchangeInfo,
|
|
|
|
fakebankBaseUrl: benchConf.bank,
|
|
|
|
http,
|
2022-03-24 01:59:08 +01:00
|
|
|
reservePub: reserveKeyPair.pub,
|
2022-03-15 17:51:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
console.log("waiting for reserve");
|
|
|
|
|
2022-03-24 01:59:08 +01:00
|
|
|
await checkReserve(http, benchConf.exchange, reserveKeyPair.pub);
|
2022-03-14 18:31:30 +01:00
|
|
|
|
2022-03-15 17:51:05 +01:00
|
|
|
console.log("reserve found");
|
2022-03-14 18:31:30 +01:00
|
|
|
|
2023-04-24 18:13:20 +02:00
|
|
|
const d1 = findDenomOrThrow(exchangeInfo, `${curr}:8`, {
|
|
|
|
denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate,
|
|
|
|
});
|
2022-03-15 17:51:05 +01:00
|
|
|
|
|
|
|
for (let j = 0; j < numDeposits; j++) {
|
|
|
|
console.log("withdrawing coin");
|
|
|
|
const coin = await withdrawCoin({
|
|
|
|
http,
|
|
|
|
cryptoApi,
|
2022-03-24 01:59:08 +01:00
|
|
|
reserveKeyPair: {
|
|
|
|
reservePriv: reserveKeyPair.priv,
|
|
|
|
reservePub: reserveKeyPair.pub,
|
|
|
|
},
|
2022-03-15 17:51:05 +01:00
|
|
|
denom: d1,
|
|
|
|
exchangeBaseUrl: benchConf.exchange,
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("depositing coin");
|
|
|
|
|
|
|
|
await depositCoin({
|
|
|
|
amount: `${curr}:4`,
|
|
|
|
coin: coin,
|
|
|
|
cryptoApi,
|
|
|
|
exchangeBaseUrl: benchConf.exchange,
|
|
|
|
http,
|
|
|
|
depositPayto: benchConf.payto,
|
|
|
|
});
|
|
|
|
|
|
|
|
const refreshDenoms = [
|
2023-04-24 18:13:20 +02:00
|
|
|
findDenomOrThrow(exchangeInfo, `${curr}:1`, {
|
|
|
|
denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate,
|
|
|
|
}),
|
|
|
|
findDenomOrThrow(exchangeInfo, `${curr}:1`, {
|
|
|
|
denomselAllowLate: Wallet.defaultConfig.testing.denomselAllowLate,
|
|
|
|
}),
|
2022-03-15 17:51:05 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
console.log("refreshing coin");
|
|
|
|
|
|
|
|
await refreshCoin({
|
|
|
|
oldCoin: coin,
|
|
|
|
cryptoApi,
|
|
|
|
http,
|
|
|
|
newDenoms: refreshDenoms,
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("refresh done");
|
|
|
|
}
|
|
|
|
}
|
2022-03-14 18:31:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format of the configuration file passed to the benchmark
|
|
|
|
*/
|
|
|
|
interface Bench2Config {
|
|
|
|
/**
|
|
|
|
* Base URL of the bank.
|
|
|
|
*/
|
|
|
|
bank: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Payto url for deposits.
|
|
|
|
*/
|
|
|
|
payto: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base URL of the exchange.
|
|
|
|
*/
|
|
|
|
exchange: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How many withdraw/deposit iterations should be made?
|
|
|
|
* Defaults to 1.
|
|
|
|
*/
|
|
|
|
iterations?: number;
|
|
|
|
|
|
|
|
currency: string;
|
|
|
|
|
|
|
|
deposits?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schema validation codec for Bench1Config.
|
|
|
|
*/
|
2022-03-15 17:51:05 +01:00
|
|
|
const codecForBench2Config = () =>
|
2022-03-14 18:31:30 +01:00
|
|
|
buildCodecForObject<Bench2Config>()
|
|
|
|
.property("bank", codecForString())
|
|
|
|
.property("payto", codecForString())
|
|
|
|
.property("exchange", codecForString())
|
|
|
|
.property("iterations", codecOptional(codecForNumber()))
|
|
|
|
.property("deposits", codecOptional(codecForNumber()))
|
|
|
|
.property("currency", codecForString())
|
2022-03-15 17:51:05 +01:00
|
|
|
.build("Bench2Config");
|