gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-webex] branch master updated (bd17ead0 -> 15b


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-webex] branch master updated (bd17ead0 -> 15b84421)
Date: Sun, 28 May 2017 00:05:38 +0200

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

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

    from bd17ead0 missing files
     new 489b8cb4 correct and simplify test cases
     new 15b84421 coverage settings

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:
 package.json       |   5 ++
 src/types-test.ts  |   1 -
 src/types.ts       |  15 ++++
 src/wallet-test.ts | 226 ++++++++++++++++++++---------------------------------
 4 files changed, 104 insertions(+), 143 deletions(-)

diff --git a/package.json b/package.json
index fc7dfb13..b2c96911 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,11 @@
   },
   "author": "",
   "license": "GPL-3.0",
+  "nyc": {
+    "exclude": [
+      "emscripten"
+    ]
+  },
   "devDependencies": {
     "@types/moment": "^2.13.0",
     "@types/react": "^15.0.22",
diff --git a/src/types-test.ts b/src/types-test.ts
index 780d49e4..88f9f272 100644
--- a/src/types-test.ts
+++ b/src/types-test.ts
@@ -51,7 +51,6 @@ test("contract validation", t => {
     products: [],
     refund_deadline: "Date(12345)",
     timestamp: "Date(12345)",
-    transaction_id: 1234,
     fulfillment_url: "foo",
     wire_method: "test",
     order_id: "test_order",
diff --git a/src/types.ts b/src/types.ts
index 24027597..53f98948 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -741,6 +741,21 @@ export namespace Amounts {
   export function isNonZero(a: AmountJson) {
     return a.value > 0 || a.fraction > 0;
   }
+
+  /**
+   * Parse an amount like 'EUR:20.5' for 20 Euros and 50 ct.
+   */
+  export function parse(s: string): AmountJson|undefined {
+    let res = s.match(/([a-zA-Z0-9_*-]+):([0-9])+([.][0-9]+)?/);
+    if (!res) {
+      return undefined;
+    }
+    return {
+      currency: res[1],
+      value: Number.parseInt(res[2]),
+      fraction: Math.round(fractionalBase * Number.parseFloat(res[3] || "0")),
+    }
+  }
 }
 
 
diff --git a/src/wallet-test.ts b/src/wallet-test.ts
index 56b5e602..2c3ed52d 100644
--- a/src/wallet-test.ts
+++ b/src/wallet-test.ts
@@ -1,30 +1,57 @@
 import {test} from "ava";
-import {mkAmount} from "./types";
+import * as types from "./types";
 import * as wallet from "./wallet";
 
+function a(x: string): types.AmountJson {
+  let amt = types.Amounts.parse(x);
+  if (!amt) {
+    throw Error("invalid amount");
+  }
+  return amt;
+}
 
-test("coin selection 1", t => {
-  let cds: any = [];
-  cds.push({
+function fakeCwd(current: string, value: string, feeDeposit: string): 
wallet.CoinWithDenom {
+  return {
     coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
+      currentAmount: a(current),
+      coinPub: "(mock)",
+      coinPriv: "(mock)",
+      denomPub: "(mock)",
+      denomSig: "(mock)",
+      exchangeBaseUrl: "(mock)",
+      blindingKey: "(mock)",
+      reservePub: "(mock)",
+      status: types.CoinStatus.Fresh,
     },
     denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
+      value: a(value),
+      feeDeposit: a(feeDeposit),
+      denomPub: "(mock)",
+      denomPubHash: "(mock)",
+      feeWithdraw: a("EUR:0.0"),
+      feeRefresh: a("EUR:0.0"),
+      feeRefund: a("EUR:0.0"),
+      stampStart: "(mock)",
+      stampExpireWithdraw: "(mock)",
+      stampExpireLegal: "(mock)",
+      stampExpireDeposit: "(mock)",
+      masterSig: "(mock)",
+      status: types.DenominationStatus.VerifiedGood,
+      isOffered: true,
+      exchangeBaseUrl: "(mock)",
     },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
+  }
+}
+
+
 
-  let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,5,"EUR"));
+test("coin selection 1", t => {
+  let cds: wallet.CoinWithDenom[] = [
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.1"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"),
+  ];
+
+  let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.1"));
   if (!res) {
     t.fail();
     return;
@@ -35,37 +62,13 @@ test("coin selection 1", t => {
 
 
 test("coin selection 2", t => {
-  let cds: any = [];
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
-  // Merchant covers the fee, this one shouldn't be used
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
-
-  let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,5,"EUR"));
+  let cds: wallet.CoinWithDenom[] = [
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"),
+    // Merchant covers the fee, this one shouldn't be used
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"),
+  ];
+  let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.5"));
   if (!res) {
     t.fail();
     return;
@@ -75,37 +78,14 @@ test("coin selection 2", t => {
 });
 
 
-test("coin selection 2", t => {
-  let cds: any = [];
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
-
-  let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,2,"EUR"));
+test("coin selection 3", t => {
+  let cds: wallet.CoinWithDenom[] = [
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    // this coin should be selected instead of previous one with fee
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"),
+  ];
+  let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.5"));
   if (!res) {
     t.fail();
     return;
@@ -116,37 +96,13 @@ test("coin selection 2", t => {
 
 
 
-test("coin selection 3", t => {
-  let cds: any = [];
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
-    },
-  });
-
-  let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,2,"EUR"));
+test("coin selection 4", t => {
+  let cds: wallet.CoinWithDenom[] = [
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+  ];
+  let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.2"));
   if (!res) {
     t.fail();
     return;
@@ -156,38 +112,24 @@ test("coin selection 3", t => {
 });
 
 
-test("coin selection 3", t => {
-  let cds: any = [];
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 0, "EUR"),
-    },
-  });
-  cds.push({
-    coin: {
-      currentAmount: mkAmount(1, 0, "EUR"),
-    },
-    denom: {
-      value: mkAmount(1, 0, "EUR"),
-      fee_deposit: mkAmount(0, 5, "EUR"),
-    },
-  });
-
-  let res = wallet.selectCoins(cds, mkAmount(4,0,"EUR"), mkAmount(0,2,"EUR"));
+test("coin selection 5", t => {
+  let cds: wallet.CoinWithDenom[] = [
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+  ];
+  let res = wallet.selectCoins(cds, a("EUR:4.0"), a("EUR:0.2"));
   t.true(!res);
   t.pass();
+});
+
 
+test("coin selection 6", t => {
+  let cds: wallet.CoinWithDenom[] = [
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+    fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+  ];
+  let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.2"));
+  t.true(!res);
+  t.pass();
 });

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



reply via email to

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