@@ -7,8 +7,7 @@ use tokio::sync::Mutex;
7
7
use crate :: cardano_block_scanner:: BlockStreamer ;
8
8
use crate :: cardano_block_scanner:: ChainScannedBlocks ;
9
9
use crate :: chain_reader:: { ChainBlockNextAction , ChainBlockReader } ;
10
- use crate :: entities:: BlockNumber ;
11
- use crate :: entities:: ChainPoint ;
10
+ use crate :: entities:: { BlockNumber , ChainPoint } ;
12
11
use crate :: StdResult ;
13
12
14
13
/// The action that indicates what to do next with the streamer
@@ -157,6 +156,7 @@ impl ChainReaderBlockStreamer {
157
156
mod tests {
158
157
use crate :: cardano_block_scanner:: ScannedBlock ;
159
158
use crate :: chain_reader:: FakeChainReader ;
159
+ use crate :: entities:: SlotNumber ;
160
160
use crate :: test_utils:: TestLogger ;
161
161
162
162
use super :: * ;
@@ -172,15 +172,15 @@ mod tests {
172
172
parsed_block: ScannedBlock :: new(
173
173
"hash-1" ,
174
174
until_block_number,
175
- 100 ,
175
+ SlotNumber ( 100 ) ,
176
176
Vec :: <& str >:: new( ) ,
177
177
) ,
178
178
} ,
179
179
ChainBlockNextAction :: RollForward {
180
180
parsed_block: ScannedBlock :: new(
181
181
"hash-2" ,
182
182
until_block_number,
183
- 100 ,
183
+ SlotNumber ( 100 ) ,
184
184
Vec :: <& str >:: new( ) ,
185
185
) ,
186
186
} ,
@@ -213,7 +213,7 @@ mod tests {
213
213
Some ( ChainScannedBlocks :: RollForwards ( vec![ ScannedBlock :: new(
214
214
"hash-2" ,
215
215
until_block_number,
216
- 100 ,
216
+ SlotNumber ( 100 ) ,
217
217
Vec :: <& str >:: new( ) ,
218
218
) ] ) ) ,
219
219
scanned_blocks
@@ -224,10 +224,20 @@ mod tests {
224
224
async fn test_parse_expected_multiple_rollforwards_below_block_number_threshold ( ) {
225
225
let chain_reader = Arc :: new ( Mutex :: new ( FakeChainReader :: new ( vec ! [
226
226
ChainBlockNextAction :: RollForward {
227
- parsed_block: ScannedBlock :: new( "hash-1" , BlockNumber ( 1 ) , 10 , Vec :: <& str >:: new( ) ) ,
227
+ parsed_block: ScannedBlock :: new(
228
+ "hash-1" ,
229
+ BlockNumber ( 1 ) ,
230
+ SlotNumber ( 10 ) ,
231
+ Vec :: <& str >:: new( ) ,
232
+ ) ,
228
233
} ,
229
234
ChainBlockNextAction :: RollForward {
230
- parsed_block: ScannedBlock :: new( "hash-2" , BlockNumber ( 2 ) , 20 , Vec :: <& str >:: new( ) ) ,
235
+ parsed_block: ScannedBlock :: new(
236
+ "hash-2" ,
237
+ BlockNumber ( 2 ) ,
238
+ SlotNumber ( 20 ) ,
239
+ Vec :: <& str >:: new( ) ,
240
+ ) ,
231
241
} ,
232
242
] ) ) ) ;
233
243
let mut block_streamer = ChainReaderBlockStreamer :: try_new (
@@ -244,8 +254,8 @@ mod tests {
244
254
245
255
assert_eq ! (
246
256
Some ( ChainScannedBlocks :: RollForwards ( vec![
247
- ScannedBlock :: new( "hash-1" , BlockNumber ( 1 ) , 10 , Vec :: <& str >:: new( ) ) ,
248
- ScannedBlock :: new( "hash-2" , BlockNumber ( 2 ) , 20 , Vec :: <& str >:: new( ) )
257
+ ScannedBlock :: new( "hash-1" , BlockNumber ( 1 ) , SlotNumber ( 10 ) , Vec :: <& str >:: new( ) ) ,
258
+ ScannedBlock :: new( "hash-2" , BlockNumber ( 2 ) , SlotNumber ( 20 ) , Vec :: <& str >:: new( ) )
249
259
] ) ) ,
250
260
scanned_blocks,
251
261
) ;
@@ -255,13 +265,28 @@ mod tests {
255
265
async fn test_parse_expected_maximum_rollforwards_retrieved_per_poll ( ) {
256
266
let chain_reader = Arc :: new ( Mutex :: new ( FakeChainReader :: new ( vec ! [
257
267
ChainBlockNextAction :: RollForward {
258
- parsed_block: ScannedBlock :: new( "hash-1" , BlockNumber ( 1 ) , 10 , Vec :: <& str >:: new( ) ) ,
268
+ parsed_block: ScannedBlock :: new(
269
+ "hash-1" ,
270
+ BlockNumber ( 1 ) ,
271
+ SlotNumber ( 10 ) ,
272
+ Vec :: <& str >:: new( ) ,
273
+ ) ,
259
274
} ,
260
275
ChainBlockNextAction :: RollForward {
261
- parsed_block: ScannedBlock :: new( "hash-2" , BlockNumber ( 2 ) , 20 , Vec :: <& str >:: new( ) ) ,
276
+ parsed_block: ScannedBlock :: new(
277
+ "hash-2" ,
278
+ BlockNumber ( 2 ) ,
279
+ SlotNumber ( 20 ) ,
280
+ Vec :: <& str >:: new( ) ,
281
+ ) ,
262
282
} ,
263
283
ChainBlockNextAction :: RollForward {
264
- parsed_block: ScannedBlock :: new( "hash-3" , BlockNumber ( 3 ) , 30 , Vec :: <& str >:: new( ) ) ,
284
+ parsed_block: ScannedBlock :: new(
285
+ "hash-3" ,
286
+ BlockNumber ( 3 ) ,
287
+ SlotNumber ( 30 ) ,
288
+ Vec :: <& str >:: new( ) ,
289
+ ) ,
265
290
} ,
266
291
] ) ) ) ;
267
292
let mut block_streamer = ChainReaderBlockStreamer :: try_new (
@@ -278,8 +303,8 @@ mod tests {
278
303
let scanned_blocks = block_streamer. poll_next ( ) . await . expect ( "poll_next failed" ) ;
279
304
assert_eq ! (
280
305
Some ( ChainScannedBlocks :: RollForwards ( vec![
281
- ScannedBlock :: new( "hash-1" , BlockNumber ( 1 ) , 10 , Vec :: <& str >:: new( ) ) ,
282
- ScannedBlock :: new( "hash-2" , BlockNumber ( 2 ) , 20 , Vec :: <& str >:: new( ) )
306
+ ScannedBlock :: new( "hash-1" , BlockNumber ( 1 ) , SlotNumber ( 10 ) , Vec :: <& str >:: new( ) ) ,
307
+ ScannedBlock :: new( "hash-2" , BlockNumber ( 2 ) , SlotNumber ( 20 ) , Vec :: <& str >:: new( ) )
283
308
] ) ) ,
284
309
scanned_blocks,
285
310
) ;
@@ -289,7 +314,7 @@ mod tests {
289
314
Some ( ChainScannedBlocks :: RollForwards ( vec![ ScannedBlock :: new(
290
315
"hash-3" ,
291
316
BlockNumber ( 3 ) ,
292
- 30 ,
317
+ SlotNumber ( 30 ) ,
293
318
Vec :: <& str >:: new( )
294
319
) , ] ) ) ,
295
320
scanned_blocks,
@@ -302,11 +327,17 @@ mod tests {
302
327
#[ tokio:: test]
303
328
async fn test_parse_expected_nothing_when_rollbackward_on_same_point ( ) {
304
329
let chain_reader = Arc :: new ( Mutex :: new ( FakeChainReader :: new ( vec ! [
305
- ChainBlockNextAction :: RollBackward { slot_number: 100 } ,
330
+ ChainBlockNextAction :: RollBackward {
331
+ slot_number: SlotNumber ( 100 ) ,
332
+ } ,
306
333
] ) ) ) ;
307
334
let mut block_streamer = ChainReaderBlockStreamer :: try_new (
308
335
chain_reader,
309
- Some ( ChainPoint :: new ( 100 , BlockNumber ( 10 ) , "hash-123" ) ) ,
336
+ Some ( ChainPoint :: new (
337
+ SlotNumber ( 100 ) ,
338
+ BlockNumber ( 10 ) ,
339
+ "hash-123" ,
340
+ ) ) ,
310
341
BlockNumber ( 1 ) ,
311
342
MAX_ROLL_FORWARDS_PER_POLL ,
312
343
TestLogger :: stdout ( ) ,
@@ -322,7 +353,9 @@ mod tests {
322
353
async fn test_parse_expected_rollbackward_when_on_different_point_and_no_previous_rollforward ( )
323
354
{
324
355
let chain_reader = Arc :: new ( Mutex :: new ( FakeChainReader :: new ( vec ! [
325
- ChainBlockNextAction :: RollBackward { slot_number: 100 } ,
356
+ ChainBlockNextAction :: RollBackward {
357
+ slot_number: SlotNumber ( 100 ) ,
358
+ } ,
326
359
] ) ) ) ;
327
360
let mut block_streamer = ChainReaderBlockStreamer :: try_new (
328
361
chain_reader,
@@ -336,7 +369,10 @@ mod tests {
336
369
337
370
let scanned_blocks = block_streamer. poll_next ( ) . await . expect ( "poll_next failed" ) ;
338
371
339
- assert_eq ! ( Some ( ChainScannedBlocks :: RollBackward ( 100 ) ) , scanned_blocks, ) ;
372
+ assert_eq ! (
373
+ Some ( ChainScannedBlocks :: RollBackward ( SlotNumber ( 100 ) ) ) ,
374
+ scanned_blocks,
375
+ ) ;
340
376
341
377
let scanned_blocks = block_streamer. poll_next ( ) . await . expect ( "poll_next failed" ) ;
342
378
assert_eq ! ( None , scanned_blocks) ;
@@ -347,20 +383,32 @@ mod tests {
347
383
) {
348
384
let chain_reader = Arc :: new ( Mutex :: new ( FakeChainReader :: new ( vec ! [
349
385
ChainBlockNextAction :: RollForward {
350
- parsed_block: ScannedBlock :: new( "hash-8" , BlockNumber ( 80 ) , 8 , Vec :: <& str >:: new( ) ) ,
386
+ parsed_block: ScannedBlock :: new(
387
+ "hash-8" ,
388
+ BlockNumber ( 80 ) ,
389
+ SlotNumber ( 8 ) ,
390
+ Vec :: <& str >:: new( ) ,
391
+ ) ,
351
392
} ,
352
393
ChainBlockNextAction :: RollForward {
353
- parsed_block: ScannedBlock :: new( "hash-9" , BlockNumber ( 90 ) , 9 , Vec :: <& str >:: new( ) ) ,
394
+ parsed_block: ScannedBlock :: new(
395
+ "hash-9" ,
396
+ BlockNumber ( 90 ) ,
397
+ SlotNumber ( 9 ) ,
398
+ Vec :: <& str >:: new( ) ,
399
+ ) ,
354
400
} ,
355
401
ChainBlockNextAction :: RollForward {
356
402
parsed_block: ScannedBlock :: new(
357
403
"hash-10" ,
358
404
BlockNumber ( 100 ) ,
359
- 10 ,
405
+ SlotNumber ( 10 ) ,
360
406
Vec :: <& str >:: new( ) ,
361
407
) ,
362
408
} ,
363
- ChainBlockNextAction :: RollBackward { slot_number: 9 } ,
409
+ ChainBlockNextAction :: RollBackward {
410
+ slot_number: SlotNumber ( 9 ) ,
411
+ } ,
364
412
] ) ) ) ;
365
413
let mut block_streamer = ChainReaderBlockStreamer :: try_new (
366
414
chain_reader,
@@ -376,8 +424,8 @@ mod tests {
376
424
377
425
assert_eq ! (
378
426
Some ( ChainScannedBlocks :: RollForwards ( vec![
379
- ScannedBlock :: new( "hash-8" , BlockNumber ( 80 ) , 8 , Vec :: <& str >:: new( ) ) ,
380
- ScannedBlock :: new( "hash-9" , BlockNumber ( 90 ) , 9 , Vec :: <& str >:: new( ) )
427
+ ScannedBlock :: new( "hash-8" , BlockNumber ( 80 ) , SlotNumber ( 8 ) , Vec :: <& str >:: new( ) ) ,
428
+ ScannedBlock :: new( "hash-9" , BlockNumber ( 90 ) , SlotNumber ( 9 ) , Vec :: <& str >:: new( ) )
381
429
] ) ) ,
382
430
scanned_blocks,
383
431
) ;
@@ -388,12 +436,24 @@ mod tests {
388
436
) {
389
437
let chain_reader = Arc :: new ( Mutex :: new ( FakeChainReader :: new ( vec ! [
390
438
ChainBlockNextAction :: RollForward {
391
- parsed_block: ScannedBlock :: new( "hash-8" , BlockNumber ( 80 ) , 8 , Vec :: <& str >:: new( ) ) ,
439
+ parsed_block: ScannedBlock :: new(
440
+ "hash-8" ,
441
+ BlockNumber ( 80 ) ,
442
+ SlotNumber ( 8 ) ,
443
+ Vec :: <& str >:: new( ) ,
444
+ ) ,
392
445
} ,
393
446
ChainBlockNextAction :: RollForward {
394
- parsed_block: ScannedBlock :: new( "hash-9" , BlockNumber ( 90 ) , 9 , Vec :: <& str >:: new( ) ) ,
447
+ parsed_block: ScannedBlock :: new(
448
+ "hash-9" ,
449
+ BlockNumber ( 90 ) ,
450
+ SlotNumber ( 9 ) ,
451
+ Vec :: <& str >:: new( ) ,
452
+ ) ,
453
+ } ,
454
+ ChainBlockNextAction :: RollBackward {
455
+ slot_number: SlotNumber ( 3 ) ,
395
456
} ,
396
- ChainBlockNextAction :: RollBackward { slot_number: 3 } ,
397
457
] ) ) ) ;
398
458
let mut block_streamer = ChainReaderBlockStreamer :: try_new (
399
459
chain_reader,
@@ -407,7 +467,10 @@ mod tests {
407
467
408
468
let scanned_blocks = block_streamer. poll_next ( ) . await . expect ( "poll_next failed" ) ;
409
469
410
- assert_eq ! ( Some ( ChainScannedBlocks :: RollBackward ( 3 ) ) , scanned_blocks, ) ;
470
+ assert_eq ! (
471
+ Some ( ChainScannedBlocks :: RollBackward ( SlotNumber ( 3 ) ) ) ,
472
+ scanned_blocks,
473
+ ) ;
411
474
}
412
475
413
476
#[ tokio:: test]
0 commit comments