summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-12-15 12:12:57 +0100
committerFlorian Dold <florian@dold.me>2023-12-15 12:20:19 +0100
commita30615c2118659e5b928593a800075e5285c65c3 (patch)
tree52e45cba394d5f1f939d72cd0ab07c5591967fc4 /packages/taler-wallet-core/src/util
parent550f7ac5c1628f5f0e5008df8d7cdda34e9939bb (diff)
downloadwallet-core-a30615c2118659e5b928593a800075e5285c65c3.tar.gz
wallet-core-a30615c2118659e5b928593a800075e5285c65c3.tar.bz2
wallet-core-a30615c2118659e5b928593a800075e5285c65c3.zip
wallet-core: fix unit test
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.test.ts49
1 files 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),
- },
- };
-}