gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated (102466500 -> f1e6fe173)


From: gnunet
Subject: [taler-wallet-core] branch master updated (102466500 -> f1e6fe173)
Date: Thu, 09 Nov 2023 14:54:28 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a change to branch master
in repository wallet-core.

    from 102466500 floor when moving from ms to secs
     new 7e3d6938b wallet-core: fix bogus timestamp logic
     new f1e6fe173 wallet-core: deliver kyc URL via experimental user data

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/integrationtests/test-wallettesting.ts     | 56 +++++++------
 packages/taler-util/src/notifications.ts           | 13 ++-
 packages/taler-util/src/time.test.ts               |  2 +-
 packages/taler-wallet-core/src/db.ts               |  2 +-
 .../taler-wallet-core/src/operations/testing.ts    | 60 ++++++--------
 .../src/operations/transactions.ts                 | 93 +++++++++++-----------
 .../taler-wallet-core/src/operations/withdraw.ts   | 21 +++--
 7 files changed, 128 insertions(+), 119 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-wallettesting.ts 
b/packages/taler-harness/src/integrationtests/test-wallettesting.ts
index 69637b875..6b4444d07 100644
--- a/packages/taler-harness/src/integrationtests/test-wallettesting.ts
+++ b/packages/taler-harness/src/integrationtests/test-wallettesting.ts
@@ -34,7 +34,11 @@ import {
   WalletCli,
   generateRandomPayto,
 } from "../harness/harness.js";
-import { SimpleTestEnvironment } from "../harness/helpers.js";
+import {
+  SimpleTestEnvironment,
+  SimpleTestEnvironmentNg,
+  createWalletDaemonWithClient,
+} from "../harness/helpers.js";
 
 const merchantAuthToken = "secret-token:sandbox";
 
