mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Add integer check to Uint64.fromNumber
This commit is contained in:
parent
87f17685ac
commit
19882e6849
@ -11,3 +11,5 @@
|
||||
- @cosmjs/sdk38: Remove `Pen` type in favour of `OfflineSigner` and remove
|
||||
`Secp256k1Pen` class in favour of `Secp256k1Wallet` which takes an
|
||||
`OfflineSigner` instead of a `SigningCallback`.
|
||||
- @cosmjs/math: Add missing integer check to `Uint64.fromNumber`. Before
|
||||
`Uint64.fromNumber(1.1)` produced some result.
|
||||
|
@ -380,12 +380,11 @@ describe("Integers", () => {
|
||||
expect(() => Uint64.fromNumber(Number.NaN)).toThrowError(/input is not a number/i);
|
||||
|
||||
// not an integer
|
||||
expect(() => Uint64.fromNumber(Number.NEGATIVE_INFINITY)).toThrowError(
|
||||
/input is not a safe integer/i,
|
||||
);
|
||||
expect(() => Uint64.fromNumber(Number.POSITIVE_INFINITY)).toThrowError(
|
||||
/input is not a safe integer/i,
|
||||
);
|
||||
expect(() => Uint64.fromNumber(1.1)).toThrowError(/input is not an integer/i);
|
||||
expect(() => Uint64.fromNumber(Number.NEGATIVE_INFINITY)).toThrowError(/input is not an integer/i);
|
||||
expect(() => Uint64.fromNumber(Number.POSITIVE_INFINITY)).toThrowError(/input is not an integer/i);
|
||||
|
||||
// not a safe integer
|
||||
expect(() => Uint64.fromNumber(Number.MAX_SAFE_INTEGER + 1)).toThrowError(
|
||||
/input is not a safe integer/i,
|
||||
);
|
||||
|
@ -173,6 +173,10 @@ export class Uint64 implements Integer, WithByteConverters {
|
||||
throw new Error("Input is not a number");
|
||||
}
|
||||
|
||||
if (!Number.isInteger(input)) {
|
||||
throw new Error("Input is not an integer");
|
||||
}
|
||||
|
||||
let bigint: BN;
|
||||
try {
|
||||
bigint = new BN(input);
|
||||
|
Loading…
x
Reference in New Issue
Block a user