@@ -455,59 +455,130 @@ func (suite *KeeperTestSuite) TestIterateClientStates() {
455
455
}
456
456
}
457
457
458
+ func (suite * KeeperTestSuite ) TestGetLatestHeight () {
459
+ var path * ibctesting.Path
460
+
461
+ cases := []struct {
462
+ name string
463
+ malleate func ()
464
+ expPass bool
465
+ }{
466
+ {
467
+ "success" ,
468
+ func () {},
469
+ true ,
470
+ },
471
+ {
472
+ "invalid client type" ,
473
+ func () {
474
+ path .EndpointA .ClientID = ibctesting .InvalidID
475
+ },
476
+ false ,
477
+ },
478
+ {
479
+ "client type is not allowed" , func () {
480
+ params := types .NewParams (exported .Localhost )
481
+ suite .chainA .GetSimApp ().GetIBCKeeper ().ClientKeeper .SetParams (suite .chainA .GetContext (), params )
482
+ },
483
+ false ,
484
+ },
485
+ {
486
+ "client type is not registered on router" , func () {
487
+ path .EndpointA .ClientID = types .FormatClientIdentifier ("08-wasm" , 0 )
488
+ },
489
+ false ,
490
+ },
491
+ }
492
+
493
+ for _ , tc := range cases {
494
+ suite .Run (tc .name , func () {
495
+ suite .SetupTest () // reset
496
+
497
+ path = ibctesting .NewPath (suite .chainA , suite .chainB )
498
+ path .SetupConnections ()
499
+
500
+ tc .malleate ()
501
+
502
+ height := suite .chainA .App .GetIBCKeeper ().ClientKeeper .GetLatestHeight (suite .chainA .GetContext (), path .EndpointA .ClientID )
503
+
504
+ if tc .expPass {
505
+ suite .Require ().Equal (suite .chainB .LatestCommittedHeader .GetHeight ().(types.Height ), height )
506
+ } else {
507
+ suite .Require ().Equal (types .ZeroHeight (), height )
508
+ }
509
+ })
510
+ }
511
+ }
512
+
458
513
func (suite * KeeperTestSuite ) TestGetTimestampAtHeight () {
459
514
var (
460
- clientID string
461
- height exported. Height
515
+ height exported. Height
516
+ path * ibctesting. Path
462
517
)
463
518
464
519
cases := []struct {
465
- msg string
520
+ name string
466
521
malleate func ()
467
- expPass bool
522
+ expError error
468
523
}{
469
524
{
470
- "verification success" ,
525
+ "success" ,
526
+ func () {},
527
+ nil ,
528
+ },
529
+ {
530
+ "invalid client type" ,
471
531
func () {
472
- path := ibctesting .NewPath (suite .chainA , suite .chainB )
473
- path .SetupConnections ()
474
-
475
- clientID = path .EndpointA .ClientID
476
- height = suite .chainB .LatestCommittedHeader .GetHeight ()
532
+ path .EndpointA .ClientID = ibctesting .InvalidID
477
533
},
478
- true ,
534
+ host . ErrInvalidID ,
479
535
},
480
536
{
481
- "client state not found" ,
482
- func () {},
483
- false ,
537
+ "client type is not allowed" , func () {
538
+ params := types .NewParams (exported .Localhost )
539
+ suite .chainA .GetSimApp ().GetIBCKeeper ().ClientKeeper .SetParams (suite .chainA .GetContext (), params )
540
+ },
541
+ types .ErrInvalidClientType ,
542
+ },
543
+ {
544
+ "client type is not registered on router" , func () {
545
+ path .EndpointA .ClientID = types .FormatClientIdentifier ("08-wasm" , 0 )
546
+ },
547
+ types .ErrRouteNotFound ,
548
+ },
549
+ {
550
+ "client state not found" , func () {
551
+ path .EndpointA .ClientID = types .FormatClientIdentifier (exported .Tendermint , 100 )
552
+ },
553
+ types .ErrClientNotFound ,
484
554
},
485
555
{
486
556
"consensus state not found" , func () {
487
- path := ibctesting .NewPath (suite .chainA , suite .chainB )
488
- path .SetupConnections ()
489
- clientID = path .EndpointA .ClientID
490
557
height = suite .chainB .LatestCommittedHeader .GetHeight ().Increment ()
491
558
},
492
- false ,
559
+ types . ErrConsensusStateNotFound ,
493
560
},
494
561
}
495
562
496
563
for _ , tc := range cases {
497
- suite .Run (fmt . Sprintf ( "Case %s" , tc .msg ) , func () {
564
+ suite .Run (tc .name , func () {
498
565
suite .SetupTest () // reset
499
566
567
+ path = ibctesting .NewPath (suite .chainA , suite .chainB )
568
+ path .SetupConnections ()
569
+
570
+ height = suite .chainB .LatestCommittedHeader .GetHeight ()
571
+
500
572
tc .malleate ()
501
573
502
- actualTimestamp , err := suite .chainA .App .GetIBCKeeper ().ClientKeeper .GetTimestampAtHeight (
503
- suite .chainA .GetContext (), clientID , height ,
504
- )
574
+ actualTimestamp , err := suite .chainA .App .GetIBCKeeper ().ClientKeeper .GetTimestampAtHeight (suite .chainA .GetContext (), path .EndpointA .ClientID , height )
505
575
506
- if tc .expPass {
576
+ expPass := tc .expError == nil
577
+ if expPass {
507
578
suite .Require ().NoError (err )
508
- suite .Require ().EqualValues (uint64 (suite .chainB .LatestCommittedHeader .GetTime ().UnixNano ()), actualTimestamp )
579
+ suite .Require ().Equal (uint64 (suite .chainB .LatestCommittedHeader .GetTime ().UnixNano ()), actualTimestamp )
509
580
} else {
510
- suite .Require ().Error (err )
581
+ suite .Require ().ErrorIs (err , tc . expError )
511
582
}
512
583
})
513
584
}
0 commit comments