@@ -347,17 +347,16 @@ private int[] getBloomIndex(String s) {
347347 Bloom bloom = Bloom .create (Hash .sha3 (ByteArray .fromHexString (s )));
348348 BitSet bs = BitSet .valueOf (bloom .getData ());
349349
350- int [] bitIndex = new int [3 ]; //must same as the number of hash function in Bloom
351- int nonZeroCount = 0 ;
350+ List <Integer > bitIndexList = new ArrayList <>();
352351 for (int i = bs .nextSetBit (0 ); i >= 0 ; i = bs .nextSetBit (i + 1 )) {
353352 // operate on index i here
354353 if (i == Integer .MAX_VALUE ) {
355354 break ; // or (i+1) would overflow
356355 }
357- bitIndex [ nonZeroCount ++] = i ;
356+ bitIndexList . add ( i ) ;
358357 }
359358
360- return bitIndex ;
359+ return bitIndexList . stream (). mapToInt ( Integer :: intValue ). toArray () ;
361360 }
362361
363362 @ Test
@@ -416,4 +415,43 @@ public void testGetConditions() {
416415 Assert .fail ();
417416 }
418417 }
418+
419+ @ Test
420+ public void testGetConditionWithHashCollision () {
421+ try {
422+ List <String > addressList = new ArrayList <>();
423+ addressList .add ("0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85" );
424+ addressList .add ("0x3038114c1a1e72c5bfa8b003bc3650ad2ba254a0" );
425+
426+ Object [] topics = new Object [0 ];
427+
428+ LogFilterWrapper logFilterWrapper =
429+ new LogFilterWrapper (new FilterRequest (null ,
430+ null ,
431+ addressList ,
432+ topics ,
433+ null ),
434+ 100 ,
435+ null );
436+
437+ LogBlockQuery logBlockQuery = new LogBlockQuery (logFilterWrapper , null , 100 , null );
438+ int [][][] conditions = logBlockQuery .getConditions ();
439+ //level = depth(address) + depth(topics), skip null
440+ Assert .assertEquals (1 , conditions .length );
441+ //elements number
442+ Assert .assertEquals (2 , conditions [0 ].length );
443+
444+ Assert .assertEquals (3 , conditions [0 ][0 ].length );
445+ //Hash collision, only two nonZero position
446+ Assert .assertEquals (2 , conditions [0 ][1 ].length );
447+
448+ Assert .assertArrayEquals (conditions [0 ][0 ],
449+ getBloomIndex ("0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85" ));
450+ Assert .assertArrayEquals (conditions [0 ][1 ],
451+ getBloomIndex ("0x3038114c1a1e72c5bfa8b003bc3650ad2ba254a0" ));
452+
453+ } catch (JsonRpcInvalidParamsException e ) {
454+ Assert .fail ();
455+ }
456+ }
419457}
0 commit comments