From 19d9ccd0c1cd4d6fbf51c7f38e122fd26c550788 Mon Sep 17 00:00:00 2001 From: sivasathyaseeelan Date: Tue, 28 Jan 2025 15:23:40 +0530 Subject: [PATCH 1/2] added missing tests in utils Signed-off-by: sivasathyaseeelan --- core/api/test/unit/utils/index.spec.ts | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/core/api/test/unit/utils/index.spec.ts b/core/api/test/unit/utils/index.spec.ts index f663f71938..501f87cfe8 100644 --- a/core/api/test/unit/utils/index.spec.ts +++ b/core/api/test/unit/utils/index.spec.ts @@ -1,4 +1,17 @@ -import { btc2sat, sat2btc } from "@/domain/bitcoin" +import { + btc2sat, + sat2btc, + toSats, + toMilliSatsFromNumber, + toMilliSatsFromString, + checkedToCurrencyBaseAmount, + checkedToSats, + isSha256Hash, +} from "@/domain/bitcoin" +import { + InvalidCurrencyBaseAmountError, + InvalidSatoshiAmountError, +} from "@/domain/errors"; import { elapsedSinceTimestamp } from "@/utils" describe("utils", () => { @@ -22,6 +35,52 @@ describe("utils", () => { }) }) + describe("toSats", () => { + it("toSats converts number or bigint to satoshis", () => { + expect(toSats(12345)).toBe(12345); + expect(toSats(BigInt(12345))).toBe(12345); + }) + }) + + describe("toMilliSatsFromNumber", () => { + it("toMilliSatsFromNumber converts number to millisatoshis", () => { + expect(toMilliSatsFromNumber(12345)).toBe(12345); + }) + }) + + describe("toMilliSatsFromString", () => { + it("toMilliSatsFromString converts string to millisatoshis", () => { + expect(toMilliSatsFromString("12345")).toBe(12345); + expect(toMilliSatsFromString("0")).toBe(0); + }) + }) + + describe("checkedToCurrencyBaseAmount", () => { + it("checkedToCurrencyBaseAmount validates currency base amount", () => { + expect(checkedToCurrencyBaseAmount(12345)).toBe(12345); + expect(checkedToCurrencyBaseAmount(0)).toBeInstanceOf( + InvalidCurrencyBaseAmountError + ); + }) + }) + + describe("checkedToSats", () => { + it("checkedToSats validates satoshi amount", () => { + expect(checkedToSats(12345)).toBe(12345); + expect(checkedToSats(0)).toBeInstanceOf(InvalidSatoshiAmountError); + }) + }) + + describe("isSha256Hash", () => { + it("isSha256Hash validates SHA-256 hash format", () => { + expect(isSha256Hash("a3c45e9f8b7d0f4c5a1234567890abcdef1234567890abcdef1234567890abcd")).toBe( + true + ); + expect(isSha256Hash("not-a-hash")).toBe(false); + expect(isSha256Hash("123")).toBe(false); + }) + }) + describe("elapsedFromTimestamp", () => { it("returns expected number of seconds for elapsed time", () => { const timestamp = new Date() From dc0954bd9939e6755e6732644527cf60cb0fa97d Mon Sep 17 00:00:00 2001 From: sivasathyaseeelan Date: Wed, 5 Feb 2025 15:58:21 +0530 Subject: [PATCH 2/2] added prettier Signed-off-by: sivasathyaseeelan --- core/api/test/unit/utils/index.spec.ts | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/core/api/test/unit/utils/index.spec.ts b/core/api/test/unit/utils/index.spec.ts index 501f87cfe8..0efae8851c 100644 --- a/core/api/test/unit/utils/index.spec.ts +++ b/core/api/test/unit/utils/index.spec.ts @@ -11,7 +11,7 @@ import { import { InvalidCurrencyBaseAmountError, InvalidSatoshiAmountError, -} from "@/domain/errors"; +} from "@/domain/errors" import { elapsedSinceTimestamp } from "@/utils" describe("utils", () => { @@ -37,47 +37,47 @@ describe("utils", () => { describe("toSats", () => { it("toSats converts number or bigint to satoshis", () => { - expect(toSats(12345)).toBe(12345); - expect(toSats(BigInt(12345))).toBe(12345); + expect(toSats(12345)).toBe(12345) + expect(toSats(BigInt(12345))).toBe(12345) }) }) describe("toMilliSatsFromNumber", () => { it("toMilliSatsFromNumber converts number to millisatoshis", () => { - expect(toMilliSatsFromNumber(12345)).toBe(12345); + expect(toMilliSatsFromNumber(12345)).toBe(12345) }) }) describe("toMilliSatsFromString", () => { it("toMilliSatsFromString converts string to millisatoshis", () => { - expect(toMilliSatsFromString("12345")).toBe(12345); - expect(toMilliSatsFromString("0")).toBe(0); + expect(toMilliSatsFromString("12345")).toBe(12345) + expect(toMilliSatsFromString("0")).toBe(0) }) }) describe("checkedToCurrencyBaseAmount", () => { it("checkedToCurrencyBaseAmount validates currency base amount", () => { - expect(checkedToCurrencyBaseAmount(12345)).toBe(12345); + expect(checkedToCurrencyBaseAmount(12345)).toBe(12345) expect(checkedToCurrencyBaseAmount(0)).toBeInstanceOf( - InvalidCurrencyBaseAmountError - ); + InvalidCurrencyBaseAmountError, + ) }) }) describe("checkedToSats", () => { it("checkedToSats validates satoshi amount", () => { - expect(checkedToSats(12345)).toBe(12345); - expect(checkedToSats(0)).toBeInstanceOf(InvalidSatoshiAmountError); + expect(checkedToSats(12345)).toBe(12345) + expect(checkedToSats(0)).toBeInstanceOf(InvalidSatoshiAmountError) }) }) describe("isSha256Hash", () => { it("isSha256Hash validates SHA-256 hash format", () => { - expect(isSha256Hash("a3c45e9f8b7d0f4c5a1234567890abcdef1234567890abcdef1234567890abcd")).toBe( - true - ); - expect(isSha256Hash("not-a-hash")).toBe(false); - expect(isSha256Hash("123")).toBe(false); + expect( + isSha256Hash("a3c45e9f8b7d0f4c5a1234567890abcdef1234567890abcdef1234567890abcd"), + ).toBe(true) + expect(isSha256Hash("not-a-hash")).toBe(false) + expect(isSha256Hash("123")).toBe(false) }) })