Skip to content

Commit

Permalink
feat: add BigInt support within BigNumberish
Browse files Browse the repository at this point in the history
  • Loading branch information
naps62 committed Mar 11, 2022
1 parent c61232d commit e42427a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/utils/uint256.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit e42427a

Please sign in to comment.