Skip to content

Commit

Permalink
fix: conversion (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi committed Apr 24, 2024
1 parent d4dc7e5 commit a681883
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/utils/convert.ts
Expand Up @@ -276,6 +276,7 @@ export class Converter {
if (ArrayBuffer.isView(number)) {
return bytesToBigInt(number)
} else {
number = number === '0x' ? '0x0' : number
return BigInt(String(number ?? '0'))
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/shared/src/lib/core/utils/tests/convert.test.ts
Expand Up @@ -2,6 +2,7 @@ import {
convertDateToUnixTimestamp,
convertUInt16NumberToLittleEndianHex,
convertUnixTimestampToDate,
Converter,
} from '../convert'

describe('File: convert.ts', () => {
Expand Down Expand Up @@ -53,4 +54,14 @@ describe('File: convert.ts', () => {
expect(convertUInt16NumberToLittleEndianHex(-32768, false)).toEqual('0080')
})
})

describe('Function: bigIntLikeToBigInt', () => {
it('should handle valid inputs', () => {
expect(Converter.bigIntLikeToBigInt('0x')).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt('0')).toEqual(BigInt(0))
expect(Converter.bigIntLikeToBigInt(100)).toEqual(BigInt(100))
expect(Converter.bigIntLikeToBigInt('123330')).toEqual(BigInt(123330))
expect(Converter.bigIntLikeToBigInt(undefined)).toEqual(BigInt(0))
})
})
})

0 comments on commit a681883

Please sign in to comment.