From 825d2c4352022e7397854b2bd9ba7d3589873c07 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 15 Feb 2023 23:32:42 +0100 Subject: make wallet-cli runnable under qtart --- packages/taler-harness/src/bench1.ts | 17 +++++++++-------- packages/taler-harness/src/bench2.ts | 11 ++++++----- packages/taler-harness/src/bench3.ts | 15 ++++++++------- packages/taler-harness/src/harness/harness.ts | 9 ++++----- packages/taler-harness/src/index.ts | 13 +++++++++++-- .../src/integrationtests/test-exchange-timetravel.ts | 10 +++------- packages/taler-harness/src/integrationtests/test-kyc.ts | 14 +++++++++----- .../test-merchant-spec-public-orders.ts | 5 +++-- .../src/integrationtests/test-payment-on-demo.ts | 4 ++-- .../src/integrationtests/test-wallet-cryptoworker.ts | 13 ------------- .../src/integrationtests/test-wallet-dbless.ts | 11 +++++------ packages/taler-harness/src/lint.ts | 10 +++++----- 12 files changed, 65 insertions(+), 67 deletions(-) (limited to 'packages/taler-harness/src') diff --git a/packages/taler-harness/src/bench1.ts b/packages/taler-harness/src/bench1.ts index 84786d25a..0a4118ec1 100644 --- a/packages/taler-harness/src/bench1.ts +++ b/packages/taler-harness/src/bench1.ts @@ -19,19 +19,19 @@ */ import { buildCodecForObject, + codecForBoolean, codecForNumber, codecForString, - codecForBoolean, codecOptional, j2s, Logger, } from "@gnu-taler/taler-util"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { - getDefaultNodeWallet2, - NodeHttpLib, - WalletApiOperation, - Wallet, AccessStats, + createNativeWalletHost2, + Wallet, + WalletApiOperation, } from "@gnu-taler/taler-wallet-core"; /** @@ -46,8 +46,9 @@ export async function runBench1(configJson: any): Promise { // Validate the configuration file for this benchmark. const b1conf = codecForBench1Config().decode(configJson); - const myHttpLib = new NodeHttpLib(); - myHttpLib.setThrottling(false); + const myHttpLib = createPlatformHttpLib({ + enableThrottling: false, + }); const numIter = b1conf.iterations ?? 1; const numDeposits = b1conf.deposits ?? 5; @@ -81,7 +82,7 @@ export async function runBench1(configJson: any): Promise { console.log("wallet DB stats", j2s(getDbStats!())); } - const res = await getDefaultNodeWallet2({ + const res = await createNativeWalletHost2({ // No persistent DB storage. persistentStoragePath: undefined, httpLib: myHttpLib, diff --git a/packages/taler-harness/src/bench2.ts b/packages/taler-harness/src/bench2.ts index 9fa5d7caf..ff87da52a 100644 --- a/packages/taler-harness/src/bench2.ts +++ b/packages/taler-harness/src/bench2.ts @@ -24,6 +24,7 @@ import { codecOptional, Logger, } from "@gnu-taler/taler-util"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { checkReserve, createFakebankReserve, @@ -31,9 +32,8 @@ import { depositCoin, downloadExchangeInfo, findDenomOrThrow, - NodeHttpLib, refreshCoin, - SynchronousCryptoWorkerFactoryNode, + SynchronousCryptoWorkerFactoryPlain, withdrawCoin, } from "@gnu-taler/taler-wallet-core"; @@ -50,12 +50,13 @@ export async function runBench2(configJson: any): Promise { const benchConf = codecForBench2Config().decode(configJson); const curr = benchConf.currency; const cryptoDisp = new CryptoDispatcher( - new SynchronousCryptoWorkerFactoryNode(), + new SynchronousCryptoWorkerFactoryPlain(), ); const cryptoApi = cryptoDisp.cryptoApi; - const http = new NodeHttpLib(); - http.setThrottling(false); + const http = createPlatformHttpLib({ + enableThrottling: false, + }); const numIter = benchConf.iterations ?? 1; const numDeposits = benchConf.deposits ?? 5; diff --git a/packages/taler-harness/src/bench3.ts b/packages/taler-harness/src/bench3.ts index 9679f05a6..5e8fac0e9 100644 --- a/packages/taler-harness/src/bench3.ts +++ b/packages/taler-harness/src/bench3.ts @@ -25,12 +25,12 @@ import { j2s, Logger, } from "@gnu-taler/taler-util"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { - getDefaultNodeWallet2, - NodeHttpLib, - WalletApiOperation, - Wallet, AccessStats, + createNativeWalletHost2, + Wallet, + WalletApiOperation, } from "@gnu-taler/taler-wallet-core"; import benchMerchantIDGenerator from "./benchMerchantIDGenerator.js"; @@ -50,8 +50,9 @@ export async function runBench3(configJson: any): Promise { throw new Error("Payto template url must contain '${id}' placeholder"); } - const myHttpLib = new NodeHttpLib(); - myHttpLib.setThrottling(false); + const myHttpLib = createPlatformHttpLib({ + enableThrottling: false, + }); const numIter = b3conf.iterations ?? 1; const numDeposits = b3conf.deposits ?? 5; @@ -89,7 +90,7 @@ export async function runBench3(configJson: any): Promise { console.log("wallet DB stats", j2s(getDbStats!())); } - const res = await getDefaultNodeWallet2({ + const res = await createNativeWalletHost2({ // No persistent DB storage. persistentStoragePath: undefined, httpLib: myHttpLib, diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index 0b7ba14cf..518b98d82 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -41,17 +41,15 @@ import { MerchantTemplateAddDetails, parsePaytoUri, stringToBytes, + TalerError, TalerProtocolDuration, WalletNotification, } from "@gnu-taler/taler-util"; import { - BankAccessApi, BankApi, BankServiceHandle, HarnessExchangeBankAccount, - NodeHttpLib, openPromise, - TalerError, WalletCoreApiClient, } from "@gnu-taler/taler-wallet-core"; import { deepStrictEqual } from "assert"; @@ -83,6 +81,7 @@ import { RemoteWallet, WalletNotificationWaiter, } from "@gnu-taler/taler-wallet-core/remote"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; const logger = new Logger("harness.ts"); @@ -507,7 +506,7 @@ class LibEuFinBankService extends BankServiceBase implements BankServiceHandle { sandboxProc: ProcessWrapper | undefined; nexusProc: ProcessWrapper | undefined; - http = new NodeHttpLib(); + http = createPlatformHttpLib(); static async create( gc: GlobalTestState, @@ -794,7 +793,7 @@ export class FakebankService { proc: ProcessWrapper | undefined; - http = new NodeHttpLib(); + http = createPlatformHttpLib(); // We store "created" accounts during setup and // register them after startup. diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index e4ee25dae..14b8a4302 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -23,7 +23,6 @@ import os from "os"; import path from "path"; import { Amounts, - clk, Configuration, decodeCrock, Logger, @@ -38,6 +37,7 @@ import { GlobalTestState, runTestWithState } from "./harness/harness.js"; import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; import { lintExchangeDeployment } from "./lint.js"; import { runEnvFull } from "./env-full.js"; +import { clk } from "@gnu-taler/taler-util/clk"; const logger = new Logger("taler-harness:index.ts"); @@ -74,6 +74,15 @@ const advancedCli = testingCli.subcommand("advancedArgs", "advanced", { help: "Subcommands for advanced operations (only use if you know what you're doing!).", }); +advancedCli + .subcommand("decode", "decode", { + help: "Decode base32-crockford.", + }) + .action((args) => { + const enc = fs.readFileSync(0, "utf8"); + console.log(decodeCrock(enc.trim())); + }); + advancedCli .subcommand("bench1", "bench1", { help: "Run the 'bench1' benchmark", @@ -272,7 +281,7 @@ testingCli help: "Produce less output.", }) .flag("noTimeout", ["--no-timeout"], { - help: "Do not time out tests." + help: "Do not time out tests.", }) .action(async (args) => { await runTests({ diff --git a/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts b/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts index 074126e9f..20285cb6a 100644 --- a/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts +++ b/packages/taler-harness/src/integrationtests/test-exchange-timetravel.ts @@ -24,22 +24,18 @@ import { Duration, durationFromSpec, } from "@gnu-taler/taler-util"; -import { - NodeHttpLib, - readSuccessResponseJsonOrThrow, -} from "@gnu-taler/taler-wallet-core"; +import { createPlatformHttpLib, readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; import { makeNoFeeCoinConfig } from "../harness/denomStructures.js"; import { BankService, ExchangeService, GlobalTestState, - MerchantPrivateApi, MerchantService, setupDb, WalletCli, getPayto, } from "../harness/harness.js"; -import { startWithdrawViaBank, withdrawViaBank } from "../harness/helpers.js"; +import { withdrawViaBank } from "../harness/helpers.js"; async function applyTimeTravel( timetravelDuration: Duration, @@ -69,7 +65,7 @@ async function applyTimeTravel( } } -const http = new NodeHttpLib(); +const http = createPlatformHttpLib(); /** * Basic time travel test. diff --git a/packages/taler-harness/src/integrationtests/test-kyc.ts b/packages/taler-harness/src/integrationtests/test-kyc.ts index 490673cee..915c3d470 100644 --- a/packages/taler-harness/src/integrationtests/test-kyc.ts +++ b/packages/taler-harness/src/integrationtests/test-kyc.ts @@ -17,11 +17,14 @@ /** * Imports. */ -import { Duration, j2s, NotificationType } from "@gnu-taler/taler-util"; +import { + Duration, + j2s, + NotificationType, +} from "@gnu-taler/taler-util"; import { BankAccessApi, BankApi, - NodeHttpLib, WalletApiOperation, } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; @@ -37,6 +40,7 @@ import { } from "../harness/harness.js"; import { EnvOptions, SimpleTestEnvironmentNg } from "../harness/helpers.js"; import * as http from "node:http"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; export async function createKycTestkudosEnvironment( t: GlobalTestState, @@ -336,12 +340,12 @@ export async function runKycTest(t: GlobalTestState) { // We now simulate the user interacting with the KYC service, // which would usually done in the browser. - const httpClient = new NodeHttpLib(); - const kycServerResp = await httpClient.get(kycNotif.kycUrl); + const httpLib = createPlatformHttpLib(); + const kycServerResp = await httpLib.get(kycNotif.kycUrl); const kycLoginResp = await kycServerResp.json(); console.log("kyc server resp:", j2s(kycLoginResp)); const kycProofUrl = kycLoginResp.redirect_uri; - const proofHttpResp = await httpClient.get(kycProofUrl); + const proofHttpResp = await httpLib.get(kycProofUrl); console.log("proof resp status", proofHttpResp.status); console.log("resp headers", proofHttpResp.headers.toJSON()); diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts index 70edaaf0c..2fafe7584 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts @@ -24,7 +24,8 @@ import { encodeCrock, getRandomBytes, } from "@gnu-taler/taler-util"; -import { NodeHttpLib, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { BankService, ExchangeService, @@ -38,7 +39,7 @@ import { withdrawViaBank, } from "../harness/helpers.js"; -const httpLib = new NodeHttpLib(); +const httpLib = createPlatformHttpLib(); interface Context { merchant: MerchantService; diff --git a/packages/taler-harness/src/integrationtests/test-payment-on-demo.ts b/packages/taler-harness/src/integrationtests/test-payment-on-demo.ts index 737620ce7..22e88c8a0 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-on-demo.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-on-demo.ts @@ -24,8 +24,8 @@ import { BankApi, BankAccessApi, BankServiceHandle, - NodeHttpLib, } from "@gnu-taler/taler-wallet-core"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; /** * Run test for basic, bank-integrated withdrawal and payment. @@ -35,7 +35,7 @@ export async function runPaymentDemoTest(t: GlobalTestState) { let bankInterface: BankServiceHandle = { baseUrl: "https://bank.demo.taler.net/", bankAccessApiBaseUrl: "https://bank.demo.taler.net/", - http: new NodeHttpLib(), + http: createPlatformHttpLib(), }; let user = await BankApi.createRandomBankUser(bankInterface); let wop = await BankAccessApi.createWithdrawalOperation( diff --git a/packages/taler-harness/src/integrationtests/test-wallet-cryptoworker.ts b/packages/taler-harness/src/integrationtests/test-wallet-cryptoworker.ts index a9f1c4d80..6c2006636 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-cryptoworker.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-cryptoworker.ts @@ -17,23 +17,10 @@ /** * Imports. */ -import { j2s } from "@gnu-taler/taler-util"; import { - checkReserve, - CryptoDispatcher, - depositCoin, - downloadExchangeInfo, - findDenomOrThrow, - NodeHttpLib, - refreshCoin, - SynchronousCryptoWorkerFactoryNode, - TalerError, - topupReserveWithDemobank, WalletApiOperation, - withdrawCoin, } from "@gnu-taler/taler-wallet-core"; import { GlobalTestState, WalletCli } from "../harness/harness.js"; -import { createSimpleTestkudosEnvironment } from "../harness/helpers.js"; /** * Run test for the different crypto workers. diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts index 7692f12b2..08c10fd91 100644 --- a/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts +++ b/packages/taler-harness/src/integrationtests/test-wallet-dbless.ts @@ -17,17 +17,16 @@ /** * Imports. */ -import { j2s } from "@gnu-taler/taler-util"; +import { j2s, TalerError } from "@gnu-taler/taler-util"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; import { checkReserve, CryptoDispatcher, depositCoin, downloadExchangeInfo, findDenomOrThrow, - NodeHttpLib, refreshCoin, - SynchronousCryptoWorkerFactoryNode, - TalerError, + SynchronousCryptoWorkerFactoryPlain, topupReserveWithDemobank, withdrawCoin, } from "@gnu-taler/taler-wallet-core"; @@ -42,9 +41,9 @@ export async function runWalletDblessTest(t: GlobalTestState) { const { bank, exchange } = await createSimpleTestkudosEnvironment(t); - const http = new NodeHttpLib(); + const http = createPlatformHttpLib(); const cryptiDisp = new CryptoDispatcher( - new SynchronousCryptoWorkerFactoryNode(), + new SynchronousCryptoWorkerFactoryPlain(), ); const cryptoApi = cryptiDisp.cryptoApi; diff --git a/packages/taler-harness/src/lint.ts b/packages/taler-harness/src/lint.ts index 49fb9dc86..3d3805e79 100644 --- a/packages/taler-harness/src/lint.ts +++ b/packages/taler-harness/src/lint.ts @@ -37,13 +37,13 @@ import { Configuration, decodeCrock, } from "@gnu-taler/taler-util"; -import { - NodeHttpLib, - readSuccessResponseJsonOrThrow, -} from "@gnu-taler/taler-wallet-core"; import { URL } from "url"; import { spawn } from "child_process"; import { delayMs } from "./harness/harness.js"; +import { + createPlatformHttpLib, + readSuccessResponseJsonOrThrow, +} from "@gnu-taler/taler-util/http"; interface BasicConf { mainCurrency: string; @@ -53,7 +53,7 @@ interface PubkeyConf { masterPublicKey: string; } -const httpLib = new NodeHttpLib(); +const httpLib = createPlatformHttpLib(); interface ShellResult { stdout: string; -- cgit v1.2.3