From 7d956c3a674fbf0ee3ddf0005c8789c1acd969c3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 24 Jan 2024 17:48:17 +0100 Subject: harness: implement command to generate wallet DB and data for migration tests --- packages/taler-harness/src/harness/harness.ts | 23 ++++----- packages/taler-harness/src/harness/helpers.ts | 2 +- packages/taler-harness/src/index.ts | 69 ++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 26 deletions(-) (limited to 'packages') diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts index a8cd1131d..b2714f496 100644 --- a/packages/taler-harness/src/harness/harness.ts +++ b/packages/taler-harness/src/harness/harness.ts @@ -1905,10 +1905,14 @@ export class WalletService { } get dbPath() { - return path.join( - this.globalState.testDir, - `walletdb-${this.opts.name}.json`, - ); + if (this.opts.useInMemoryDb) { + return ":memory:"; + } else { + return path.join( + this.globalState.testDir, + `walletdb-${this.opts.name}.sqlite3`, + ); + } } async stop(): Promise { @@ -1919,21 +1923,12 @@ export class WalletService { } async start(): Promise { - let dbPath: string; - if (this.opts.useInMemoryDb) { - dbPath = ":memory:"; - } else { - dbPath = path.join( - this.globalState.testDir, - `walletdb-${this.opts.name}.json`, - ); - } const unixPath = this.socketPath; this.walletProc = this.globalState.spawnService( "taler-wallet-cli", [ "--wallet-db", - dbPath, + this.dbPath, "-LTRACE", // FIXME: Make this configurable? "--no-throttle", // FIXME: Optionally do throttling for some tests? "advanced", diff --git a/packages/taler-harness/src/harness/helpers.ts b/packages/taler-harness/src/harness/helpers.ts index adf43f6d0..7daa6c3c5 100644 --- a/packages/taler-harness/src/harness/helpers.ts +++ b/packages/taler-harness/src/harness/helpers.ts @@ -385,7 +385,7 @@ export async function createSimpleTestkudosEnvironmentV2( const { walletClient, walletService } = await createWalletDaemonWithClient( t, - { name: "wallet" }, + { name: "wallet", persistent: true }, ); console.log("setup done!"); diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts index 84d2d60f0..5a0ccbd12 100644 --- a/packages/taler-harness/src/index.ts +++ b/packages/taler-harness/src/index.ts @@ -33,7 +33,7 @@ import { generateIban, j2s, rsaBlind, - setGlobalLogLevelFromString + setGlobalLogLevelFromString, } from "@gnu-taler/taler-util"; import { clk } from "@gnu-taler/taler-util/clk"; import { @@ -43,6 +43,7 @@ import { import { CryptoDispatcher, SynchronousCryptoWorkerFactoryPlain, + WalletApiOperation, downloadExchangeInfo, topupReserveWithDemobank, } from "@gnu-taler/taler-wallet-core"; @@ -62,6 +63,7 @@ import { } from "./harness/harness.js"; import { getTestInfo, runTests } from "./integrationtests/testrunner.js"; import { lintExchangeDeployment } from "./lint.js"; +import { createSimpleTestkudosEnvironmentV2 } from "./harness/helpers.js"; const logger = new Logger("taler-harness:index.ts"); @@ -177,9 +179,61 @@ advancedCli await runTestWithState(testState, runEnv1, "env1", true); }); -const sandcastleCli = testingCli.subcommand("sandcastleArgs", "sandcastle", { - help: "Subcommands for handling GNU Taler sandcastle deployments.", -}); +advancedCli + .subcommand("walletDbgen", "wallet-dbgen", { + help: "Generate a wallet test database (to be used for migration testing).", + }) + .requiredArgument("outdir", clk.STRING) + .action(async (args) => { + const outdir = args.walletDbgen.outdir; + fs.mkdirSync(outdir, { + recursive: true, + }); + + const testRootDir = fs.mkdtempSync(path.join(os.tmpdir(), "taler-dbgen-")); + console.log(`generating data in ${testRootDir}`); + const t = new GlobalTestState({ + testDir: testRootDir, + }); + const { walletClient, walletService, bank, exchange, merchant } = + await createSimpleTestkudosEnvironmentV2(t); + await walletClient.call(WalletApiOperation.RunIntegrationTestV2, { + amountToSpend: "TESTKUDOS:5" as AmountString, + amountToWithdraw: "TESTKUDOS:10" as AmountString, + corebankApiBaseUrl: bank.corebankApiBaseUrl, + exchangeBaseUrl: exchange.baseUrl, + merchantBaseUrl: merchant.makeInstanceBaseUrl(), + }); + await walletClient.call( + WalletApiOperation.TestingWaitTransactionsFinal, + {}, + ); + + const transactionsJson = walletClient.call( + WalletApiOperation.GetTransactions, + { + includeRefreshes: true, + }, + ); + + const balancesJson = walletClient.call(WalletApiOperation.GetBalances, {}); + + const backupJson = walletClient.call(WalletApiOperation.ExportDb, {}); + + await walletService.stop(); + + await t.shutdown(); + + console.log(`generated data in ${testRootDir}`); + + fs.copyFileSync(walletService.dbPath, `${outdir}/wallet-db.sqlite3`); + fs.writeFileSync( + `${outdir}/wallet-transactions.json`, + j2s(transactionsJson), + ); + fs.writeFileSync(`${outdir}/wallet-balances.json`, j2s(balancesJson)); + fs.writeFileSync(`${outdir}/wallet-backup.json`, j2s(backupJson)); + }); const configCli = testingCli.subcommand("configArgs", "config", { help: "Subcommands for handling the Taler configuration.", @@ -653,13 +707,6 @@ deploymentCli process.exit(2); }); -type TestResult = { - testName: string; - caseName: string; - result: "skiped" | "ok" | "fail"; - error?: any; -}; - deploymentCli .subcommand("coincfg", "gen-coin-config", { help: "Generate a coin/denomination configuration for the exchange.", -- cgit v1.2.3