@@ -382,6 +382,10 @@ func (suite *KeeperTestSuite) TestValidatorDowntime() {
382
382
// add the validator pubkey and signing info to the store
383
383
app .SlashingKeeper .AddPubkey (ctx , pubkey )
384
384
385
+ // set unbounding packet with valset update id
386
+ vscPacket := ccv.ValidatorSetChangePacketData {ValsetUpdateId : uint64 (3 )}
387
+ app .ChildKeeper .SetUnbondingPacket (ctx , uint64 (0 ), channeltypes.Packet {Data : vscPacket .GetBytes ()})
388
+
385
389
valInfo := slashingtypes .NewValidatorSigningInfo (consAddr , ctx .BlockHeight (), ctx .BlockHeight ()- 1 ,
386
390
time.Time {}.UTC (), false , int64 (0 ))
387
391
app .SlashingKeeper .SetValidatorSigningInfo (ctx , consAddr , valInfo )
@@ -419,8 +423,7 @@ func (suite *KeeperTestSuite) TestAfterValidatorDowntimeHook() {
419
423
420
424
now := time .Now ()
421
425
422
- // Cover the cases when the validatir jailing duration
423
- // is either elapsed, null or still going
426
+ // test cases with different jail durations
424
427
testcases := []struct {
425
428
jailedUntil time.Time
426
429
expUpdate bool
@@ -436,11 +439,23 @@ func (suite *KeeperTestSuite) TestAfterValidatorDowntimeHook() {
436
439
},
437
440
}
438
441
439
- // synchronize the block time with the test cases
442
+ // set validator signing info to not panic
440
443
ctx = ctx .WithBlockTime (now )
441
444
valInfo := slashingtypes .NewValidatorSigningInfo (consAddr , int64 (1 ), int64 (1 ),
442
445
time.Time {}.UTC (), false , int64 (0 ))
446
+ app .SlashingKeeper .SetValidatorSigningInfo (ctx , consAddr , valInfo )
447
+
448
+ // expect no updates when there is no unbonding packets
449
+ app .ChildKeeper .AfterValidatorDowntime (ctx , consAddr , int64 (1 ))
450
+ signInfo , _ := app .SlashingKeeper .GetValidatorSigningInfo (ctx , consAddr )
451
+
452
+ suite .Require ().True (false == ! (signInfo .JailedUntil .Equal (signInfo .JailedUntil )))
443
453
454
+ // set unbounding packet with valset update id
455
+ vscPacket := ccv.ValidatorSetChangePacketData {ValsetUpdateId : uint64 (3 )}
456
+ app .ChildKeeper .SetUnbondingPacket (ctx , uint64 (0 ), channeltypes.Packet {Data : vscPacket .GetBytes ()})
457
+
458
+ // test cases
444
459
for _ , tc := range testcases {
445
460
// set the current unjailing time
446
461
valInfo .JailedUntil = tc .jailedUntil
@@ -461,8 +476,17 @@ func (suite *KeeperTestSuite) TestGetLastUnboundingPacket() {
461
476
app := suite .childChain .App .(* app.App )
462
477
ctx := suite .childChain .GetContext ()
463
478
464
- ubdPacket := app .ChildKeeper .GetLastUnbondingPacket (ctx )
465
- suite .Require ().Zero (ubdPacket .ValsetUpdateId )
479
+ // check if IBC packet is valid
480
+ _ , err := app .ChildKeeper .GetLastUnbondingPacketData (ctx )
481
+ suite .NotNil (err )
482
+
483
+ app .ChildKeeper .SetUnbondingPacket (ctx , uint64 (0 ), channeltypes.Packet {Sequence : 1 })
484
+
485
+ // check if unbouding packet data is valid
486
+ _ , err = app .ChildKeeper .GetLastUnbondingPacketData (ctx )
487
+ suite .NotNil (err )
488
+
489
+ // check if the last packet stored is returned
466
490
for i := 0 ; i < 5 ; i ++ {
467
491
pd := ccv .NewValidatorSetChangePacketData (
468
492
[]abci.ValidatorUpdate {},
@@ -473,6 +497,7 @@ func (suite *KeeperTestSuite) TestGetLastUnboundingPacket() {
473
497
app .ChildKeeper .SetUnbondingPacket (ctx , uint64 (i ), packet )
474
498
}
475
499
476
- ubdPacket = app .ChildKeeper .GetLastUnbondingPacket (ctx )
500
+ ubdPacket , err := app .ChildKeeper .GetLastUnbondingPacketData (ctx )
501
+ suite .Nil (err )
477
502
suite .Require ().Equal (uint64 (4 ), ubdPacket .ValsetUpdateId )
478
503
}
0 commit comments