File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ export default class Queue {
126126 . map ( state => state . blockNumber )
127127 const uniqueBlockNumbers = [ ...new Set ( blockNumbers ) ]
128128 const blockNumbersBigInt = uniqueBlockNumbers . map ( num => BigInt ( num ) )
129- const minBlockNumber = blockNumbersBigInt . sort ( ) [ 0 ]
129+ const minBlockNumber = Utils . min ( blockNumbersBigInt )
130130 return minBlockNumber
131131 }
132132
Original file line number Diff line number Diff line change @@ -48,4 +48,20 @@ export default class Utils {
4848 }
4949 return result
5050 }
51+
52+ public static min = ( array : bigint [ ] ) : bigint | undefined => {
53+ let minValue = array [ 0 ]
54+ if ( ! minValue ) {
55+ return undefined
56+ }
57+
58+ for ( let i = 1 ; i < array . length ; ++ i ) {
59+ const value = array [ i ]
60+ if ( value < minValue ) {
61+ minValue = value
62+ }
63+ }
64+
65+ return minValue
66+ }
5167}
Original file line number Diff line number Diff line change 1+ import Utils from '../../../src/services/sync/utils'
2+
3+ describe ( 'Key tests' , ( ) => {
4+ describe ( 'min' , ( ) => {
5+ it ( 'with empty array' , ( ) => {
6+ const arr : bigint [ ] = [ ]
7+ const minValue = Utils . min ( arr )
8+ expect ( minValue ) . toBe ( undefined )
9+ } )
10+
11+ it ( 'only one value' , ( ) => {
12+ const value = BigInt ( 1 )
13+ const arr = [ value ]
14+ const minValue = Utils . min ( arr )
15+ expect ( minValue ) . toEqual ( value )
16+ } )
17+
18+ it ( 'two value' , ( ) => {
19+ const arr = [ BigInt ( 38050 ) , BigInt ( 4058 ) ]
20+ const minValue = Utils . min ( arr )
21+ expect ( minValue ) . toEqual ( BigInt ( 4058 ) )
22+ } )
23+ } )
24+ } )
You can’t perform that action at this time.
0 commit comments