File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export class RawUInt64 {
3131 * @returns {number|module:coders/uint64~uint64 }
3232 * A numeric if the uint64 is no greater than Number.MAX_SAFE_INTEGER or the original uint64 value otherwise.
3333 */
34- public static compact = ( uint64 ) : any => {
34+ public static compact = ( uint64 : number [ ] ) : number | number [ ] => {
3535 const low = uint64 [ 0 ] ;
3636 const high = uint64 [ 1 ] ;
3737
Original file line number Diff line number Diff line change @@ -124,7 +124,11 @@ export class UInt64 {
124124 * @returns {number }
125125 */
126126 public compact ( ) : number {
127- return uint64 . compact ( this . toDTO ( ) ) ;
127+ const result = uint64 . compact ( this . toDTO ( ) ) ;
128+ if ( Array . isArray ( result ) ) {
129+ throw new Error ( 'Compacted value is greater than Number.Max_Value.' ) ;
130+ }
131+ return result ;
128132 }
129133
130134 /**
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ describe('Uint64', () => {
6666 expect ( uint64Compact ) . to . be . equal ( 51110867862 ) ;
6767 } ) ;
6868
69+ it ( 'should compact UInt64 number' , ( ) => {
70+ expect ( ( ) => {
71+ new UInt64 ( [ 3866227606 , 0x00200000 + 1 ] ) . compact ( ) ;
72+ } ) . to . throw ( Error , 'Compacted value is greater than Number.Max_Value.' ) ;
73+ } ) ;
74+
6975 it ( 'should fromUint throw exception with negative uint value' , ( ) => {
7076 expect ( ( ) => {
7177 UInt64 . fromUint ( - 1 ) ;
You can’t perform that action at this time.
0 commit comments