gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 02/03: wallet-core: fix unit test


From: gnunet
Subject: [taler-wallet-core] 02/03: wallet-core: fix unit test
Date: Fri, 15 Dec 2023 12:20:25 +0100

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

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

commit a30615c2118659e5b928593a800075e5285c65c3
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Dec 15 12:12:57 2023 +0100

    wallet-core: fix unit test
---
 .../src/util/coinSelection.test.ts                 | 49 ++++++++--------------
 1 file changed, 18 insertions(+), 31 deletions(-)

diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts 
b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index 055c42902..0715c999f 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -22,7 +22,7 @@ import {
   TalerProtocolTimestamp,
   j2s,
 } from "@gnu-taler/taler-util";
-import test, { ExecutionContext } from "ava";
+import test from "ava";
 import {
   AvailableDenom,
   testing_greedySelectPeer,
@@ -32,6 +32,7 @@ import {
 const inTheDistantFuture = AbsoluteTime.toProtocolTimestamp(
   AbsoluteTime.addDuration(AbsoluteTime.now(), Duration.fromSpec({ hours: 1 
})),
 );
+
 const inThePast = AbsoluteTime.toProtocolTimestamp(
   AbsoluteTime.subtractDuraction(
     AbsoluteTime.now(),
@@ -61,18 +62,20 @@ test("p2p: should select the coin", (t) => {
 
   t.log(j2s(coins));
 
-  expect(t, coins).deep.equal({
+  t.assert(coins != null);
+
+  t.deepEqual(coins, {
     "hash0;32;http://exchange.localhost/": {
       exchangeBaseUrl: "http://exchange.localhost/";,
       denomPubHash: "hash0",
       maxAge: 32,
       contributions: [Amounts.parseOrThrow("LOCAL:2.1")],
-      expireDeposit: TalerProtocolTimestamp.fromSeconds(1702412542),
-      expireWithdraw: TalerProtocolTimestamp.fromSeconds(1702412542),
+      expireDeposit: inTheDistantFuture,
+      expireWithdraw: inTheDistantFuture,
     },
   });
 
-  expect(t, tally).deep.equal({
+  t.deepEqual(tally, {
     amountAcc: Amounts.parseOrThrow("LOCAL:2"),
     depositFeesAcc: Amounts.parseOrThrow("LOCAL:0.1"),
     lastDepositFee: Amounts.parseOrThrow("LOCAL:0.1"),
@@ -99,7 +102,7 @@ test("p2p: should select 3 coins", (t) => {
     tally,
   );
 
-  expect(t, coins).deep.equal({
+  t.deepEqual(coins, {
     "hash0;32;http://exchange.localhost/": {
       exchangeBaseUrl: "http://exchange.localhost/";,
       denomPubHash: "hash0",
@@ -109,12 +112,12 @@ test("p2p: should select 3 coins", (t) => {
         Amounts.parseOrThrow("LOCAL:9.9"),
         Amounts.parseOrThrow("LOCAL:0.5"),
       ],
-      expireDeposit: TalerProtocolTimestamp.fromSeconds(1702412542),
-      expireWithdraw: TalerProtocolTimestamp.fromSeconds(1702412542),
+      expireDeposit: inTheDistantFuture,
+      expireWithdraw: inTheDistantFuture,
     },
   });
 
-  expect(t, tally).deep.equal({
+  t.deepEqual(tally, {
     amountAcc: Amounts.parseOrThrow("LOCAL:20"),
     depositFeesAcc: Amounts.parseOrThrow("LOCAL:0.3"),
     lastDepositFee: Amounts.parseOrThrow("LOCAL:0.1"),
@@ -141,9 +144,9 @@ test("p2p: can't select since the instructed amount is too 
high", (t) => {
     tally,
   );
 
-  expect(t, coins).deep.equal(undefined);
+  t.is(coins, undefined);
 
-  expect(t, tally).deep.equal({
+  t.deepEqual(tally, {
     amountAcc: Amounts.parseOrThrow("LOCAL:49"),
     depositFeesAcc: Amounts.parseOrThrow("LOCAL:0.5"),
     lastDepositFee: Amounts.parseOrThrow("LOCAL:0.1"),
@@ -191,18 +194,18 @@ test("pay: select one coin to pay with fee", (t) => {
     tally,
   );
 
-  expect(t, coins).deep.equal({
+  t.deepEqual(coins, {
     "hash0;32;http://exchange.localhost/": {
       exchangeBaseUrl: "http://exchange.localhost/";,
       denomPubHash: "hash0",
       maxAge: 32,
       contributions: [Amounts.parseOrThrow("LOCAL:2.2")],
-      expireDeposit: TalerProtocolTimestamp.fromSeconds(1702412542),
-      expireWithdraw: TalerProtocolTimestamp.fromSeconds(1702412542),
+      expireDeposit: inTheDistantFuture,
+      expireWithdraw: inTheDistantFuture,
     },
   });
 
-  expect(t, tally).deep.equal({
+  t.deepEqual(tally, {
     amountPayRemaining: Amounts.parseOrThrow("LOCAL:2"),
     amountWireFeeLimitRemaining: zero,
     amountDepositFeeLimitRemaining: zero,
@@ -244,19 +247,3 @@ function createCandidates(
     };
   });
 }
-
-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),
-    },
-  };
-}

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