summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/testing.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/testing.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/testing.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts
index 9b5dd2a19..b21f1992c 100644
--- a/packages/taler-wallet-core/src/operations/testing.ts
+++ b/packages/taler-wallet-core/src/operations/testing.ts
@@ -23,6 +23,7 @@ import {
ConfirmPayResultType,
Duration,
IntegrationTestV2Args,
+ j2s,
Logger,
NotificationType,
RegisterAccountRequest,
@@ -31,6 +32,7 @@ import {
TestPayResult,
TransactionMajorState,
TransactionMinorState,
+ TransactionState,
TransactionType,
WithdrawTestBalanceRequest,
} from "@gnu-taler/taler-util";
@@ -494,6 +496,49 @@ async function waitUntilPendingReady(
cancelNotifs();
}
+/**
+ * Wait until a transaction is in a particular state.
+ */
+export async function waitTransactionState(
+ ws: InternalWalletState,
+ transactionId: string,
+ txState: TransactionState,
+): Promise<void> {
+ logger.info(
+ `starting waiting for ${transactionId} to be in ${JSON.stringify(
+ txState,
+ )})`,
+ );
+ ws.ensureTaskLoopRunning();
+ let p: OpenedPromise<void> | undefined = undefined;
+ const cancelNotifs = ws.addNotificationListener((notif) => {
+ if (!p) {
+ return;
+ }
+ if (notif.type === NotificationType.TransactionStateTransition) {
+ p.resolve();
+ }
+ });
+ while (1) {
+ p = openPromise();
+ const tx = await getTransactionById(ws, {
+ transactionId,
+ });
+ if (
+ tx.txState.major === txState.major &&
+ tx.txState.minor === txState.minor
+ ) {
+ break;
+ }
+ // Wait until transaction state changed
+ await p.promise;
+ }
+ logger.info(
+ `done waiting for ${transactionId} to be in ${JSON.stringify(txState)}`,
+ );
+ cancelNotifs();
+}
+
export async function runIntegrationTest2(
ws: InternalWalletState,
args: IntegrationTestV2Args,