Skip to content

Commit

Permalink
test: add planckToTokens test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzuswapteam004 committed Sep 16, 2024
1 parent 2c865c4 commit f86f3c7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/util/src/planckToTokens.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { planckToTokens } from "./planckToTokens"

describe("planckToTokens", () => {
it("should correctly convert planck to tokens with given decimals", () => {
expect(planckToTokens("1000000", 6)).toBe("1")
expect(planckToTokens("123456789", 8)).toBe("1.23456789")
})

it("should return undefined if planck is not a string", () => {
expect(planckToTokens(1000000000 as unknown as string, 18)).toBeUndefined()
})

it("should return undefined if tokenDecimals is not a number", () => {
expect(planckToTokens("1000000000", "18" as unknown as number)).toBeUndefined()
})

it("should handle missing tokenDecimals", () => {
expect(planckToTokens("1000000000")).toBeUndefined()
})

it("should handle missing planck", () => {
expect(planckToTokens(undefined, 18)).toBeUndefined()
})

it("should handle invalid planck input", () => {
expect(planckToTokens("abc", 18)).toBe("NaN")
})
})

0 comments on commit f86f3c7

Please sign in to comment.