Skip to content

Commit

Permalink
Fix BigNumber when passed something with a length property (#1172).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Nov 25, 2020
1 parent 211defa commit 45a2902
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/bytes/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ export function isBytes(value: any): value is Bytes {

for (let i = 0; i < value.length; i++) {
const v = value[i];
if (v < 0 || v >= 256 || (v % 1)) {
if (typeof(v) !== "number" || v < 0 || v >= 256 || (v % 1)) {
return false;
}
}

return true;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/tests/src.ts/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ describe("BigNumber", function() {
});
});

// Fails to create from BN (or any junk with a length) (See: #1172)
it("Fails on junk with a length property", function() {
const junk: any = { negative: 0, words: [ 1000 ], length: 1, red: null };
assert.throws(() => {
const value = ethers.BigNumber.from("100").add(junk);
console.log("ERROR", value);
}, (error: Error) => {
return true;
});
});

// @TODO: Add more tests here

});
Expand Down

0 comments on commit 45a2902

Please sign in to comment.