@@ -214,14 +214,11 @@ test_matches_solana( void ) {
214214 ulong weights2 [18 ] = { 78 , 70 , 38 , 27 , 21 , 82 , 42 , 21 , 77 , 77 , 17 , 4 , 50 , 96 , 83 , 33 , 16 , 72 };
215215
216216 memset ( zero_seed , 48 , 32UL );
217- fd_chacha20_rng_init ( rng , zero_seed );
218-
219217 partial = fd_wsample_new_init ( _shmem , rng , 18UL , 0 , FD_WSAMPLE_HINT_FLAT );
220218 for ( ulong i = 0UL ; i < 18UL ; i ++ ) partial = fd_wsample_new_add ( partial , weights2 [i ] );
221219 tree = fd_wsample_join ( fd_wsample_new_fini ( partial , 0UL ) );
222220 fd_wsample_seed_rng ( tree , zero_seed , 0 /* use_chacha8 */ );
223221
224-
225222 FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 9UL );
226223 FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 3UL );
227224 FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 12UL );
@@ -245,6 +242,66 @@ test_matches_solana( void ) {
245242 fd_chacha_rng_delete ( fd_chacha_rng_leave ( rng ) );
246243}
247244
245+ static void
246+ test_matches_solana_chacha8 ( void ) {
247+ /* Adopted from test_repeated_leader_schedule_specific: */
248+ fd_chacha_rng_t _rng [1 ];
249+ fd_chacha_rng_t * rng = fd_chacha_rng_join ( fd_chacha_rng_new ( _rng , FD_CHACHA_RNG_MODE_MOD ) );
250+ uchar zero_seed [32 ] = {0 };
251+
252+ void * partial = fd_wsample_new_init ( _shmem , rng , 2UL , 0 , FD_WSAMPLE_HINT_FLAT );
253+ fd_wsample_t * tree = fd_wsample_join ( fd_wsample_new_fini ( fd_wsample_new_add ( fd_wsample_new_add ( partial , 2UL ), 1UL ), 0UL ) );
254+ fd_wsample_seed_rng ( tree , zero_seed , 1 /* use_chacha8 */ );
255+
256+ FD_TEST ( fd_wsample_sample ( tree ) == 1UL );
257+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
258+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
259+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
260+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
261+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
262+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
263+ FD_TEST ( fd_wsample_sample ( tree ) == 0UL );
264+
265+ fd_wsample_delete ( fd_wsample_leave ( tree ) );
266+ fd_chacha_rng_delete ( fd_chacha_rng_leave ( rng ) );
267+
268+ rng = fd_chacha_rng_join ( fd_chacha_rng_new ( _rng , FD_CHACHA_RNG_MODE_SHIFT ) );
269+
270+ /* Adopted from test_weighted_shuffle_hard_coded, except they handle
271+ the special case for 0 weights inside their WeightedShuffle object,
272+ and the test case initially used i32 as weights, which made their
273+ Chacha20 object generate i32s instead of u64s. */
274+ ulong weights2 [18 ] = { 78 , 70 , 38 , 27 , 21 , 82 , 42 , 21 , 77 , 77 , 17 , 4 , 50 , 96 , 83 , 33 , 16 , 72 };
275+
276+ memset ( zero_seed , 48 , 32UL );
277+ partial = fd_wsample_new_init ( _shmem , rng , 18UL , 0 , FD_WSAMPLE_HINT_FLAT );
278+ for ( ulong i = 0UL ; i < 18UL ; i ++ ) partial = fd_wsample_new_add ( partial , weights2 [i ] );
279+ tree = fd_wsample_join ( fd_wsample_new_fini ( partial , 0UL ) );
280+ fd_wsample_seed_rng ( tree , zero_seed , 1 /* use_chacha8 */ );
281+
282+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 13UL );
283+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 8UL );
284+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 6UL );
285+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 14UL );
286+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 0UL );
287+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 17UL );
288+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 1UL );
289+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 12UL );
290+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 3UL );
291+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 16UL );
292+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 5UL );
293+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 15UL );
294+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 9UL );
295+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 2UL );
296+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 4UL );
297+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 7UL );
298+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 10UL );
299+ FD_TEST ( fd_wsample_sample_and_remove ( tree ) == 11UL );
300+
301+ fd_wsample_delete ( fd_wsample_leave ( tree ) );
302+ fd_chacha_rng_delete ( fd_chacha_rng_leave ( rng ) );
303+ }
304+
248305static void
249306test_sharing ( void ) {
250307 fd_chacha_rng_t _rng [1 ];
@@ -472,6 +529,7 @@ main( int argc,
472529 FD_TEST ( fd_wsample_footprint ( MAX , 1 )< MAX_FOOTPRINT );
473530
474531 test_matches_solana ();
532+ test_matches_solana_chacha8 ();
475533 test_map ();
476534 test_sharing ();
477535 test_restore_disabled ();
0 commit comments