more real cases

This commit is contained in:
Sebastian 2023-06-20 17:50:07 -03:00
parent 77849fdf5d
commit 5c5586df99
No known key found for this signature in database
GPG Key ID: 173909D1A5F66069
2 changed files with 144 additions and 1 deletions

View File

@ -79,7 +79,12 @@ import {
} from "../index.js"; } from "../index.js";
import { InternalWalletState } from "../internal-wallet-state.js"; import { InternalWalletState } from "../internal-wallet-state.js";
import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
import { constructTaskIdentifier, OperationAttemptResult, spendCoins, TombstoneTag } from "./common.js"; import {
constructTaskIdentifier,
OperationAttemptResult,
spendCoins,
TombstoneTag,
} from "./common.js";
import { getExchangeDetails } from "./exchanges.js"; import { getExchangeDetails } from "./exchanges.js";
import { import {
extractContractData, extractContractData,

View File

@ -627,3 +627,141 @@ function asCoinList(v: { info: CoinInfo; size: number }[]): any {
return [c.info.value, c.size]; return [c.info.value, c.size];
}); });
} }
/**
* regression tests
*/
test("demo: withdraw raw 25", (t) => {
const coinList: Coin[] = [
[kudos`0.1`, 0],
[kudos`1`, 0],
[kudos`2`, 0],
[kudos`5`, 0],
[kudos`10`, 0],
];
const result = convertWithdrawalAmountFromAvailableCoins(
{
list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
exchanges: {},
},
kudos`25`,
TransactionAmountMode.Raw,
);
t.is(Amounts.stringifyValue(result.effective), "24.8");
t.is(Amounts.stringifyValue(result.raw), "24.92");
// coins received
// 8 x 0.1
// 2 x 0.2
// 2 x 10.0
// total effective 24.8
// fee 12 x 0.01 = 0.12
// total raw 24.92
// left in reserve 25 - 24.92 == 0.08
//current wallet impl: hides the left in reserve fee
//shows fee = 0.2
});
test("demo: deposit max after withdraw raw 25", (t) => {
const coinList: Coin[] = [
[kudos`0.1`, 8],
[kudos`1`, 0],
[kudos`2`, 2],
[kudos`5`, 0],
[kudos`10`, 2],
];
const result = getMaxDepositAmountForAvailableCoins(
{
list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
exchanges: {
one: {
wireFee: kudos`0.01`,
purseFee: kudos`0.00`,
creditDeadline: AbsoluteTime.never(),
debitDeadline: AbsoluteTime.never(),
},
},
},
"KUDOS",
);
t.is(Amounts.stringifyValue(result.effective), "24.8");
t.is(Amounts.stringifyValue(result.raw), "24.67");
// 8 x 0.1
// 2 x 0.2
// 2 x 10.0
// total effective 24.8
// deposit fee 12 x 0.01 = 0.12
// wire fee 0.01
// total raw: 24.8 - 0.13 = 24.67
// current wallet impl fee 0.14
});
test("demo: withdraw raw 13", (t) => {
const coinList: Coin[] = [
[kudos`0.1`, 0],
[kudos`1`, 0],
[kudos`2`, 0],
[kudos`5`, 0],
[kudos`10`, 0],
];
const result = convertWithdrawalAmountFromAvailableCoins(
{
list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
exchanges: {},
},
kudos`13`,
TransactionAmountMode.Raw,
);
t.is(Amounts.stringifyValue(result.effective), "12.8");
t.is(Amounts.stringifyValue(result.raw), "12.9");
// coins received
// 8 x 0.1
// 1 x 0.2
// 1 x 10.0
// total effective 12.8
// fee 10 x 0.01 = 0.10
// total raw 12.9
// left in reserve 13 - 12.9 == 0.1
//current wallet impl: hides the left in reserve fee
//shows fee = 0.2
});
test("demo: deposit max after withdraw raw 13", (t) => {
const coinList: Coin[] = [
[kudos`0.1`, 8],
[kudos`1`, 0],
[kudos`2`, 1],
[kudos`5`, 0],
[kudos`10`, 1],
];
const result = getMaxDepositAmountForAvailableCoins(
{
list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
exchanges: {
one: {
wireFee: kudos`0.01`,
purseFee: kudos`0.00`,
creditDeadline: AbsoluteTime.never(),
debitDeadline: AbsoluteTime.never(),
},
},
},
"KUDOS",
);
t.is(Amounts.stringifyValue(result.effective), "12.8");
t.is(Amounts.stringifyValue(result.raw), "12.69");
// 8 x 0.1
// 1 x 0.2
// 1 x 10.0
// total effective 12.8
// deposit fee 10 x 0.01 = 0.10
// wire fee 0.01
// total raw: 12.8 - 0.11 = 12.69
// current wallet impl fee 0.14
});