From e42427afa9a57673576da68cfbbee1356ffb5c0d Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Fri, 11 Mar 2022 19:21:58 +0000 Subject: [PATCH] feat: add BigInt support within BigNumberish --- __tests__/utils/uint256.test.ts | 9 +++++++++ src/utils/number.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/__tests__/utils/uint256.test.ts b/__tests__/utils/uint256.test.ts index eef19f41d..944ccaa13 100644 --- a/__tests__/utils/uint256.test.ts +++ b/__tests__/utils/uint256.test.ts @@ -24,6 +24,15 @@ describe('cairo uint256', () => { } `); }); + test('should convert BigInt to uint256 struct', () => { + const uint256 = bnToUint256(BigInt(UINT_128_MAX.add(ONE).toString())); + expect(uint256).toMatchInlineSnapshot(` + Object { + "high": "0x1", + "low": "0x0", + } + `); + }); test('should throw if BN over uint256 range', () => { expect(() => bnToUint256(UINT_256_MAX.add(toBN(1)))).toThrowErrorMatchingInlineSnapshot( `"Number is too large"` diff --git a/src/utils/number.ts b/src/utils/number.ts index 4cb448902..0ddef2c5d 100644 --- a/src/utils/number.ts +++ b/src/utils/number.ts @@ -3,7 +3,7 @@ import assert from 'minimalistic-assert'; import { addHexPrefix, removeHexPrefix } from './encode'; -export type BigNumberish = string | number | BN; +export type BigNumberish = string | number | BN | BigInt; export function isHex(hex: string): boolean { return hex.startsWith('0x');