diff options
Diffstat (limited to 'src/wallet-test.ts')
-rw-r--r-- | src/wallet-test.ts | 112 |
1 files changed, 42 insertions, 70 deletions
diff --git a/src/wallet-test.ts b/src/wallet-test.ts index c937de3f5..a465db517 100644 --- a/src/wallet-test.ts +++ b/src/wallet-test.ts @@ -19,11 +19,9 @@ import test from "ava"; import * as dbTypes from "./types/dbTypes"; import * as types from "./types/walletTypes"; -import * as wallet from "./wallet"; - import { AmountJson } from "./util/amounts"; import * as Amounts from "./util/amounts"; -import { selectPayCoins } from "./operations/pay"; +import { selectPayCoins, AvailableCoinInfo } from "./operations/pay"; function a(x: string): AmountJson { const amt = Amounts.parse(x); @@ -33,125 +31,99 @@ function a(x: string): AmountJson { return amt; } -function fakeCwd( + +function fakeAci( current: string, - value: string, feeDeposit: string, -): types.CoinWithDenom { +): AvailableCoinInfo { return { - coin: { - blindingKey: "(mock)", - coinPriv: "(mock)", - coinPub: "(mock)", - currentAmount: a(current), - denomPub: "(mock)", - denomPubHash: "(mock)", - denomSig: "(mock)", - exchangeBaseUrl: "(mock)", - reservePub: "(mock)", - coinIndex: -1, - withdrawSessionId: "", - status: dbTypes.CoinStatus.Fresh, - }, - denom: { - denomPub: "(mock)", - denomPubHash: "(mock)", - exchangeBaseUrl: "(mock)", - feeDeposit: a(feeDeposit), - feeRefresh: a("EUR:0.0"), - feeRefund: a("EUR:0.0"), - feeWithdraw: a("EUR:0.0"), - isOffered: true, - masterSig: "(mock)", - stampExpireDeposit: { t_ms: 0 }, - stampExpireLegal: { t_ms: 0 }, - stampExpireWithdraw: { t_ms: 0 }, - stampStart: { t_ms: 0 }, - status: dbTypes.DenominationStatus.VerifiedGood, - value: a(value), - }, - }; + availableAmount: a(current), + coinPub: "foobar", + denomPub: "foobar", + feeDeposit: a(feeDeposit), + } + } test("coin selection 1", t => { - const cds: types.CoinWithDenom[] = [ - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.1"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"), + const acis: AvailableCoinInfo[] = [ + fakeAci("EUR:1.0", "EUR:0.1"), + fakeAci("EUR:1.0", "EUR:0.0"), ]; - const res = selectPayCoins([], cds, a("EUR:2.0"), a("EUR:0.1")); + const res = selectPayCoins(acis, a("EUR:2.0"), a("EUR:0.1")); if (!res) { t.fail(); return; } - t.true(res.cds.length === 2); + t.true(res.coinPubs.length === 2); t.pass(); }); test("coin selection 2", t => { - const cds: types.CoinWithDenom[] = [ - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"), + 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 - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"), + fakeAci("EUR:1.0", "EUR:0.0"), ]; - const res = selectPayCoins([], cds, a("EUR:2.0"), a("EUR:0.5")); + const res = selectPayCoins(acis, a("EUR:2.0"), a("EUR:0.5")); if (!res) { t.fail(); return; } - t.true(res.cds.length === 2); + t.true(res.coinPubs.length === 2); t.pass(); }); test("coin selection 3", t => { - const cds: types.CoinWithDenom[] = [ - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), + 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 - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"), + fakeAci("EUR:1.0", "EUR:0.0"), ]; - const res = selectPayCoins([], cds, a("EUR:2.0"), a("EUR:0.5")); + const res = selectPayCoins(acis, a("EUR:2.0"), a("EUR:0.5")); if (!res) { t.fail(); return; } - t.true(res.cds.length === 2); + t.true(res.coinPubs.length === 2); t.pass(); }); test("coin selection 4", t => { - const cds: types.CoinWithDenom[] = [ - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), + const acis: AvailableCoinInfo[] = [ + fakeAci("EUR:1.0", "EUR:0.5"), + fakeAci("EUR:1.0", "EUR:0.5"), + fakeAci("EUR:1.0", "EUR:0.5"), ]; - const res = selectPayCoins([], cds, a("EUR:2.0"), a("EUR:0.2")); + const res = selectPayCoins(acis, a("EUR:2.0"), a("EUR:0.5")); if (!res) { t.fail(); return; } - t.true(res.cds.length === 3); + t.true(res.coinPubs.length === 3); t.pass(); }); test("coin selection 5", t => { - const cds: types.CoinWithDenom[] = [ - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), + const acis: AvailableCoinInfo[] = [ + fakeAci("EUR:1.0", "EUR:0.5"), + fakeAci("EUR:1.0", "EUR:0.5"), + fakeAci("EUR:1.0", "EUR:0.5"), ]; - const res = selectPayCoins([], cds, a("EUR:4.0"), a("EUR:0.2")); + const res = selectPayCoins(acis, a("EUR:4.0"), a("EUR:0.2")); t.true(!res); t.pass(); }); test("coin selection 6", t => { - const cds: types.CoinWithDenom[] = [ - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), - fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"), + const acis: AvailableCoinInfo[] = [ + fakeAci("EUR:1.0", "EUR:0.5"), + fakeAci("EUR:1.0", "EUR:0.5"), ]; - const res = selectPayCoins([], cds, a("EUR:2.0"), a("EUR:0.2")); + const res = selectPayCoins(acis, a("EUR:2.0"), a("EUR:0.2")); t.true(!res); t.pass(); }); |