@@ -318,128 +318,6 @@ func TestCheckpointManager_IsCheckpointBlock(t *testing.T) {
318
318
}
319
319
}
320
320
321
- func TestCheckpointManager_PostBlock (t * testing.T ) {
322
- const (
323
- numOfReceipts = 5
324
- block = 5
325
- epoch = 1
326
- )
327
-
328
- state := newTestState (t )
329
-
330
- createReceipts := func (startID , endID uint64 ) []* types.Receipt {
331
- receipts := make ([]* types.Receipt , endID - startID )
332
- for i := startID ; i < endID ; i ++ {
333
- receipts [i - startID ] = & types.Receipt {Logs : []* types.Log {
334
- createTestLogForExitEvent (t , i ),
335
- }}
336
- receipts [i - startID ].SetStatus (types .ReceiptSuccess )
337
- }
338
-
339
- return receipts
340
- }
341
-
342
- extra := & Extra {
343
- Checkpoint : & CheckpointData {
344
- EpochNumber : epoch ,
345
- },
346
- }
347
-
348
- req := & PostBlockRequest {FullBlock : & types.FullBlock {Block : & types.Block {Header : & types.Header {Number : block }}},
349
- Epoch : epoch }
350
-
351
- req .FullBlock .Block .Header .ExtraData = extra .MarshalRLPTo (nil )
352
-
353
- blockchain := new (blockchainMock )
354
- checkpointManager := newCheckpointManager (wallet .NewEcdsaSigner (createTestKey (t )), 5 , types .ZeroAddress ,
355
- nil , blockchain , nil , hclog .NewNullLogger (), state )
356
-
357
- t .Run ("PostBlock - not epoch ending block" , func (t * testing.T ) {
358
- require .NoError (t , state .CheckpointStore .updateLastSaved (block - 1 )) // we got everything till the current block
359
- req .IsEpochEndingBlock = false
360
- req .FullBlock .Receipts = createReceipts (0 , 5 )
361
- require .NoError (t , checkpointManager .PostBlock (req ))
362
-
363
- exitEvents , err := state .CheckpointStore .getExitEvents (epoch , func (exitEvent * ExitEvent ) bool {
364
- return exitEvent .BlockNumber == block
365
- })
366
-
367
- require .NoError (t , err )
368
- require .Len (t , exitEvents , 5 )
369
- require .Equal (t , uint64 (epoch ), exitEvents [0 ].EpochNumber )
370
- })
371
-
372
- t .Run ("PostBlock - epoch ending block (exit events are saved to the next epoch)" , func (t * testing.T ) {
373
- require .NoError (t , state .CheckpointStore .updateLastSaved (block )) // we got everything till the current block
374
- req .IsEpochEndingBlock = true
375
- req .FullBlock .Receipts = createReceipts (5 , 10 )
376
- extra .Validators = & validator.ValidatorSetDelta {}
377
- req .FullBlock .Block .Header .ExtraData = extra .MarshalRLPTo (nil )
378
- req .FullBlock .Block .Header .Number = block + 1
379
-
380
- require .NoError (t , checkpointManager .PostBlock (req ))
381
-
382
- exitEvents , err := state .CheckpointStore .getExitEvents (epoch + 1 , func (exitEvent * ExitEvent ) bool {
383
- return exitEvent .BlockNumber == block + 2 // they should be saved in the next epoch and its first block
384
- })
385
-
386
- require .NoError (t , err )
387
- require .Len (t , exitEvents , 5 )
388
- require .Equal (t , uint64 (block + 2 ), exitEvents [0 ].BlockNumber )
389
- require .Equal (t , uint64 (epoch + 1 ), exitEvents [0 ].EpochNumber )
390
- })
391
-
392
- t .Run ("PostBlock - there are missing events" , func (t * testing.T ) {
393
- require .NoError (t , state .CheckpointStore .updateLastSaved (block )) // we are missing one block
394
-
395
- missedReceipts := createReceipts (10 , 13 )
396
- newReceipts := createReceipts (13 , 15 )
397
-
398
- extra := & Extra {
399
- Checkpoint : & CheckpointData {
400
- EpochNumber : epoch + 1 ,
401
- },
402
- }
403
-
404
- blockchain .On ("GetHeaderByNumber" , uint64 (block + 1 )).Return (& types.Header {
405
- Number : block + 1 ,
406
- ExtraData : extra .MarshalRLPTo (nil ),
407
- Hash : types .BytesToHash ([]byte {0 , 1 , 2 , 3 }),
408
- }, true )
409
- blockchain .On ("GetReceiptsByHash" , types .BytesToHash ([]byte {0 , 1 , 2 , 3 })).Return ([]* types.Receipt {}, nil )
410
- blockchain .On ("GetHeaderByNumber" , uint64 (block + 2 )).Return (& types.Header {
411
- Number : block + 2 ,
412
- ExtraData : extra .MarshalRLPTo (nil ),
413
- Hash : types .BytesToHash ([]byte {4 , 5 , 6 , 7 }),
414
- }, true )
415
- blockchain .On ("GetReceiptsByHash" , types .BytesToHash ([]byte {4 , 5 , 6 , 7 })).Return (missedReceipts , nil )
416
-
417
- req .IsEpochEndingBlock = false
418
- req .FullBlock .Block .Header .Number = block + 3 // new block
419
- req .FullBlock .Block .Header .ExtraData = extra .MarshalRLPTo (nil ) // same epoch
420
- req .FullBlock .Receipts = newReceipts
421
- require .NoError (t , checkpointManager .PostBlock (req ))
422
-
423
- exitEvents , err := state .CheckpointStore .getExitEvents (epoch + 1 , func (exitEvent * ExitEvent ) bool {
424
- return exitEvent .BlockNumber == block + 2
425
- })
426
-
427
- require .NoError (t , err )
428
- // receipts from missed block + events from previous test case that were saved in the next epoch
429
- // since they were in epoch ending block
430
- require .Len (t , exitEvents , len (missedReceipts )+ 5 )
431
- require .Equal (t , extra .Checkpoint .EpochNumber , exitEvents [0 ].EpochNumber )
432
-
433
- exitEvents , err = state .CheckpointStore .getExitEvents (epoch + 1 , func (exitEvent * ExitEvent ) bool {
434
- return exitEvent .BlockNumber == block + 3
435
- })
436
-
437
- require .NoError (t , err )
438
- require .Len (t , exitEvents , len (newReceipts ))
439
- require .Equal (t , extra .Checkpoint .EpochNumber , exitEvents [0 ].EpochNumber )
440
- })
441
- }
442
-
443
321
func TestCheckpointManager_BuildEventRoot (t * testing.T ) {
444
322
t .Parallel ()
445
323
0 commit comments