commit e63dfd6bb587ca65b2b418bf2e1851745b2da0b2
parent f98e841eeeeeff81cbcb4ba468b3e3b7ba9ca324
Author: Florian Dold <florian@dold.me>
Date: Mon, 17 Feb 2025 20:13:44 +0100
wallet cli: implement wait flag for testing withdrawal
Diffstat:
4 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts
@@ -43,6 +43,7 @@ import {
summarizeTalerErrorDetail,
TalerUriAction,
TransactionIdStr,
+ TransactionMajorState,
WalletNotification,
} from "@gnu-taler/taler-util";
import { clk } from "@gnu-taler/taler-util/clk";
@@ -57,7 +58,6 @@ import {
import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
import { JsonMessage, runRpcServer } from "@gnu-taler/taler-util/twrpc";
import {
- AccessStats,
createNativeWalletHost2,
nativeCrypto,
Wallet,
@@ -378,7 +378,10 @@ async function withWallet<T>(
await wh.wallet.client.call(WalletApiOperation.Shutdown, {});
if (process.env.TALER_WALLET_DBSTATS) {
console.log("database stats:");
- const stats = await wh.wallet.client.call(WalletApiOperation.TestingGetDbStats, {});
+ const stats = await wh.wallet.client.call(
+ WalletApiOperation.TestingGetDbStats,
+ {},
+ );
console.log(j2s(stats));
}
return result;
@@ -1750,21 +1753,53 @@ const testCli = walletCli.subcommand("testingArgs", "testing", {
testCli
.subcommand("withdrawTestkudos", "withdraw-testkudos")
+ .flag("wait", ["--wait"])
.action(async (args) => {
await withWallet(args, { lazyTaskLoop: true }, async (wallet) => {
- await wallet.client.call(WalletApiOperation.WithdrawTestkudos, {});
+ const resp = await wallet.client.call(
+ WalletApiOperation.WithdrawTestkudos,
+ {},
+ );
+ if (args.withdrawTestkudos.wait) {
+ await wallet.client.call(
+ WalletApiOperation.TestingWaitTransactionState,
+ {
+ transactionId: resp.transactionId,
+ txState: {
+ major: TransactionMajorState.Done,
+ },
+ },
+ );
+ }
});
});
-testCli.subcommand("withdrawKudos", "withdraw-kudos").action(async (args) => {
- await withWallet(args, { lazyTaskLoop: true }, async (wallet) => {
- await wallet.client.call(WalletApiOperation.WithdrawTestBalance, {
- amount: "KUDOS:50" as AmountString,
- corebankApiBaseUrl: "https://bank.demo.taler.net/",
- exchangeBaseUrl: "https://exchange.demo.taler.net/",
+testCli
+ .subcommand("withdrawKudos", "withdraw-kudos")
+ .flag("wait", ["--wait"])
+ .action(async (args) => {
+ await withWallet(args, { lazyTaskLoop: true }, async (wallet) => {
+ const resp = await wallet.client.call(
+ WalletApiOperation.WithdrawTestBalance,
+ {
+ amount: "KUDOS:50" as AmountString,
+ corebankApiBaseUrl: "https://bank.demo.taler.net/",
+ exchangeBaseUrl: "https://exchange.demo.taler.net/",
+ },
+ );
+ if (args.withdrawKudos.wait) {
+ await wallet.client.call(
+ WalletApiOperation.TestingWaitTransactionState,
+ {
+ transactionId: resp.transactionId,
+ txState: {
+ major: TransactionMajorState.Done,
+ },
+ },
+ );
+ }
});
});
-});
class PerfTimer {
tStarted: bigint | undefined;
diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts
@@ -45,6 +45,7 @@ import {
TalerCorebankApiClient,
TestPayArgs,
TestPayResult,
+ TransactionIdStr,
TransactionMajorState,
TransactionMinorState,
TransactionState,
@@ -100,7 +101,7 @@ export interface WithdrawTestBalanceResult {
/**
* Transaction ID of the newly created withdrawal transaction.
*/
- transactionId: string;
+ transactionId: TransactionIdStr;
/**
* Account of the user registered for the withdrawal.
diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts
@@ -178,6 +178,7 @@ import {
RunBackupCycleRequest,
} from "./backup/index.js";
import { PaymentBalanceDetails } from "./balance.js";
+import { WithdrawTestBalanceResult } from "./testing.js";
export enum WalletApiOperation {
InitWallet = "initWallet",
@@ -1170,7 +1171,7 @@ export type TestCryptoOp = {
export type WithdrawTestBalanceOp = {
op: WalletApiOperation.WithdrawTestBalance;
request: WithdrawTestBalanceRequest;
- response: EmptyObject;
+ response: WithdrawTestBalanceResult;
};
/**
@@ -1179,7 +1180,7 @@ export type WithdrawTestBalanceOp = {
export type WithdrawTestkudosOp = {
op: WalletApiOperation.WithdrawTestkudos;
request: EmptyObject;
- response: EmptyObject;
+ response: WithdrawTestBalanceResult;
};
/**
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
@@ -344,6 +344,7 @@ import {
getActiveTaskIds,
} from "./shepherd.js";
import {
+ WithdrawTestBalanceResult,
runIntegrationTest,
runIntegrationTest2,
testPay,
@@ -884,21 +885,18 @@ async function handleSetWalletRunConfig(
}
async function handleWithdrawTestkudos(wex: WalletExecutionContext) {
- await withdrawTestBalance(wex, {
+ return await withdrawTestBalance(wex, {
amount: "TESTKUDOS:10" as AmountString,
corebankApiBaseUrl: "https://bank.test.taler.net/",
exchangeBaseUrl: "https://exchange.test.taler.net/",
});
- // FIXME: Is this correct?
- return {};
}
async function handleWithdrawTestBalance(
wex: WalletExecutionContext,
req: WithdrawTestBalanceRequest,
-): Promise<EmptyObject> {
- await withdrawTestBalance(wex, req);
- return {};
+): Promise<WithdrawTestBalanceResult> {
+ return await withdrawTestBalance(wex, req);
}
async function handleRunIntegrationTest(