aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/.gitignore1
-rw-r--r--packages/taler-wallet-core/package.json5
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.test.ts3
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.test.ts51
4 files changed, 35 insertions, 25 deletions
diff --git a/packages/taler-wallet-core/.gitignore b/packages/taler-wallet-core/.gitignore
index 502167fa0..cb5a51ac5 100644
--- a/packages/taler-wallet-core/.gitignore
+++ b/packages/taler-wallet-core/.gitignore
@@ -1 +1,2 @@
/lib
+/coverage
diff --git a/packages/taler-wallet-core/package.json b/packages/taler-wallet-core/package.json
index 223aa05e4..76180e159 100644
--- a/packages/taler-wallet-core/package.json
+++ b/packages/taler-wallet-core/package.json
@@ -16,7 +16,8 @@
"compile": "tsc && rollup -c",
"pretty": "prettier --write src",
"test": "tsc && ava",
- "coverage": "tsc && nyc ava",
+ "coverage": "tsc && c8 --src src --all ava",
+ "coverage:html": "tsc && c8 -r html --src src --all ava",
"clean": "rimraf dist lib tsconfig.tsbuildinfo"
},
"files": [
@@ -42,6 +43,7 @@
"@typescript-eslint/eslint-plugin": "^5.9.0",
"@typescript-eslint/parser": "^5.9.0",
"ava": "^4.0.0",
+ "c8": "^7.11.0",
"eslint": "^8.6.0",
"eslint-config-airbnb-typescript": "^16.1.0",
"eslint-plugin-import": "^2.25.4",
@@ -49,7 +51,6 @@
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"jed": "^1.1.1",
- "nyc": "^15.1.0",
"po2json": "^0.4.5",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
diff --git a/packages/taler-wallet-core/src/operations/withdraw.test.ts b/packages/taler-wallet-core/src/operations/withdraw.test.ts
index 179852966..2c890a121 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.test.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts
@@ -357,9 +357,6 @@ test("withdrawal selection bug repro", (t) => {
const res = selectWithdrawalDenominations(amount, denoms);
- console.error("cost", Amounts.stringify(res.totalWithdrawCost));
- console.error("withdraw amount", Amounts.stringify(amount));
-
t.assert(Amounts.cmp(res.totalWithdrawCost, amount) <= 0);
t.pass();
});
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index b4dc2a18b..49f8d1635 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -42,11 +42,12 @@ function fakeAci(current: string, feeDeposit: string): AvailableCoinInfo {
};
}
-test("coin selection 1", (t) => {
+test("it should be able to pay if merchant takes the fees", (t) => {
const acis: AvailableCoinInfo[] = [
fakeAci("EUR:1.0", "EUR:0.1"),
fakeAci("EUR:1.0", "EUR:0.0"),
];
+ acis.forEach((x, i) => x.coinPub = String(i));
const res = selectPayCoins({
candidates: {
@@ -63,17 +64,18 @@ test("coin selection 1", (t) => {
t.fail();
return;
}
- t.true(res.coinPubs.length === 2);
+ t.deepEqual(res.coinPubs, ["1", "0"]);
t.pass();
});
-test("coin selection 2", (t) => {
+test("it should take the last two coins if it pays less fees", (t) => {
const acis: AvailableCoinInfo[] = [
fakeAci("EUR:1.0", "EUR:0.5"),
fakeAci("EUR:1.0", "EUR:0.0"),
// Merchant covers the fee, this one shouldn't be used
fakeAci("EUR:1.0", "EUR:0.0"),
];
+ acis.forEach((x, i) => x.coinPub = String(i));
const res = selectPayCoins({
candidates: {
@@ -90,17 +92,18 @@ test("coin selection 2", (t) => {
t.fail();
return;
}
- t.true(res.coinPubs.length === 2);
+ t.deepEqual(res.coinPubs, ["1", "2"]);
t.pass();
});
-test("coin selection 3", (t) => {
+test("it should take the last coins if the merchant doest not take all the fee", (t) => {
const acis: AvailableCoinInfo[] = [
fakeAci("EUR:1.0", "EUR:0.5"),
fakeAci("EUR:1.0", "EUR:0.5"),
// this coin should be selected instead of previous one with fee
fakeAci("EUR:1.0", "EUR:0.0"),
- ];
+ ]
+ acis.forEach((x, i) => x.coinPub = String(i));
const res = selectPayCoins({
candidates: {
@@ -117,15 +120,15 @@ test("coin selection 3", (t) => {
t.fail();
return;
}
- t.true(res.coinPubs.length === 2);
+ t.deepEqual(res.coinPubs, ["2", "0"]);
t.pass();
});
-test("coin selection 4", (t) => {
+test("it should use 3 coins to cover fees and payment", (t) => {
const acis: AvailableCoinInfo[] = [
- fakeAci("EUR:1.0", "EUR:0.5"),
- fakeAci("EUR:1.0", "EUR:0.5"),
- fakeAci("EUR:1.0", "EUR:0.5"),
+ fakeAci("EUR:1.0", "EUR:0.5"), //contributed value 1 (fee by the merchant)
+ fakeAci("EUR:1.0", "EUR:0.5"), //contributed value .5
+ fakeAci("EUR:1.0", "EUR:0.5"), //contributed value .5
];
const res = selectPayCoins({
@@ -147,7 +150,7 @@ test("coin selection 4", (t) => {
t.pass();
});
-test("coin selection 5", (t) => {
+test("it should return undefined if there is not enough coins", (t) => {
const acis: AvailableCoinInfo[] = [
fakeAci("EUR:1.0", "EUR:0.5"),
fakeAci("EUR:1.0", "EUR:0.5"),
@@ -169,7 +172,7 @@ test("coin selection 5", (t) => {
t.pass();
});
-test("coin selection 6", (t) => {
+test("it should return undefined if there is not enough coins (taking into account fees)", (t) => {
const acis: AvailableCoinInfo[] = [
fakeAci("EUR:1.0", "EUR:0.5"),
fakeAci("EUR:1.0", "EUR:0.5"),
@@ -188,7 +191,7 @@ test("coin selection 6", (t) => {
t.pass();
});
-test("coin selection 7", (t) => {
+test("it should not count into customer fee if merchant can afford it", (t) => {
const acis: AvailableCoinInfo[] = [
fakeAci("EUR:1.0", "EUR:0.1"),
fakeAci("EUR:1.0", "EUR:0.1"),
@@ -211,13 +214,15 @@ test("coin selection 7", (t) => {
t.pass();
});
-test("coin selection 8", (t) => {
+test("it should use the coins that spent less relative fee", (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"),
];
+ acis.forEach((x, i) => x.coinPub = String(i));
+
const res = selectPayCoins({
candidates: {
candidateCoins: acis,
@@ -228,8 +233,11 @@ test("coin selection 8", (t) => {
wireFeeLimit: a("EUR:0"),
wireFeeAmortization: 1,
});
- t.truthy(res);
- t.true(res!.coinContributions.length === 3);
+ if (!res) {
+ t.fail();
+ return;
+ }
+ t.deepEqual(res.coinPubs, ["0", "2", "3"]);
t.pass();
});
@@ -248,10 +256,13 @@ test("coin selection 9", (t) => {
wireFeeLimit: a("EUR:0"),
wireFeeAmortization: 1,
});
- t.truthy(res);
- t.true(res!.coinContributions.length === 2);
+ if (!res) {
+ t.fail();
+ return;
+ }
+ t.true(res.coinContributions.length === 2);
t.true(
- Amounts.cmp(Amounts.sum(res!.coinContributions).amount, "EUR:1.2") === 0,
+ Amounts.cmp(Amounts.sum(res.coinContributions).amount, "EUR:1.2") === 0,
);
t.pass();
});