From 0148d40f880674fe2171808a31bbed48dbf6337a Mon Sep 17 00:00:00 2001
From: Vlad Stan <stan.v.vlad@gmail.com>
Date: Wed, 2 Sep 2020 10:08:31 +0300
Subject: [PATCH] add unit tests for UInt31 and BIP32Path

---
 test/types.spec.ts | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/test/types.spec.ts b/test/types.spec.ts
index 363b83c..1be3170 100644
--- a/test/types.spec.ts
+++ b/test/types.spec.ts
@@ -54,4 +54,41 @@ describe('types', () => {
       });
     });
   });
+
+  describe('UInt31', () => {
+    const UINT31_MAX = Math.pow(2, 31) - 1;
+    it('return true for valid values', () => {
+      assert.strictEqual(types.UInt31(0), true);
+      assert.strictEqual(types.UInt31(1000), true);
+      assert.strictEqual(types.UInt31(UINT31_MAX), true);
+    });
+
+    it('return false for negative values', () => {
+      assert.strictEqual(types.UInt31(-1), false);
+      assert.strictEqual(types.UInt31(-UINT31_MAX), false);
+    });
+
+    it('return false for values > UINT31_MAX', () => {
+      assert.strictEqual(types.UInt31(UINT31_MAX + 1), false);
+    });
+  });
+
+  describe('BIP32Path', () => {
+    it('return true for valid paths', () => {
+      assert.strictEqual(types.BIP32Path("m/0'/0'"), true);
+      assert.strictEqual(types.BIP32Path("m/0'/0"), true);
+      assert.strictEqual(types.BIP32Path("m/0'/1'/2'/3/4'"), true);
+    });
+
+    it('return false for invalid paths', () => {
+      assert.strictEqual(types.BIP32Path('m'), false);
+      assert.strictEqual(types.BIP32Path("n/0'/0'"), false);
+      assert.strictEqual(types.BIP32Path("m/0'/x"), false);
+    });
+
+    it('return "BIP32 derivation path" for JSON.strigify()', () => {
+      const toJsonValue = JSON.stringify(types.BIP32Path);
+      assert.equal(toJsonValue, '"BIP32 derivation path"');
+    });
+  });
 });