@@ -45,7 +49,7 @@ const merchantAuthToken = "secret-token:sandbox";
 export async function createMyEnvironment(
   t: GlobalTestState,
   coinConfig: CoinConfig[] = defaultCoinConfig.map((x) => x("TESTKUDOS")),
-): Promise<SimpleTestEnvironment> {
+): Promise<SimpleTestEnvironmentNg> {
   const db = await setupDb(t);
 
   const bank = await BankService.create(t, {
@@ -99,13 +103,19 @@ export async function createMyEnvironment(
 
   console.log("setup done!");
 
-  const wallet = new WalletCli(t);
+  const { walletClient, walletService } = await createWalletDaemonWithClient(
+    t,
+    {
+      name: "w1",
+    },
+  );
 
   return {
     commonDb: db,
     exchange,
     merchant,
-    wallet,
+    walletClient,
+    walletService,
     bank,
     exchangeBankAccount,
   };
@@ -115,9 +125,11 @@ export async function createMyEnvironment(
  * Run test for basic, bank-integrated withdrawal.
  */
 export async function runWallettestingTest(t: GlobalTestState) {
-  const { wallet, bank, exchange, merchant } = await createMyEnvironment(t);
+  const { walletClient, bank, exchange, merchant } = await createMyEnvironment(
+    t,
+  );
 
-  await wallet.client.call(WalletApiOperation.RunIntegrationTest, {
+  await walletClient.call(WalletApiOperation.RunIntegrationTest, {
     amountToSpend: "TESTKUDOS:5" as AmountString,
     amountToWithdraw: "TESTKUDOS:10" as AmountString,
     corebankApiBaseUrl: bank.corebankApiBaseUrl,
@@ -126,7 +138,7 @@ export async function runWallettestingTest(t: 
GlobalTestState) {
     merchantBaseUrl: merchant.makeInstanceBaseUrl(),
   });
 
-  let txns = await wallet.client.call(WalletApiOperation.GetTransactions, {});
+  let txns = await walletClient.call(WalletApiOperation.GetTransactions, {});
   console.log(JSON.stringify(txns, undefined, 2));
   let txTypes = txns.transactions.map((x) => x.type);
 
@@ -139,42 +151,42 @@ export async function runWallettestingTest(t: 
GlobalTestState) {
     "payment",
   ]);
 
-  wallet.deleteDatabase();
+  await walletClient.call(WalletApiOperation.ClearDb, {});
 
-  await wallet.client.call(WalletApiOperation.WithdrawTestBalance, {
+  await walletClient.call(WalletApiOperation.WithdrawTestBalance, {
     amount: "TESTKUDOS:10" as AmountString,
     corebankApiBaseUrl: bank.corebankApiBaseUrl,
     exchangeBaseUrl: exchange.baseUrl,
   });
 
-  await wallet.runUntilDone();
+  await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
 
-  await wallet.client.call(WalletApiOperation.TestPay, {
+  await walletClient.call(WalletApiOperation.TestPay, {
     amount: "TESTKUDOS:5" as AmountString,
     merchantAuthToken: merchantAuthToken,
     merchantBaseUrl: merchant.makeInstanceBaseUrl(),
     summary: "foo",
   });
 
-  await wallet.runUntilDone();
+  await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
 
-  txns = await wallet.client.call(WalletApiOperation.GetTransactions, {});
+  txns = await walletClient.call(WalletApiOperation.GetTransactions, {});
   console.log(JSON.stringify(txns, undefined, 2));
   txTypes = txns.transactions.map((x) => x.type);
 
   t.assertDeepEqual(txTypes, ["withdrawal", "payment"]);
 
-  wallet.deleteDatabase();
+  await walletClient.call(WalletApiOperation.ClearDb, {});
 
-  await wallet.client.call(WalletApiOperation.WithdrawTestBalance, {
+  await walletClient.call(WalletApiOperation.WithdrawTestBalance, {
     amount: "TESTKUDOS:10" as AmountString,
     corebankApiBaseUrl: bank.corebankApiBaseUrl,
     exchangeBaseUrl: exchange.baseUrl,
   });
 
-  await wallet.runUntilDone();
+  await walletClient.call(WalletApiOperation.TestingWaitTransactionsFinal, {});
 
-  const coinDump = await wallet.client.call(WalletApiOperation.DumpCoins, {});
+  const coinDump = await walletClient.call(WalletApiOperation.DumpCoins, {});
 
   console.log("coin dump:", JSON.stringify(coinDump, undefined, 2));
 
@@ -194,7 +206,7 @@ export async function runWallettestingTest(t: 
GlobalTestState) {
 
   console.log("suspending coin");
 
-  await wallet.client.call(WalletApiOperation.SetCoinSuspended, {
+  await walletClient.call(WalletApiOperation.SetCoinSuspended, {
     coinPub: susp,
     suspended: true,
   });
@@ -202,7 +214,7 @@ export async function runWallettestingTest(t: 
GlobalTestState) {
   // This should fail, as we've suspended a coin that we need
   // to pay.
   await t.assertThrowsAsync(async () => {
-    await wallet.client.call(WalletApiOperation.TestPay, {
+    await walletClient.call(WalletApiOperation.TestPay, {
       amount: "TESTKUDOS:5" as AmountString,
       merchantAuthToken: merchantAuthToken,
       merchantBaseUrl: merchant.makeInstanceBaseUrl(),
@@ -212,19 +224,17 @@ export async function runWallettestingTest(t: 
GlobalTestState) {
 
   console.log("unsuspending coin");
 
-  await wallet.client.call(WalletApiOperation.SetCoinSuspended, {
+  await walletClient.call(WalletApiOperation.SetCoinSuspended, {
     coinPub: susp,
     suspended: false,
   });
 
-  await wallet.client.call(WalletApiOperation.TestPay, {
+  await walletClient.call(WalletApiOperation.TestPay, {
     amount: "TESTKUDOS:5" as AmountString,
     merchantAuthToken: merchantAuthToken,
     merchantBaseUrl: merchant.makeInstanceBaseUrl(),
     summary: "foo",
   });
-
-  await t.shutdown();
 }
 
 runWallettestingTest.suites = ["wallet"];
diff --git a/packages/taler-util/src/notifications.ts 
b/packages/taler-util/src/notifications.ts
index ed26c6ae7..b91d91777 100644
--- a/packages/taler-util/src/notifications.ts
+++ b/packages/taler-util/src/notifications.ts
@@ -46,6 +46,17 @@ export interface TransactionStateTransitionNotification {
   oldTxState: TransactionState;
   newTxState: TransactionState;
   errorInfo?: ErrorInfoSummary;
+
+  /**
+   * Additional "user data" that is dependent on the
+   * state transition.
+   *
+   * Usage should be avoided.
+   *
+   * Currently used to notify the iOS app about
+   * the KYC URL.
+   */
+  experimentalUserData?: any;
 }
 
 export interface ExchangeAddedNotification {
@@ -66,13 +77,11 @@ export interface BackupOperationErrorNotification {
   error: TalerErrorDetail;
 }
 
-
 export interface PendingOperationProcessedNotification {
   type: NotificationType.PendingOperationProcessed;
   id: string;
 }
 
-
 export type WalletNotification =
   | BalanceChangeNotification
   | BackupOperationErrorNotification
diff --git a/packages/taler-util/src/time.test.ts 
b/packages/taler-util/src/time.test.ts
index 876b35b9a..5dd8c7715 100644
--- a/packages/taler-util/src/time.test.ts
+++ b/packages/taler-util/src/time.test.ts
@@ -15,7 +15,7 @@
  */
 
 import test from "ava";
-import { Duration } from "./time.js";
+import { AbsoluteTime, Duration } from "./time.js";
 
 test("duration parsing", (t) => {
   const d1 = Duration.fromPrettyString("1h");
diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index d59085dcc..3e8452bcd 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -189,7 +189,7 @@ export function timestampPreciseToDb(
   } else {
     let tUs = stamp.t_s * 1000000;
     if (stamp.off_us) {
-      tUs == stamp.off_us;
+      tUs += stamp.off_us;
     }
     return tUs as DbPreciseTimestamp;
   }
diff --git a/packages/taler-wallet-core/src/operations/testing.ts 
b/packages/taler-wallet-core/src/operations/testing.ts
index 3fff9ccaa..62766556c 100644
--- a/packages/taler-wallet-core/src/operations/testing.ts
+++ b/packages/taler-wallet-core/src/operations/testing.ts
@@ -14,67 +14,67 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
+/**
+ * @file
+ * Implementation of wallet-core operations that are used for testing,
+ * but typically not in the production wallet.
+ */
+
 /**
  * Imports.
  */
 import {
   AbsoluteTime,
-  base64FromArrayBuffer,
+  Amounts,
+  AmountString,
+  CheckPaymentResponse,
+  codecForAny,
+  codecForCheckPaymentResponse,
   ConfirmPayResultType,
   Duration,
+  IntegrationTestArgs,
   IntegrationTestV2Args,
   j2s,
   Logger,
   NotificationType,
-  RegisterAccountRequest,
-  stringToBytes,
+  PreparePayResultType,
   TalerCorebankApiClient,
+  TestPayArgs,
   TestPayResult,
   TransactionMajorState,
   TransactionMinorState,
   TransactionState,
   TransactionType,
+  URL,
   WithdrawTestBalanceRequest,
 } from "@gnu-taler/taler-util";
 import {
   HttpRequestLibrary,
   readSuccessResponseJsonOrThrow,
-  checkSuccessResponseOrThrow,
 } from "@gnu-taler/taler-util/http";
-import {
-  AmountString,
-  codecForAny,
-  CheckPaymentResponse,
-  codecForCheckPaymentResponse,
-  IntegrationTestArgs,
-  Amounts,
-  TestPayArgs,
-  URL,
-  PreparePayResultType,
-} from "@gnu-taler/taler-util";
+import { OpenedPromise, openPromise } from "../index.js";
 import { InternalWalletState } from "../internal-wallet-state.js";
+import { checkLogicInvariant } from "../util/invariants.js";
+import { getBalances } from "./balance.js";
+import { updateExchangeFromUrl } from "./exchanges.js";
 import {
   confirmPay,
   preparePayForUri,
   startRefundQueryForUri,
 } from "./pay-merchant.js";
-import { getBalances } from "./balance.js";
-import { checkLogicInvariant } from "../util/invariants.js";
-import { acceptWithdrawalFromUri } from "./withdraw.js";
-import { updateExchangeFromUrl } from "./exchanges.js";
 import { initiatePeerPullPayment } from "./pay-peer-pull-credit.js";
 import {
-  preparePeerPullDebit,
   confirmPeerPullDebit,
+  preparePeerPullDebit,
 } from "./pay-peer-pull-debit.js";
 import {
-  preparePeerPushCredit,
   confirmPeerPushCredit,
+  preparePeerPushCredit,
 } from "./pay-peer-push-credit.js";
 import { initiatePeerPushDebit } from "./pay-peer-push-debit.js";
-import { OpenedPromise, openPromise } from "../index.js";
-import { getTransactionById, getTransactions } from "./transactions.js";
 import { getPendingOperations } from "./pending.js";
+import { getTransactionById, getTransactions } from "./transactions.js";
+import { acceptWithdrawalFromUri } from "./withdraw.js";
 
 const logger = new Logger("operations/testing.ts");
 
@@ -83,20 +83,6 @@ interface MerchantBackendInfo {
   authToken?: string;
 }
 
-/**
- * Generate a random alphanumeric ID.  Does *not* use cryptographically
- * secure randomness.
- */
-function makeId(length: number): string {
-  let result = "";
-  const characters =
-    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
-  for (let i = 0; i < length; i++) {
-    result += characters.charAt(Math.floor(Math.random() * characters.length));
-  }
-  return result;
-}
-
 export async function withdrawTestBalance(
   ws: InternalWalletState,
   req: WithdrawTestBalanceRequest,
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts 
b/packages/taler-wallet-core/src/operations/transactions.ts
index bebb3d60b..a30120baa 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -31,8 +31,6 @@ import {
   stringifyPayPullUri,
   stringifyPayPushUri,
   TalerErrorCode,
-  TalerPreciseTimestamp,
-  TalerProtocolTimestamp,
   Transaction,
   TransactionByIdRequest,
   TransactionIdStr,
@@ -50,12 +48,12 @@ import {
   DepositGroupRecord,
   ExchangeDetailsRecord,
   OperationRetryRecord,
-  PeerPullPaymentIncomingRecord,
-  PeerPullDebitRecordStatus,
   PeerPullCreditRecord,
-  PeerPushPaymentIncomingRecord,
+  PeerPullDebitRecordStatus,
+  PeerPullPaymentIncomingRecord,
   PeerPushCreditStatus,
   PeerPushDebitRecord,
+  PeerPushPaymentIncomingRecord,
   PurchaseRecord,
   PurchaseStatus,
   RefreshGroupRecord,
@@ -68,7 +66,6 @@ import {
 } from "../db.js";
 import {
   GetReadOnlyAccess,
-  timestampOptionalPreciseFromDb,
   timestampPreciseFromDb,
   timestampProtocolFromDb,
   WalletStoresV1,
@@ -85,81 +82,56 @@ import {
 } from "./common.js";
 import {
   abortDepositGroup,
-  failDepositTransaction,
+  computeDepositTransactionActions,
   computeDepositTransactionStatus,
   deleteDepositGroup,
+  failDepositTransaction,
   resumeDepositGroup,
   suspendDepositGroup,
-  computeDepositTransactionActions,
 } from "./deposits.js";
 import { getExchangeDetails } from "./exchanges.js";
 import {
   abortPayMerchant,
-  failPaymentTransaction,
+  computePayMerchantTransactionActions,
   computePayMerchantTransactionState,
   computeRefundTransactionState,
   expectProposalDownload,
   extractContractData,
+  failPaymentTransaction,
   resumePayMerchant,
   suspendPayMerchant,
-  computePayMerchantTransactionActions,
 } from "./pay-merchant.js";
 import {
-  abortRefreshGroup,
-  failRefreshGroup,
-  computeRefreshTransactionState,
-  resumeRefreshGroup,
-  suspendRefreshGroup,
-  computeRefreshTransactionActions,
-} from "./refresh.js";
-import {
-  abortTipTransaction,
-  failTipTransaction,
-  computeRewardTransactionStatus,
-  resumeTipTransaction,
-  suspendRewardTransaction,
-  computeTipTransactionActions,
-} from "./reward.js";
-import {
-  abortWithdrawalTransaction,
-  augmentPaytoUrisForWithdrawal,
-  failWithdrawalTransaction,
-  computeWithdrawalTransactionStatus,
-  resumeWithdrawalTransaction,
-  suspendWithdrawalTransaction,
-  computeWithdrawalTransactionActions,
-} from "./withdraw.js";
-import {
-  computePeerPullCreditTransactionState,
+  abortPeerPullCreditTransaction,
   computePeerPullCreditTransactionActions,
-  suspendPeerPullCreditTransaction,
+  computePeerPullCreditTransactionState,
   failPeerPullCreditTransaction,
   resumePeerPullCreditTransaction,
-  abortPeerPullCreditTransaction,
+  suspendPeerPullCreditTransaction,
 } from "./pay-peer-pull-credit.js";
 import {
-  computePeerPullDebitTransactionState,
+  abortPeerPullDebitTransaction,
   computePeerPullDebitTransactionActions,
-  suspendPeerPullDebitTransaction,
+  computePeerPullDebitTransactionState,
   failPeerPullDebitTransaction,
   resumePeerPullDebitTransaction,
-  abortPeerPullDebitTransaction,
+  suspendPeerPullDebitTransaction,
 } from "./pay-peer-pull-debit.js";
 import {
-  computePeerPushCreditTransactionState,
+  abortPeerPushCreditTransaction,
   computePeerPushCreditTransactionActions,
-  suspendPeerPushCreditTransaction,
+  computePeerPushCreditTransactionState,
   failPeerPushCreditTransaction,
   resumePeerPushCreditTransaction,
-  abortPeerPushCreditTransaction,
+  suspendPeerPushCreditTransaction,
 } from "./pay-peer-push-credit.js";
 import {
-  computePeerPushDebitTransactionState,
+  abortPeerPushDebitTransaction,
   computePeerPushDebitTransactionActions,
-  suspendPeerPushDebitTransaction,
+  computePeerPushDebitTransactionState,
   failPeerPushDebitTransaction,
   resumePeerPushDebitTransaction,
-  abortPeerPushDebitTransaction,
+  suspendPeerPushDebitTransaction,
 } from "./pay-peer-push-debit.js";
 import {
   iterRecordsForDeposit,
@@ -173,6 +145,31 @@ import {
   iterRecordsForReward,
   iterRecordsForWithdrawal,
 } from "./pending.js";
+import {
+  abortRefreshGroup,
+  computeRefreshTransactionActions,
+  computeRefreshTransactionState,
+  failRefreshGroup,
+  resumeRefreshGroup,
+  suspendRefreshGroup,
+} from "./refresh.js";
+import {
+  abortTipTransaction,
+  computeRewardTransactionStatus,
+  computeTipTransactionActions,
+  failTipTransaction,
+  resumeTipTransaction,
+  suspendRewardTransaction,
+} from "./reward.js";
+import {
+  abortWithdrawalTransaction,
+  augmentPaytoUrisForWithdrawal,
+  computeWithdrawalTransactionActions,
+  computeWithdrawalTransactionStatus,
+  failWithdrawalTransaction,
+  resumeWithdrawalTransaction,
+  suspendWithdrawalTransaction,
+} from "./withdraw.js";
 
 const logger = new Logger("taler-wallet-core:transactions.ts");
 
@@ -1937,6 +1934,7 @@ export function notifyTransition(
   ws: InternalWalletState,
   transactionId: string,
   transitionInfo: TransitionInfo | undefined,
+  experimentalUserData: any = undefined,
 ): void {
   if (
     transitionInfo &&
@@ -1950,6 +1948,7 @@ export function notifyTransition(
       oldTxState: transitionInfo.oldTxState,
       newTxState: transitionInfo.newTxState,
       transactionId,
+      experimentalUserData,
     });
   }
   ws.workAvailable.trigger();
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts 
b/packages/taler-wallet-core/src/operations/withdraw.ts
index 5b8d101b1..c83993816 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -781,6 +781,8 @@ async function handleKycRequired(
     throw Error(`unexpected response from kyc-check (${kycStatusRes.status})`);
   }
 
+  let notificationKycUrl: string | undefined = undefined;
+
   const transitionInfo = await ws.db
     .mktx((x) => [x.planchets, x.withdrawalGroups])
     .runReadWrite(async (tx) => {
@@ -813,10 +815,12 @@ async function handleKycRequired(
             amlStatus === AmlStatus.normal || amlStatus === undefined
               ? WithdrawalGroupStatus.PendingKyc
               : amlStatus === AmlStatus.pending
-                ? WithdrawalGroupStatus.PendingAml
-                : amlStatus === AmlStatus.fronzen
-                  ? WithdrawalGroupStatus.SuspendedAml
-                  : assertUnreachable(amlStatus);
+              ? WithdrawalGroupStatus.PendingAml
+              : amlStatus === AmlStatus.fronzen
+              ? WithdrawalGroupStatus.SuspendedAml
+              : assertUnreachable(amlStatus);
+
+          notificationKycUrl = kycUrl;
 
           await tx.withdrawalGroups.put(wg2);
           const newTxState = computeWithdrawalTransactionStatus(wg2);
@@ -829,7 +833,7 @@ async function handleKycRequired(
           return undefined;
       }
     });
-  notifyTransition(ws, transactionId, transitionInfo);
+  notifyTransition(ws, transactionId, transitionInfo, notificationKycUrl);
 }
 
 /**
@@ -1102,7 +1106,7 @@ async function processPlanchetVerifyAndStoreCoin(
         return false;
       }
       p.planchetStatus = PlanchetStatus.WithdrawalDone;
-      p.lastError = undefined
+      p.lastError = undefined;
       await tx.planchets.put(p);
       await makeCoinAvailable(ws, tx, coin);
       return true;
@@ -1150,7 +1154,8 @@ export async function updateWithdrawalDenoms(
         denom.verificationStatus === DenominationVerificationStatus.Unverified
       ) {
         logger.trace(
-          `Validating denomination (${current + 1}/${denominations.length
+          `Validating denomination (${current + 1}/${
+            denominations.length
           }) signature of ${denom.denomPubHash}`,
         );
         let valid = false;
@@ -1775,7 +1780,7 @@ export async function getExchangeWithdrawalInfo(
     ) {
       logger.warn(
         `wallet's support for exchange protocol version 
${WALLET_EXCHANGE_PROTOCOL_VERSION} might be outdated ` +
-        `(exchange has ${exchangeDetails.protocolVersionRange}), checking for 
updates`,
+          `(exchange has ${exchangeDetails.protocolVersionRange}), checking 
for updates`,
       );
     }
   }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]