gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (cb2fbc76 -> c4d28995)


From: gnunet
Subject: [taler-wallet-core] branch master updated (cb2fbc76 -> c4d28995)
Date: Mon, 23 Mar 2020 13:17:40 +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 cb2fbc76 fix another withdrawal state machine bug, add 'show-reserve' 
to advanced CLI
     new f10172d1 specify node version
     new b6d081b6 update git URL
     new eabbbd33 config files WIP
     new 0e51d45e upgrade ts and prettier
     new 1b0b3f14 make sure the 'testing withdraw' subcommand does retries
     new c4d28995 implement time travelling

The 6 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:
 contrib/integrationtest.conf     |  10 +++
 package.json                     |   9 ++-
 src/headless/helpers.ts          |   4 +-
 src/headless/integrationtest.ts  | 141 ++++++++++++++++++++++++++++++++++++++-
 src/headless/taler-wallet-cli.ts |  41 ++++++++++--
 src/operations/reserves.ts       |   4 +-
 src/util/time.ts                 |   8 ++-
 tsconfig.json                    |   1 +
 yarn.lock                        |  15 +++--
 9 files changed, 216 insertions(+), 17 deletions(-)
 create mode 100644 contrib/integrationtest.conf

diff --git a/contrib/integrationtest.conf b/contrib/integrationtest.conf
new file mode 100644
index 00000000..5b4f4e85
--- /dev/null
+++ b/contrib/integrationtest.conf
@@ -0,0 +1,10 @@
+[integrationtest]
+walletdb = testwalletdb.json
+bank_base_url = https://bank.test.taler.net/
+exchange_base_url = https://exchange.test.taler.net/
+merchant_base_url = https://backend.test.taler.net/
+merchant_api_key = sandbox
+
+[integrationtest-basic]
+amount_withdraw = TESTKUDOS:10
+amount_spend = TESTKUDOS:5
diff --git a/package.json b/package.json
index 6d1edeac..310e10e1 100644
--- a/package.json
+++ b/package.json
@@ -2,10 +2,13 @@
   "name": "taler-wallet",
   "version": "0.6.11",
   "description": "",
+  "engines": {
+    "node": ">=0.12.0"
+  },
   "main": "dist/node/index.js",
   "repository": {
     "type": "git",
-    "url": "git://git.taler.net/wallet.git"
+    "url": "git://git.taler.net/wallet-core.git"
   },
   "author": "Florian Dold",
   "license": "GPL-3.0",
@@ -44,7 +47,7 @@
     "nyc": "^14.1.1",
     "po2json": "^1.0.0-alpha",
     "pogen": "^0.0.5",
-    "prettier": "^1.18.2",
+    "prettier": "^2.0.1",
     "react": "^16.8.5",
     "react-dom": "^16.8.5",
     "rollup": "^1.27.8",
@@ -55,7 +58,7 @@
     "through2": "3.0.1",
     "tslint": "^5.19.0",
     "typedoc": "^0.15.0",
-    "typescript": "^3.7.2",
+    "typescript": "^3.8.3",
     "uglify-js": "^3.0.27",
     "vinyl": "^2.2.0",
     "vinyl-fs": "^3.0.3",
diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts
index 0f690f26..dc56a987 100644
--- a/src/headless/helpers.ts
+++ b/src/headless/helpers.ts
@@ -158,6 +158,9 @@ export async function withdrawTestBalance(
   ]);
 
   const donePromise = new Promise((resolve, reject) => {
+    myWallet.runRetryLoop().catch((x) => {
+      reject(x);
+    });
     myWallet.addNotificationListener(n => {
       if (
         n.type === NotificationType.ReserveDepleted &&
@@ -169,7 +172,6 @@ export async function withdrawTestBalance(
   });
 
   await bank.createReserve(bankUser, amount, reservePub, exchangePaytoUri);
-
   await myWallet.confirmReserve({ reservePub: reserveResponse.reservePub });
   await donePromise;
 }
diff --git a/src/headless/integrationtest.ts b/src/headless/integrationtest.ts
index 984ef9c3..fbc6223f 100644
--- a/src/headless/integrationtest.ts
+++ b/src/headless/integrationtest.ts
@@ -24,6 +24,7 @@ import { Logger } from "../util/logging";
 import { NodeHttpLib } from "./NodeHttpLib";
 import * as Amounts from "../util/amounts";
 import { Wallet } from "../wallet";
+import { Configuration } from "../util/talerconfig";
 
 const logger = new Logger("integrationtest.ts");
 
@@ -189,5 +190,143 @@ export async function runIntegrationTest(args: 
IntegrationTestArgs) {
 
   const history = await myWallet.getHistory({ verboseDetails: true });
 
-  console.log("history after integration test:", JSON.stringify(history, 
undefined, 2));
+  console.log(
+    "history after integration test:",
+    JSON.stringify(history, undefined, 2),
+  );
+}
+
+export async function runIntegrationTestBasic(cfg: Configuration) {
+  const walletDbPath = cfg.getString("integrationtest", "walletdb").required();
+
+  const bankBaseUrl = cfg
+    .getString("integrationtest", "bank_base_url")
+    .required();
+
+  const exchangeBaseUrl = cfg
+    .getString("integrationtest", "exchange_base_url")
+    .required();
+
+  const merchantBaseUrl = cfg
+    .getString("integrationtest", "merchant_base_url")
+    .required();
+
+  const merchantApiKey = cfg
+    .getString("integrationtest", "merchant_api_key")
+    .required();
+
+  const parsedWithdrawAmount = cfg
+    .getAmount("integrationtest-basic", "amount_withdraw")
+    .required();
+
+  const parsedSpendAmount = cfg
+    .getAmount("integrationtest-basic", "amount_spend")
+    .required();
+
+  const currency = parsedSpendAmount.currency;
+
+  const myHttpLib = new NodeHttpLib();
+  myHttpLib.setThrottling(false);
+
+  const myWallet = await getDefaultNodeWallet({
+    httpLib: myHttpLib,
+    persistentStoragePath: walletDbPath,
+  });
+
+  myWallet.runRetryLoop().catch(e => {
+    console.error("exception during retry loop:", e);
+  });
+
+  logger.info("withdrawing test balance");
+  await withdrawTestBalance(
+    myWallet,
+    Amounts.toString(parsedWithdrawAmount),
+    bankBaseUrl,
+    exchangeBaseUrl,
+  );
+  logger.info("done withdrawing test balance");
+
+  const balance = await myWallet.getBalances();
+
+  console.log(JSON.stringify(balance, null, 2));
+
+  const myMerchant = new MerchantBackendConnection(
+    merchantBaseUrl,
+    merchantApiKey,
+  );
+
+  await makePayment(myWallet, myMerchant, Amounts.toString(parsedSpendAmount), 
"hello world");
+
+  // Wait until the refresh is done
+  await myWallet.runUntilDone();
+
+  console.log("withdrawing test balance for refund");
+  const withdrawAmountTwo: Amounts.AmountJson = {
+    currency,
+    value: 18,
+    fraction: 0,
+  };
+  const spendAmountTwo: Amounts.AmountJson = {
+    currency,
+    value: 7,
+    fraction: 0,
+  };
+
+  const refundAmount: Amounts.AmountJson = {
+    currency,
+    value: 6,
+    fraction: 0,
+  };
+
+  const spendAmountThree: Amounts.AmountJson = {
+    currency,
+    value: 3,
+    fraction: 0,
+  };
+
+  await withdrawTestBalance(
+    myWallet,
+    Amounts.toString(withdrawAmountTwo),
+    bankBaseUrl,
+    exchangeBaseUrl,
+  );
+
+  // Wait until the withdraw is done
+  await myWallet.runUntilDone();
+
+  let { orderId: refundOrderId } = await makePayment(
+    myWallet,
+    myMerchant,
+    Amounts.toString(spendAmountTwo),
+    "order that will be refunded",
+  );
+
+  const refundUri = await myMerchant.refund(
+    refundOrderId,
+    "test refund",
+    Amounts.toString(refundAmount),
+  );
+
+  console.log("refund URI", refundUri);
+
+  await myWallet.applyRefund(refundUri);
+
+  // Wait until the refund is done
+  await myWallet.runUntilDone();
+
+  await makePayment(
+    myWallet,
+    myMerchant,
+    Amounts.toString(spendAmountThree),
+    "payment after refund",
+  );
+
+  await myWallet.runUntilDone();
+
+  const history = await myWallet.getHistory({ verboseDetails: true });
+
+  console.log(
+    "history after integration test:",
+    JSON.stringify(history, undefined, 2),
+  );
 }
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index 4518d601..9a21d2a1 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -18,7 +18,7 @@ import os = require("os");
 import fs = require("fs");
 import { getDefaultNodeWallet, withdrawTestBalance } from "./helpers";
 import { MerchantBackendConnection } from "./merchant";
-import { runIntegrationTest } from "./integrationtest";
+import { runIntegrationTest, runIntegrationTestBasic } from 
"./integrationtest";
 import { Wallet } from "../wallet";
 import qrcodeGenerator = require("qrcode-generator");
 import * as clk from "./clk";
@@ -30,6 +30,8 @@ import { OperationFailedAndReportedError } from 
"../operations/errors";
 import { Bank } from "./bank";
 import { classifyTalerUri, TalerUriType } from "../util/taleruri";
 import util = require("util");
+import { Configuration } from "../util/talerconfig";
+import { setDangerousTimetravel } from "../util/time";
 
 // Backwards compatibility with nodejs<0.11, where TextEncoder and TextDecoder
 // are not globals yet.
@@ -38,7 +40,7 @@ import util = require("util");
 
 const logger = new Logger("taler-wallet-cli.ts");
 
-const walletDbPath = os.homedir + "/" + ".talerwalletdb.json";
+const defaultWalletDbPath = os.homedir + "/" + ".talerwalletdb.json";
 
 function assertUnreachable(x: never): never {
   throw new Error("Didn't expect to get here");
@@ -115,6 +117,17 @@ const walletCli = clk
   .program("wallet", {
     help: "Command line interface for the GNU Taler wallet.",
   })
+  .maybeOption("walletDbFile", ["--wallet-db"], clk.STRING, {
+    help: "location of the wallet database file"
+  })
+  .maybeOption("timetravel", ["--timetravel"], clk.INT, {
+    help: "modify system time by given offset in microseconds",
+    onPresentHandler: (x) => {
+      // Convert microseconds to milliseconds and do timetravel
+      logger.info(`timetravelling ${x} microseconds`);
+      setDangerousTimetravel(x / 1000);
+    },
+  })
   .maybeOption("inhibit", ["--inhibit"], clk.STRING, {
     help:
       "Inhibit running certain operations, useful for debugging and testing.",
@@ -132,8 +145,9 @@ async function withWallet<T>(
   walletCliArgs: WalletCliArgsType,
   f: (w: Wallet) => Promise<T>,
 ): Promise<T> {
+  const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
   const wallet = await getDefaultNodeWallet({
-    persistentStoragePath: walletDbPath,
+    persistentStoragePath: dbPath,
   });
   applyVerbose(walletCliArgs.wallet.verbose);
   try {
@@ -189,7 +203,9 @@ walletCli
       } else {
         for (const h of history.history) {
           console.log(
-            `event at ${new Date(h.timestamp.t_ms).toISOString()} with type 
${h.type}:`,
+            `event at ${new Date(h.timestamp.t_ms).toISOString()} with type ${
+              h.type
+            }:`,
           );
           console.log(JSON.stringify(h, undefined, 2));
           console.log();
@@ -402,6 +418,23 @@ const testCli = walletCli.subcommand("testingArgs", 
"testing", {
   help: "Subcommands for testing GNU Taler deployments.",
 });
 
+testCli
+  .subcommand("integrationtestBasic", "integrationtest-basic")
+  .requiredArgument("cfgfile", clk.STRING)
+  .action(async args => {
+    const cfgStr = fs.readFileSync(args.integrationtestBasic.cfgfile, "utf8");
+    const cfg = new Configuration();
+    cfg.loadFromString(cfgStr);
+    try {
+      await runIntegrationTestBasic(cfg);
+    } catch (e) {
+      console.log("integration test failed");
+      console.log(e)
+      process.exit(1);
+    }
+    process.exit(0);
+  });
+
 testCli
   .subcommand("testPayCmd", "test-pay", { help: "create contract and pay" })
   .requiredOption("amount", ["-a", "--amount"], clk.STRING)
diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts
index 0daad8cc..c0e22b3c 100644
--- a/src/operations/reserves.ts
+++ b/src/operations/reserves.ts
@@ -195,7 +195,7 @@ export async function createReserve(
   // Asynchronously process the reserve, but return
   // to the caller already.
   processReserve(ws, resp.reservePub, true).catch(e => {
-    console.error("Processing reserve failed:", e);
+    console.error("Processing reserve (after createReserve) failed:", e);
   });
 
   return resp;
@@ -604,7 +604,7 @@ export async function confirmReserve(
   ws.notify({ type: NotificationType.ReserveUpdated });
 
   processReserve(ws, req.reservePub, true).catch(e => {
-    console.log("processing reserve failed:", e);
+    console.log("processing reserve (after confirmReserve) failed:", e);
   });
 }
 
diff --git a/src/util/time.ts b/src/util/time.ts
index 88297f9a..2740c361 100644
--- a/src/util/time.ts
+++ b/src/util/time.ts
@@ -34,9 +34,15 @@ export interface Duration {
   readonly d_ms: number | "forever";
 }
 
+let timeshift: number = 0;
+
+export function setDangerousTimetravel(dt: number) {
+  timeshift = dt;
+}
+
 export function getTimestampNow(): Timestamp {
   return {
-    t_ms: new Date().getTime(),
+    t_ms: new Date().getTime() + timeshift,
   };
 }
 
diff --git a/tsconfig.json b/tsconfig.json
index a6cd7b26..6808b337 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -86,6 +86,7 @@
     "src/util/payto.ts",
     "src/util/promiseUtils.ts",
     "src/util/query.ts",
+    "src/util/talerconfig.ts",
     "src/util/taleruri-test.ts",
     "src/util/taleruri.ts",
     "src/util/time.ts",
diff --git a/yarn.lock b/yarn.lock
index 74d331dc..f891ac2e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5534,10 +5534,10 @@ prepend-http@^2.0.0:
   resolved 
"https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897";
   integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
 
-prettier@^1.18.2:
-  version "1.19.1"
-  resolved 
"https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb";
-  integrity 
sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
+prettier@^2.0.1:
+  version "2.0.1"
+  resolved 
"https://registry.yarnpkg.com/prettier/-/prettier-2.0.1.tgz#3f00ac71263be34684b2b2c8d7e7f63737592dac";
+  integrity 
sha512-piXGBcY1zoFOG0MvHpNE5reAGseLmaCRifQ/fmfF49BcYkInEs/naD/unxGNAeOKFA5+JxVrPyMvMlpzcd20UA==
 
 pretty-hrtime@^1.0.0:
   version "1.0.3"
@@ -7020,11 +7020,16 @@ typedoc@^0.15.0:
     typedoc-default-themes "^0.6.1"
     typescript "3.7.x"
 
-typescript@3.7.x, typescript@^3.7.2:
+typescript@3.7.x:
   version "3.7.2"
   resolved 
"https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb";
   integrity 
sha512-ml7V7JfiN2Xwvcer+XAf2csGO1bPBdRbFCkYBczNZggrBZ9c7G3riSUeJmqEU5uOtXNPMhE3n+R4FA/3YOAWOQ==
 
+typescript@^3.8.3:
+  version "3.8.3"
+  resolved 
"https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061";
+  integrity 
sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
+
 uglify-js@^3.0.27, uglify-js@^3.1.4:
   version "3.6.9"
   resolved 
"https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.9.tgz#85d353edb6ddfb62a9d798f36e91792249320611";

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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