diff options
author | Florian Dold <florian@dold.me> | 2023-06-30 23:01:48 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-06-30 23:01:48 +0200 |
commit | 7a18e12a175856b3d17d2bb70ec549004c281ff5 (patch) | |
tree | 73b753a55458774aa646356c3d09ac1417458696 /packages/taler-wallet-core/src/operations | |
parent | 86e9799ffdfa5aab5a25cbce1d18881e0a3dfc3e (diff) | |
download | wallet-core-7a18e12a175856b3d17d2bb70ec549004c281ff5.tar.xz |
wallet-core: towards event-based waiting in runIntegrationTestV2
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts | 48 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/testing.ts | 44 |
2 files changed, 73 insertions, 19 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts index 4c00ed592..c7e13754f 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer-pull-credit.ts @@ -746,31 +746,37 @@ export async function initiatePeerPullPayment( undefined, ); - await ws.db + const transitionInfo = await ws.db .mktx((x) => [x.peerPullPaymentInitiations, x.contractTerms]) .runReadWrite(async (tx) => { - await tx.peerPullPaymentInitiations.put({ - amount: req.partialContractTerms.amount, - contractTermsHash: hContractTerms, - exchangeBaseUrl: exchangeBaseUrl, - pursePriv: pursePair.priv, - pursePub: pursePair.pub, - mergePriv: mergePair.priv, - mergePub: mergePair.pub, - status: PeerPullPaymentInitiationStatus.PendingCreatePurse, - contractTerms: contractTerms, - mergeTimestamp, - contractEncNonce, - mergeReserveRowId: mergeReserveRowId, - contractPriv: contractKeyPair.priv, - contractPub: contractKeyPair.pub, - withdrawalGroupId, - estimatedAmountEffective: wi.withdrawalAmountEffective, - }); + const ppi: PeerPullPaymentInitiationRecord = { + amount: req.partialContractTerms.amount, + contractTermsHash: hContractTerms, + exchangeBaseUrl: exchangeBaseUrl, + pursePriv: pursePair.priv, + pursePub: pursePair.pub, + mergePriv: mergePair.priv, + mergePub: mergePair.pub, + status: PeerPullPaymentInitiationStatus.PendingCreatePurse, + contractTerms: contractTerms, + mergeTimestamp, + contractEncNonce, + mergeReserveRowId: mergeReserveRowId, + contractPriv: contractKeyPair.priv, + contractPub: contractKeyPair.pub, + withdrawalGroupId, + estimatedAmountEffective: wi.withdrawalAmountEffective, + } + await tx.peerPullPaymentInitiations.put(ppi); + const oldTxState: TransactionState = { + major: TransactionMajorState.None, + }; + const newTxState = computePeerPullCreditTransactionState(ppi); await tx.contractTerms.put({ contractTermsRaw: contractTerms, h: hContractTerms, }); + return { oldTxState, newTxState }; }); const transactionId = constructTransactionIdentifier({ @@ -781,6 +787,10 @@ export async function initiatePeerPullPayment( // The pending-incoming balance has changed. ws.notify({ type: NotificationType.BalanceChange }); + notifyTransition(ws, transactionId, transitionInfo); + + ws.workAvailable.trigger(); + return { talerUri: stringifyTalerUri({ type: TalerUriAction.PayPull, diff --git a/packages/taler-wallet-core/src/operations/testing.ts b/packages/taler-wallet-core/src/operations/testing.ts index 77e218cd7..2a3584a0a 100644 --- a/packages/taler-wallet-core/src/operations/testing.ts +++ b/packages/taler-wallet-core/src/operations/testing.ts @@ -27,6 +27,8 @@ import { NotificationType, stringToBytes, TestPayResult, + TransactionMajorState, + TransactionMinorState, WithdrawTestBalanceRequest, } from "@gnu-taler/taler-util"; import { @@ -66,6 +68,7 @@ import { } from "./pay-peer-push-credit.js"; import { initiatePeerPushDebit } from "./pay-peer-push-debit.js"; import { OpenedPromise, openPromise } from "../index.js"; +import { getTransactionById } from "./transactions.js"; const logger = new Logger("operations/testing.ts"); @@ -459,10 +462,45 @@ async function waitUntilDone(ws: InternalWalletState): Promise<void> { }); } +async function waitUntilPendingReady( + ws: InternalWalletState, + transactionId: string, +): Promise<void> { + logger.info(`starting waiting for ${transactionId} to be in pending(ready)`); + ws.ensureTaskLoopRunning(); + let p: OpenedPromise<void> | undefined = undefined; + 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 == TransactionMajorState.Pending && + tx.txState.minor === TransactionMinorState.Ready + ) { + break; + } + // Wait until transaction state changed + await p.promise; + } + logger.info(`done waiting for ${transactionId} to be in pending(ready)`); + // FIXME: Remove listener! +} + export async function runIntegrationTest2( ws: InternalWalletState, args: IntegrationTestV2Args, ): Promise<void> { + // FIXME: Make sure that a task look is running, since we're + // waiting for notifications. logger.info("running test with arguments", args); const exchangeInfo = await updateExchangeFromUrl(ws, args.exchangeBaseUrl); @@ -565,6 +603,8 @@ export async function runIntegrationTest2( }, }); + await waitUntilPendingReady(ws, peerPushInit.transactionId); + const peerPushCredit = await preparePeerPushCredit(ws, { talerUri: peerPushInit.talerUri, }); @@ -586,6 +626,8 @@ export async function runIntegrationTest2( }, }); + await waitUntilPendingReady(ws, peerPullInit.transactionId); + const peerPullInc = await preparePeerPullDebit(ws, { talerUri: peerPullInit.talerUri, }); @@ -594,6 +636,8 @@ export async function runIntegrationTest2( peerPullPaymentIncomingId: peerPullInc.peerPullPaymentIncomingId, }); + await ws.runUntilDone(); + logger.trace("integration test: all done!"); } |