Skip to content

Commit

Permalink
fix: relax type checking in "fromFp" function
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRBerg committed Sep 29, 2021
1 parent 81ca57e commit 48f6a31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/fromBn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 5 additions & 6 deletions test/fromBn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 48f6a31

Please sign in to comment.