Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/format/RawUInt64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class RawUInt64 {
* @returns {number|module:coders/uint64~uint64}
* A numeric if the uint64 is no greater than Number.MAX_SAFE_INTEGER or the original uint64 value otherwise.
*/
public static compact = (uint64): any => {
public static compact = (uint64: number[]): number | number[] => {
const low = uint64[0];
const high = uint64[1];

Expand Down
6 changes: 5 additions & 1 deletion src/model/UInt64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ export class UInt64 {
* @returns {number}
*/
public compact(): number {
return uint64.compact(this.toDTO());
const result = uint64.compact(this.toDTO());
if (Array.isArray(result)) {
throw new Error('Compacted value is greater than Number.Max_Value.');
}
return result;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions test/model/UInt64.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('Uint64', () => {
expect(uint64Compact).to.be.equal(51110867862);
});

it('should compact UInt64 number', () => {
expect(() => {
new UInt64([3866227606, 0x00200000 + 1]).compact();
}).to.throw(Error, 'Compacted value is greater than Number.Max_Value.');
});

it('should fromUint throw exception with negative uint value', () => {
expect(() => {
UInt64.fromUint(-1);
Expand Down