summaryrefslogtreecommitdiff
path: root/src/wallet-test.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-14 03:37:47 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-14 03:37:47 +0100
commitce334320363618c6c1ed3d2ae598d49cae98753c (patch)
tree1c77d9f7f8e193891b249410a4924e5d83532385 /src/wallet-test.ts
parentaf901cb892a5ecd493915e49c04dfbecf00c8b0e (diff)
downloadwallet-core-ce334320363618c6c1ed3d2ae598d49cae98753c.tar.gz
wallet-core-ce334320363618c6c1ed3d2ae598d49cae98753c.tar.bz2
wallet-core-ce334320363618c6c1ed3d2ae598d49cae98753c.zip
add test cases for coin selection
Diffstat (limited to 'src/wallet-test.ts')
-rw-r--r--src/wallet-test.ts193
1 files changed, 193 insertions, 0 deletions
diff --git a/src/wallet-test.ts b/src/wallet-test.ts
new file mode 100644
index 000000000..144b2054c
--- /dev/null
+++ b/src/wallet-test.ts
@@ -0,0 +1,193 @@
+import {test, TestLib} from "testlib/talertest";
+import {mkAmount} from "./types";
+import * as wallet from "./wallet";
+
+
+test("coin selection 1", (t: TestLib) => {
+ 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;
+ }
+ t.assert(res.length == 2);
+ t.pass();
+});
+
+
+test("coin selection 2", (t: TestLib) => {
+ 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;
+ }
+ t.assert(res.length == 2);
+ t.pass();
+});
+
+
+test("coin selection 2", (t: TestLib) => {
+ 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;
+ }
+ t.assert(res.length == 2);
+ t.pass();
+});
+
+
+
+test("coin selection 3", (t: TestLib) => {
+ 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;
+ }
+ t.assert(res.length == 3);
+ t.pass();
+});
+
+
+test("coin selection 3", (t: TestLib) => {
+ 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"));
+ t.assert(!res);
+ t.pass();
+
+});