gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: re-add tests, more coin selec


From: gnunet
Subject: [taler-wallet-core] branch master updated: re-add tests, more coin selection tests
Date: Sat, 27 Mar 2021 20:48:49 +0100

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 2be1c3c8 re-add tests, more coin selection tests
2be1c3c8 is described below

commit 2be1c3c8bd78b501ddf3a0b989f954f9163b3702
Author: Florian Dold <florian@dold.me>
AuthorDate: Sat Mar 27 20:48:44 2021 +0100

    re-add tests, more coin selection tests
---
 packages/taler-wallet-core/package.json            |  2 +-
 .../{withdraw-test.ts => withdraw.test.ts}         |  0
 ...coinSelection-test.ts => coinSelection.test.ts} | 68 ++++++++++++++++++++++
 .../taler-wallet-core/src/util/coinSelection.ts    |  3 +-
 .../src/util/{helpers-test.ts => helpers.test.ts}  |  0
 5 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/packages/taler-wallet-core/package.json 
b/packages/taler-wallet-core/package.json
index 15485cb5..de974469 100644
--- a/packages/taler-wallet-core/package.json
+++ b/packages/taler-wallet-core/package.json
@@ -71,7 +71,7 @@
       "esm"
     ],
     "files": [
-      "src/**/*-test.*"
+      "src/**/*.test.*"
     ],
     "typescript": {
       "extensions": [
diff --git a/packages/taler-wallet-core/src/operations/withdraw-test.ts 
b/packages/taler-wallet-core/src/operations/withdraw.test.ts
similarity index 100%
rename from packages/taler-wallet-core/src/operations/withdraw-test.ts
rename to packages/taler-wallet-core/src/operations/withdraw.test.ts
diff --git a/packages/taler-wallet-core/src/util/coinSelection-test.ts 
b/packages/taler-wallet-core/src/util/coinSelection.test.ts
similarity index 71%
rename from packages/taler-wallet-core/src/util/coinSelection-test.ts
rename to packages/taler-wallet-core/src/util/coinSelection.test.ts
index 962a1483..bfcd05cc 100644
--- a/packages/taler-wallet-core/src/util/coinSelection-test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -184,3 +184,71 @@ test("coin selection 6", (t) => {
   t.true(!res);
   t.pass();
 });
+
+test("coin selection 7", (t) => {
+  const acis: AvailableCoinInfo[] = [
+    fakeAci("EUR:1.0", "EUR:0.1"),
+    fakeAci("EUR:1.0", "EUR:0.1"),
+  ];
+  const res = selectPayCoins({
+    candidates: {
+      candidateCoins: acis,
+      wireFeesPerExchange: {},
+    },
+    contractTermsAmount: a("EUR:2.0"),
+    depositFeeLimit: a("EUR:0.2"),
+    wireFeeLimit: a("EUR:0"),
+    wireFeeAmortization: 1,
+  });
+  t.truthy(res);
+  t.true(Amounts.cmp(res!.customerDepositFees, "EUR:0.0") === 0);
+  t.true(
+    Amounts.cmp(Amounts.sum(res!.coinContributions).amount, "EUR:2.0") === 0,
+  );
+  t.pass();
+});
+
+test("coin selection 8", (t) => {
+  const acis: AvailableCoinInfo[] = [
+    fakeAci("EUR:1.0", "EUR:0.2"),
+    fakeAci("EUR:0.1", "EUR:0.2"),
+    fakeAci("EUR:0.05", "EUR:0.05"),
+    fakeAci("EUR:0.05", "EUR:0.05"),
+  ];
+  const res = selectPayCoins({
+    candidates: {
+      candidateCoins: acis,
+      wireFeesPerExchange: {},
+    },
+    contractTermsAmount: a("EUR:1.1"),
+    depositFeeLimit: a("EUR:0.4"),
+    wireFeeLimit: a("EUR:0"),
+    wireFeeAmortization: 1,
+  });
+  t.truthy(res);
+  t.true(res!.coinContributions.length === 3);
+  t.pass();
+});
+
+test("coin selection 9", (t) => {
+  const acis: AvailableCoinInfo[] = [
+    fakeAci("EUR:1.0", "EUR:0.2"),
+    fakeAci("EUR:0.2", "EUR:0.2"),
+  ];
+  const res = selectPayCoins({
+    candidates: {
+      candidateCoins: acis,
+      wireFeesPerExchange: {},
+    },
+    contractTermsAmount: a("EUR:1.2"),
+    depositFeeLimit: a("EUR:0.4"),
+    wireFeeLimit: a("EUR:0"),
+    wireFeeAmortization: 1,
+  });
+  t.truthy(res);
+  t.true(res!.coinContributions.length === 2);
+  t.true(
+    Amounts.cmp(Amounts.sum(res!.coinContributions).amount, "EUR:1.2") === 0,
+  );
+  t.pass();
+});
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts 
b/packages/taler-wallet-core/src/util/coinSelection.ts
index a840993c..e1fec5c9 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -284,9 +284,10 @@ export function selectPayCoins(
   for (const aci of candidateCoins) {
     // Don't use this coin if depositing it is more expensive than
     // the amount it would give the merchant.
-    if (Amounts.cmp(aci.feeDeposit, aci.availableAmount) >= 0) {
+    if (Amounts.cmp(aci.feeDeposit, aci.availableAmount) > 0) {
       continue;
     }
+
     if (Amounts.isZero(tally.amountPayRemaining)) {
       // We have spent enough!
       break;
diff --git a/packages/taler-wallet-core/src/util/helpers-test.ts 
b/packages/taler-wallet-core/src/util/helpers.test.ts
similarity index 100%
rename from packages/taler-wallet-core/src/util/helpers-test.ts
rename to packages/taler-wallet-core/src/util/helpers.test.ts

-- 
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]