aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/taler-wallet-core/package.json2
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.test.ts (renamed from packages/taler-wallet-core/src/operations/withdraw-test.ts)0
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.test.ts (renamed from packages/taler-wallet-core/src/util/coinSelection-test.ts)68
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts3
-rw-r--r--packages/taler-wallet-core/src/util/helpers.test.ts (renamed from packages/taler-wallet-core/src/util/helpers-test.ts)0
5 files changed, 71 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/package.json b/packages/taler-wallet-core/package.json
index 15485cb56..de974469d 100644
--- a/packages/taler-wallet-core/package.json
+++ b/packages/taler-wallet-core/package.json
@@ -71,7 +71,7 @@
"esm"
],
"files": [
- "src/**/*-test.*"
+ "src/**/*.test.*"
],
"typescript": {
"extensions": [
diff --git a/packages/taler-wallet-core/src/operations/withdraw-test.ts b/packages/taler-wallet-core/src/operations/withdraw.test.ts
index ad52a5f0c..ad52a5f0c 100644
--- a/packages/taler-wallet-core/src/operations/withdraw-test.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.test.ts
diff --git a/packages/taler-wallet-core/src/util/coinSelection-test.ts b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index 962a14835..bfcd05cce 100644
--- a/packages/taler-wallet-core/src/util/coinSelection-test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -184,3 +184,71 @@ test("coin selection 6", (t) => {
t.true(!res);
t.pass();
});
+
+test("coin selection 7", (t) => {
+ const acis: AvailableCoinInfo[] = [
+ fakeAci("EUR:1.0", "EUR:0.1"),
+ fakeAci("EUR:1.0", "EUR:0.1"),
+ ];
+ const res = selectPayCoins({
+ candidates: {
+ candidateCoins: acis,
+ wireFeesPerExchange: {},
+ },
+ contractTermsAmount: a("EUR:2.0"),
+ depositFeeLimit: a("EUR:0.2"),
+ wireFeeLimit: a("EUR:0"),
+ wireFeeAmortization: 1,
+ });
+ t.truthy(res);
+ t.true(Amounts.cmp(res!.customerDepositFees, "EUR:0.0") === 0);
+ t.true(
+ Amounts.cmp(Amounts.sum(res!.coinContributions).amount, "EUR:2.0") === 0,
+ );
+ t.pass();
+});
+
+test("coin selection 8", (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"),
+ ];
+ const res = selectPayCoins({
+ candidates: {
+ candidateCoins: acis,
+ wireFeesPerExchange: {},
+ },
+ contractTermsAmount: a("EUR:1.1"),
+ depositFeeLimit: a("EUR:0.4"),
+ wireFeeLimit: a("EUR:0"),
+ wireFeeAmortization: 1,
+ });
+ t.truthy(res);
+ t.true(res!.coinContributions.length === 3);
+ t.pass();
+});
+
+test("coin selection 9", (t) => {
+ const acis: AvailableCoinInfo[] = [
+ fakeAci("EUR:1.0", "EUR:0.2"),
+ fakeAci("EUR:0.2", "EUR:0.2"),
+ ];
+ const res = selectPayCoins({
+ candidates: {
+ candidateCoins: acis,
+ wireFeesPerExchange: {},
+ },
+ contractTermsAmount: a("EUR:1.2"),
+ depositFeeLimit: a("EUR:0.4"),
+ wireFeeLimit: a("EUR:0"),
+ wireFeeAmortization: 1,
+ });
+ t.truthy(res);
+ t.true(res!.coinContributions.length === 2);
+ t.true(
+ Amounts.cmp(Amounts.sum(res!.coinContributions).amount, "EUR:1.2") === 0,
+ );
+ t.pass();
+});
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index a840993c4..e1fec5c97 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -284,9 +284,10 @@ export function selectPayCoins(
for (const aci of candidateCoins) {
// Don't use this coin if depositing it is more expensive than
// the amount it would give the merchant.
- if (Amounts.cmp(aci.feeDeposit, aci.availableAmount) >= 0) {
+ if (Amounts.cmp(aci.feeDeposit, aci.availableAmount) > 0) {
continue;
}
+
if (Amounts.isZero(tally.amountPayRemaining)) {
// We have spent enough!
break;
diff --git a/packages/taler-wallet-core/src/util/helpers-test.ts b/packages/taler-wallet-core/src/util/helpers.test.ts
index dbecf14b8..dbecf14b8 100644
--- a/packages/taler-wallet-core/src/util/helpers-test.ts
+++ b/packages/taler-wallet-core/src/util/helpers.test.ts