gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: failing p2p test case


From: gnunet
Subject: [taler-wallet-core] branch master updated: failing p2p test case
Date: Wed, 13 Sep 2023 16:09:42 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new a654c88a5 failing p2p test case
a654c88a5 is described below

commit a654c88a584b1249d1e60c0b8de0aeff72e5979e
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Wed Sep 13 11:09:33 2023 -0300

    failing p2p test case
---
 packages/taler-wallet-core/src/dbless.ts           |  2 +-
 .../src/util/coinSelection.test.ts                 | 64 ++++++++++++++++++++++
 .../taler-wallet-core/src/util/coinSelection.ts    |  6 ++
 3 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/packages/taler-wallet-core/src/dbless.ts 
b/packages/taler-wallet-core/src/dbless.ts
index 65c293bdf..d70eab888 100644
--- a/packages/taler-wallet-core/src/dbless.ts
+++ b/packages/taler-wallet-core/src/dbless.ts
@@ -31,6 +31,7 @@ import {
   AmountJson,
   Amounts,
   AmountString,
+  BankAccessApiClient,
   codecForAny,
   codecForBankWithdrawalOperationPostResponse,
   codecForBatchDepositSuccess,
@@ -53,7 +54,6 @@ import {
   HttpRequestLibrary,
   readSuccessResponseJsonOrThrow,
 } from "@gnu-taler/taler-util/http";
-import { BankAccessApiClient } from "../../taler-util/src/bank-api-client.js";
 import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
 import { DenominationRecord } from "./db.js";
 import { isWithdrawableDenom } from "./index.js";
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts 
b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index b907eb160..f678e75e7 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -18,8 +18,72 @@ import {
   AgeRestriction,
   AmountJson,
   Amounts,
+  DenomKeyType,
   Duration,
   TransactionAmountMode,
 } from "@gnu-taler/taler-util";
 import test, { ExecutionContext } from "ava";
+import { testing_greedySelectPeer } from "./coinSelection.js"
 
+type Tester<T> = {
+  deep: {
+    equal(another: T): ReturnType<ExecutionContext["deepEqual"]>;
+    equals(another: T): ReturnType<ExecutionContext["deepEqual"]>;
+  }
+}
+
+function expect<T>(t: ExecutionContext, thing: T): Tester<T> {
+  return {
+    deep: {
+      equal: (another: T) => t.deepEqual(thing, another),
+      equals: (another: T) => t.deepEqual(thing, another),
+    },
+  };
+}
+
+const inTheDistantFuture = AbsoluteTime.toProtocolTimestamp(
+  AbsoluteTime.addDuration(AbsoluteTime.now(), Duration.fromSpec({ hours: 1 }))
+)
+const inThePast = AbsoluteTime.toProtocolTimestamp(
+  AbsoluteTime.subtractDuraction(AbsoluteTime.now(), Duration.fromSpec({ 
hours: 1 }))
+)
+test("should select the coin", (t) => {
+  const instructedAmount = Amounts.parseOrThrow("LOCAL:2")
+  const tally = {
+    amountAcc: Amounts.zeroOfCurrency(instructedAmount.currency),
+    depositFeesAcc: Amounts.zeroOfCurrency(instructedAmount.currency),
+    lastDepositFee: Amounts.zeroOfCurrency(instructedAmount.currency),
+  };
+  const coins = testing_greedySelectPeer(
+    // candidates available
+    [{
+      "denomPub": {
+        "age_mask": 0,
+        "cipher": DenomKeyType.Rsa,
+        "rsa_public_key": "PPP"
+      },
+      "denomPubHash": "XXX",
+      "value": "LOCAL:10",
+      "feeDeposit": "LOCAL:0.1",
+      "feeRefresh": "LOCAL:0",
+      "feeRefund": "LOCAL:0",
+      "feeWithdraw": "LOCAL:0",
+      "stampExpireDeposit": inTheDistantFuture,
+      "stampExpireLegal": inTheDistantFuture,
+      "stampExpireWithdraw": inTheDistantFuture,
+      "stampStart": inThePast,
+      "exchangeBaseUrl": "http://exchange.localhost/";,
+      "numAvailable": 5,
+      "maxAge": 32
+    }],
+    instructedAmount, tally);
+
+  expect(t, coins).deep.equal({
+    "XXX;32;http://exchange.localhost/": {
+      exchangeBaseUrl: "http://exchange.localhost/";,
+      denomPubHash: "XXX",
+      maxAge: 32,
+      contributions: [Amounts.parseOrThrow("LOCAL:2")],
+    }
+  });
+});
\ No newline at end of file
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts 
b/packages/taler-wallet-core/src/util/coinSelection.ts
index 6fd0f1b86..b8ce5e0f2 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -894,6 +894,12 @@ interface PeerCoinSelectionTally {
   lastDepositFee: AmountJson;
 }
 
+/**
+ * exporting for testing
+ */
+export function testing_greedySelectPeer(...args: Parameters<typeof 
greedySelectPeer>): ReturnType<typeof greedySelectPeer> {
+  return greedySelectPeer(...args)
+}
 function greedySelectPeer(
   candidates: AvailableDenom[],
   instructedAmount: AmountLike,

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