aboutsummaryrefslogtreecommitdiff
path: root/src/wallet-test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet-test.ts')
-rw-r--r--src/wallet-test.ts226
1 files changed, 84 insertions, 142 deletions
diff --git a/src/wallet-test.ts b/src/wallet-test.ts
index 56b5e6027..2c3ed52d0 100644
--- a/src/wallet-test.ts
+++ b/src/wallet-test.ts
@@ -1,30 +1,57 @@
import {test} from "ava";
-import {mkAmount} from "./types";
+import * as types from "./types";
import * as wallet from "./wallet";
+function a(x: string): types.AmountJson {
+ let amt = types.Amounts.parse(x);
+ if (!amt) {
+ throw Error("invalid amount");
+ }
+ return amt;
+}
-test("coin selection 1", t => {
- let cds: any = [];
- cds.push({
+function fakeCwd(current: string, value: string, feeDeposit: string): wallet.CoinWithDenom {
+ return {
coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
+ currentAmount: a(current),
+ coinPub: "(mock)",
+ coinPriv: "(mock)",
+ denomPub: "(mock)",
+ denomSig: "(mock)",
+ exchangeBaseUrl: "(mock)",
+ blindingKey: "(mock)",
+ reservePub: "(mock)",
+ status: types.CoinStatus.Fresh,
},
denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
+ value: a(value),
+ feeDeposit: a(feeDeposit),
+ denomPub: "(mock)",
+ denomPubHash: "(mock)",
+ feeWithdraw: a("EUR:0.0"),
+ feeRefresh: a("EUR:0.0"),
+ feeRefund: a("EUR:0.0"),
+ stampStart: "(mock)",
+ stampExpireWithdraw: "(mock)",
+ stampExpireLegal: "(mock)",
+ stampExpireDeposit: "(mock)",
+ masterSig: "(mock)",
+ status: types.DenominationStatus.VerifiedGood,
+ isOffered: true,
+ exchangeBaseUrl: "(mock)",
},
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
+ }
+}
+
+
- let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,5,"EUR"));
+test("coin selection 1", t => {
+ let cds: wallet.CoinWithDenom[] = [
+ fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.1"),
+ fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.0"),
+ ];
+
+ let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.1"));
if (!res) {
t.fail();
return;
@@ -35,37 +62,13 @@ test("coin selection 1", t => {
test("coin selection 2", t => {
- let cds: any = [];
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
- // Merchant covers the fee, this one shouldn't be used
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
-
- let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,5,"EUR"));
+ let cds: wallet.CoinWithDenom[] = [
+ fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+ fakeCwd("EUR:1.0", "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"),
+ ];
+ let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.5"));
if (!res) {
t.fail();
return;
@@ -75,37 +78,14 @@ test("coin selection 2", t => {
});
-test("coin selection 2", t => {
- let cds: any = [];
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
-
- let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,2,"EUR"));
+test("coin selection 3", t => {
+ let cds: wallet.CoinWithDenom[] = [
+ fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+ fakeCwd("EUR:1.0", "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"),
+ ];
+ let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.5"));
if (!res) {
t.fail();
return;
@@ -116,37 +96,13 @@ test("coin selection 2", t => {
-test("coin selection 3", t => {
- let cds: any = [];
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
- },
- });
-
- let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,2,"EUR"));
+test("coin selection 4", t => {
+ let cds: wallet.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"),
+ ];
+ let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.2"));
if (!res) {
t.fail();
return;
@@ -156,38 +112,24 @@ test("coin selection 3", t => {
});
-test("coin selection 3", t => {
- let cds: any = [];
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 0, "EUR"),
- },
- });
- cds.push({
- coin: {
- currentAmount: mkAmount(1, 0, "EUR"),
- },
- denom: {
- value: mkAmount(1, 0, "EUR"),
- fee_deposit: mkAmount(0, 5, "EUR"),
- },
- });
-
- let res = wallet.selectCoins(cds, mkAmount(4,0,"EUR"), mkAmount(0,2,"EUR"));
+test("coin selection 5", t => {
+ let cds: wallet.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"),
+ ];
+ let res = wallet.selectCoins(cds, a("EUR:4.0"), a("EUR:0.2"));
t.true(!res);
t.pass();
+});
+
+test("coin selection 6", t => {
+ let cds: wallet.CoinWithDenom[] = [
+ fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+ fakeCwd("EUR:1.0", "EUR:1.0", "EUR:0.5"),
+ ];
+ let res = wallet.selectCoins(cds, a("EUR:2.0"), a("EUR:0.2"));
+ t.true(!res);
+ t.pass();
});