Fix BigNumber when passed something with a length property (#1172).

This commit is contained in:
Richard Moore 2020-11-25 15:07:34 -05:00
parent 211defa27f
commit 45a2902874
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 12 additions and 2 deletions

@ -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;
}

@ -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
});