aboutsummaryrefslogtreecommitdiff
path: root/src/types-test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/types-test.ts')
-rw-r--r--src/types-test.ts78
1 files changed, 51 insertions, 27 deletions
diff --git a/src/types-test.ts b/src/types-test.ts
index 56a826441..38cb9260a 100644
--- a/src/types-test.ts
+++ b/src/types-test.ts
@@ -15,12 +15,16 @@
*/
import test from "ava";
-import * as Amounts from "./amounts";
+import * as Amounts from "./util/amounts";
import { ContractTerms } from "./talerTypes";
-const amt = (value: number, fraction: number, currency: string): Amounts.AmountJson => ({value, fraction, currency});
+const amt = (
+ value: number,
+ fraction: number,
+ currency: string,
+): Amounts.AmountJson => ({ value, fraction, currency });
-test("amount addition (simple)", (t) => {
+test("amount addition (simple)", t => {
const a1 = amt(1, 0, "EUR");
const a2 = amt(1, 0, "EUR");
const a3 = amt(2, 0, "EUR");
@@ -28,14 +32,14 @@ test("amount addition (simple)", (t) => {
t.pass();
});
-test("amount addition (saturation)", (t) => {
+test("amount addition (saturation)", t => {
const a1 = amt(1, 0, "EUR");
const res = Amounts.add(amt(Amounts.maxAmountValue, 0, "EUR"), a1);
t.true(res.saturated);
t.pass();
});
-test("amount subtraction (simple)", (t) => {
+test("amount subtraction (simple)", t => {
const a1 = amt(2, 5, "EUR");
const a2 = amt(1, 0, "EUR");
const a3 = amt(1, 5, "EUR");
@@ -43,7 +47,7 @@ test("amount subtraction (simple)", (t) => {
t.pass();
});
-test("amount subtraction (saturation)", (t) => {
+test("amount subtraction (saturation)", t => {
const a1 = amt(0, 0, "EUR");
const a2 = amt(1, 0, "EUR");
let res = Amounts.sub(a1, a2);
@@ -53,8 +57,7 @@ test("amount subtraction (saturation)", (t) => {
t.pass();
});
-
-test("amount comparison", (t) => {
+test("amount comparison", t => {
t.is(Amounts.cmp(amt(1, 0, "EUR"), amt(1, 0, "EUR")), 0);
t.is(Amounts.cmp(amt(1, 1, "EUR"), amt(1, 0, "EUR")), 1);
t.is(Amounts.cmp(amt(1, 1, "EUR"), amt(1, 2, "EUR")), -1);
@@ -65,18 +68,36 @@ test("amount comparison", (t) => {
t.pass();
});
-
-test("amount parsing", (t) => {
- t.is(Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:0"),
- amt(0, 0, "TESTKUDOS")), 0);
- t.is(Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:10"),
- amt(10, 0, "TESTKUDOS")), 0);
- t.is(Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:0.1"),
- amt(0, 10000000, "TESTKUDOS")), 0);
- t.is(Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:0.00000001"),
- amt(0, 1, "TESTKUDOS")), 0);
- t.is(Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:4503599627370496.99999999"),
- amt(4503599627370496, 99999999, "TESTKUDOS")), 0);
+test("amount parsing", t => {
+ t.is(
+ Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:0"), amt(0, 0, "TESTKUDOS")),
+ 0,
+ );
+ t.is(
+ Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:10"), amt(10, 0, "TESTKUDOS")),
+ 0,
+ );
+ t.is(
+ Amounts.cmp(
+ Amounts.parseOrThrow("TESTKUDOS:0.1"),
+ amt(0, 10000000, "TESTKUDOS"),
+ ),
+ 0,
+ );
+ t.is(
+ Amounts.cmp(
+ Amounts.parseOrThrow("TESTKUDOS:0.00000001"),
+ amt(0, 1, "TESTKUDOS"),
+ ),
+ 0,
+ );
+ t.is(
+ Amounts.cmp(
+ Amounts.parseOrThrow("TESTKUDOS:4503599627370496.99999999"),
+ amt(4503599627370496, 99999999, "TESTKUDOS"),
+ ),
+ 0,
+ );
t.throws(() => Amounts.parseOrThrow("foo:"));
t.throws(() => Amounts.parseOrThrow("1.0"));
t.throws(() => Amounts.parseOrThrow("42"));
@@ -85,14 +106,18 @@ test("amount parsing", (t) => {
t.throws(() => Amounts.parseOrThrow("EUR:.42"));
t.throws(() => Amounts.parseOrThrow("EUR:42."));
t.throws(() => Amounts.parseOrThrow("TESTKUDOS:4503599627370497.99999999"));
- t.is(Amounts.cmp(Amounts.parseOrThrow("TESTKUDOS:0.99999999"),
- amt(0, 99999999, "TESTKUDOS")), 0);
+ t.is(
+ Amounts.cmp(
+ Amounts.parseOrThrow("TESTKUDOS:0.99999999"),
+ amt(0, 99999999, "TESTKUDOS"),
+ ),
+ 0,
+ );
t.throws(() => Amounts.parseOrThrow("TESTKUDOS:0.999999991"));
t.pass();
});
-
-test("amount stringification", (t) => {
+test("amount stringification", t => {
t.is(Amounts.toString(amt(0, 0, "TESTKUDOS")), "TESTKUDOS:0");
t.is(Amounts.toString(amt(4, 94000000, "TESTKUDOS")), "TESTKUDOS:4.94");
t.is(Amounts.toString(amt(0, 10000000, "TESTKUDOS")), "TESTKUDOS:0.1");
@@ -103,13 +128,12 @@ test("amount stringification", (t) => {
t.pass();
});
-
-test("contract terms validation", (t) => {
+test("contract terms validation", t => {
const c = {
H_wire: "123",
amount: "EUR:1.5",
auditors: [],
- exchanges: [{master_pub: "foo", url: "foo"}],
+ exchanges: [{ master_pub: "foo", url: "foo" }],
fulfillment_url: "foo",
max_fee: "EUR:1.5",
merchant_pub: "12345",