From a30615c2118659e5b928593a800075e5285c65c3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 15 Dec 2023 12:12:57 +0100 Subject: wallet-core: fix unit test --- .../src/util/coinSelection.test.ts | 49 ++++++++-------------- 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'packages/taler-wallet-core/src/util') 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 = { - deep: { - equal(another: T): ReturnType; - equals(another: T): ReturnType; - }; -}; - -function expect(t: ExecutionContext, thing: T): Tester { - return { - deep: { - equal: (another: T) => t.deepEqual(thing, another), - equals: (another: T) => t.deepEqual(thing, another), - }, - }; -} -- cgit v1.2.3