taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 1997c2bb4945ec318de58d6f4c88b6649a514d61
parent 5e45a5a3e4d6185f348dfb0adf582788fba55233
Author: Florian Dold <florian@dold.me>
Date:   Wed, 11 Sep 2024 23:23:28 +0200

wallet-core: fix deposit kyc transition, also fix test

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-kyc-deposit-deposit.ts | 38++++++++++++++++++++------------------
Mpackages/taler-util/src/types-taler-wallet.ts | 2+-
Mpackages/taler-wallet-core/src/deposits.ts | 12++++++++++--
Mpackages/taler-wallet-core/src/testing.ts | 21+++++++++++++++++----
4 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-kyc-deposit-deposit.ts b/packages/taler-harness/src/integrationtests/test-kyc-deposit-deposit.ts @@ -18,6 +18,7 @@ * Imports. */ import { + Logger, TalerCorebankApiClient, TransactionMajorState, TransactionMinorState, @@ -45,6 +46,8 @@ import { withdrawViaBankV3, } from "../harness/helpers.js"; +const logger = new Logger("test-kyc-deposit-deposit.ts"); + interface KycTestEnv { commonDb: DbInfo; bankClient: TalerCorebankApiClient; @@ -232,22 +235,6 @@ export async function runKycDepositDepositTest(t: GlobalTestState) { }, ); - await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { - transactionId: depositResp.transactionId, - txState: { - major: TransactionMajorState.Pending, - minor: TransactionMinorState.Track, - }, - }); - - await exchange.runAggregatorOnceWithTimetravel({ - timetravelMicroseconds: 1000 * 1000 * 60 * 60 * 3, - }); - - await exchange.runTransferOnceWithTimetravel({ - timetravelMicroseconds: 1000 * 1000 * 60 * 60 * 3, - }); - console.log("waiting for kyc-required"); await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { @@ -276,12 +263,27 @@ export async function runKycDepositDepositTest(t: GlobalTestState) { paytoHash: kycPaytoHash, }); + logger.info(`made decision to have no rules on ${kycPaytoHash}`); + + await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { + transactionId: depositResp.transactionId, + txState: [ + { + major: TransactionMajorState.Done, + }, + { + major: TransactionMajorState.Pending, + minor: TransactionMinorState.Track, + }, + ], + }); + await exchange.runAggregatorOnceWithTimetravel({ - timetravelMicroseconds: 1000 * 1000 * 60 * 60 * 3, + timetravelMicroseconds: 1000 * 1000 * 60 * 60, }); await exchange.runTransferOnceWithTimetravel({ - timetravelMicroseconds: 1000 * 1000 * 60 * 60 * 3, + timetravelMicroseconds: 1000 * 1000 * 60 * 60, }); await walletClient.call(WalletApiOperation.TestingWaitTransactionState, { diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -3103,7 +3103,7 @@ export interface TestingWaitExchangeStateRequest { export interface TestingWaitTransactionRequest { transactionId: TransactionIdStr; - txState: TransactionState; + txState: TransactionState | TransactionState[]; } export interface TestingGetReserveHistoryRequest { diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts @@ -889,6 +889,10 @@ async function processDepositGroupPendingKyc( }, ); + logger.trace( + `request to ${kycStatusRes.requestUrl} returned status ${kycStatusRes.status}`, + ); + if ( kycStatusRes.status === HttpStatusCode.Ok || kycStatusRes.status === HttpStatusCode.NoContent @@ -905,7 +909,7 @@ async function processDepositGroupPendingKyc( case DepositOperationStatus.PendingAggregateKyc: newDg.operationStatus = DepositOperationStatus.PendingTrack; break; - case DepositOperationStatus.PendingDeposit: + case DepositOperationStatus.PendingDepositKyc: newDg.operationStatus = DepositOperationStatus.PendingDeposit; break; default: @@ -919,7 +923,11 @@ async function processDepositGroupPendingKyc( ); notifyTransition(wex, ctx.transactionId, transitionInfo); } else if (kycStatusRes.status === HttpStatusCode.Accepted) { - logger.info("kyc still pending"); + const statusResp = await readResponseJsonOrThrow( + kycStatusRes, + codecForAccountKycStatus(), + ); + logger.info(`kyc still pending (HTTP 202): ${j2s(statusResp)}`); } else { throwUnexpectedRequestError( kycStatusRes, diff --git a/packages/taler-wallet-core/src/testing.ts b/packages/taler-wallet-core/src/testing.ts @@ -583,7 +583,7 @@ async function waitUntilTransactionPendingReady( export async function waitTransactionState( wex: WalletExecutionContext, transactionId: string, - txState: TransactionState, + txState: TransactionState | TransactionState[], ): Promise<void> { logger.info( `starting waiting for ${transactionId} to be in ${JSON.stringify( @@ -595,9 +595,22 @@ export async function waitTransactionState( const tx = await getTransactionById(wex, { transactionId, }); - return ( - tx.txState.major === txState.major && tx.txState.minor === txState.minor - ); + if (Array.isArray(txState)) { + for (const myState of txState) { + if ( + tx.txState.major === myState.major && + tx.txState.minor === myState.minor + ) { + return true; + } + } + return false; + } else { + return ( + tx.txState.major === txState.major && + tx.txState.minor === txState.minor + ); + } }, filterNotification(notif) { return notif.type === NotificationType.TransactionStateTransition;