2017-05-27 19:20:27 +02:00
|
|
|
import {test} from "ava";
|
2016-11-14 03:37:47 +01:00
|
|
|
import {mkAmount} from "./types";
|
|
|
|
import * as wallet from "./wallet";
|
|
|
|
|
|
|
|
|
2017-05-27 19:20:27 +02:00
|
|
|
test("coin selection 1", t => {
|
2016-11-14 03:37:47 +01:00
|
|
|
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"),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
let res = wallet.selectCoins(cds, mkAmount(2,0,"EUR"), mkAmount(0,5,"EUR"));
|
|
|
|
if (!res) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-27 19:20:27 +02:00
|
|
|
t.true(res.length == 2);
|
2016-11-14 03:37:47 +01:00
|
|
|
t.pass();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-05-27 19:20:27 +02:00
|
|
|
test("coin selection 2", t => {
|
2016-11-14 03:37:47 +01:00
|
|
|
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"));
|
|
|
|
if (!res) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-27 19:20:27 +02:00
|
|
|
t.true(res.length == 2);
|
2016-11-14 03:37:47 +01:00
|
|
|
t.pass();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-05-27 19:20:27 +02:00
|
|
|
test("coin selection 2", t => {
|
2016-11-14 03:37:47 +01:00
|
|
|
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"));
|
|
|
|
if (!res) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-27 19:20:27 +02:00
|
|
|
t.true(res.length == 2);
|
2016-11-14 03:37:47 +01:00
|
|
|
t.pass();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-27 19:20:27 +02:00
|
|
|
test("coin selection 3", t => {
|
2016-11-14 03:37:47 +01:00
|
|
|
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"));
|
|
|
|
if (!res) {
|
|
|
|
t.fail();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-27 19:20:27 +02:00
|
|
|
t.true(res.length == 3);
|
2016-11-14 03:37:47 +01:00
|
|
|
t.pass();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-05-27 19:20:27 +02:00
|
|
|
test("coin selection 3", t => {
|
2016-11-14 03:37:47 +01:00
|
|
|
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"));
|
2017-05-27 19:20:27 +02:00
|
|
|
t.true(!res);
|
2016-11-14 03:37:47 +01:00
|
|
|
t.pass();
|
|
|
|
|
|
|
|
});
|