Fix BigNumber when passed something with a length property (#1172).
This commit is contained in:
parent
211defa27f
commit
45a2902874
@ -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
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user