From 48f6a311ea56429d92148ee1cc12077b400490e9 Mon Sep 17 00:00:00 2001 From: Paul Razvan Berg Date: Tue, 28 Sep 2021 22:37:11 -0400 Subject: [PATCH] fix: relax type checking in "fromFp" function --- package.json | 2 +- src/fromBn.ts | 4 ++-- test/fromBn.test.ts | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index fba4e2f..e3a0694 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "coverage": "yarn nyc --nycrc-path ./.nycrc.yaml mocha", "lint": "yarn lint:ts && yarn prettier:check && yarn typecheck", "lint:ts": "eslint --config ./.eslintrc.yaml --ignore-path ./.eslintignore --ext .ts .", - "_postinstall": "husky install", + "postinstall": "husky install", "postpublish": "pinst --enable", "prepack": "yarn build", "prepublishOnly": "pinst --disable", diff --git a/src/fromBn.ts b/src/fromBn.ts index fad9adc..d0a56a7 100644 --- a/src/fromBn.ts +++ b/src/fromBn.ts @@ -4,8 +4,8 @@ import { BigNumber, FixedNumber } from "@ethersproject/bignumber"; * Convert a big number with a custom number of decimals to a stringified fixed-point number. */ export function fromBn(x: BigNumber, decimals: number = 18): string { - if (x === undefined || x instanceof BigNumber === false) { - throw new Error("Input must be an ethers BigNumber"); + if (x === undefined) { + throw new Error("Input must not be undefined"); } if (decimals < 1 || decimals > 77) { diff --git a/test/fromBn.test.ts b/test/fromBn.test.ts index 5c7a513..58912e4 100644 --- a/test/fromBn.test.ts +++ b/test/fromBn.test.ts @@ -5,15 +5,14 @@ import forEach from "mocha-each"; import { fromBn } from "../src"; describe("fromBn", function () { - describe("when x is not a big number", function () { - const testSets = [undefined, null, true, 2.71, Math.PI, "3.14", { x: 100 }, function () {}]; - - forEach(testSets).it("throws an error", function (x: any) { - expect(() => fromBn(x)).toThrow("Input must be an ethers BigNumber"); + describe("when x is undefined", function () { + it("throws an error", function () { + const x: any = undefined; + expect(() => fromBn(x)).toThrow("Input must not be undefined"); }); }); - describe("when x is a big number", function () { + describe("when x is not undefined", function () { describe("when the number of decimals is out of bounds", function () { const testSets = [-1729, 0, 78, 1729];