github.com/okex/exchain@v1.8.0/libs/ibc-go/modules/core/02-client/abci_test.go (about) 1 package client_test 2 3 import ( 4 client "github.com/okex/exchain/libs/ibc-go/modules/core/02-client" 5 types2 "github.com/okex/exchain/libs/tendermint/types" 6 "testing" 7 8 "github.com/stretchr/testify/suite" 9 // abci "github.com/tendermint/tendermint/abci/types" 10 // tmproto "github.com/tendermint/tendermint/proto/tendermint/types" 11 12 "github.com/okex/exchain/libs/ibc-go/modules/core/02-client/types" 13 "github.com/okex/exchain/libs/ibc-go/modules/core/exported" 14 localhosttypes "github.com/okex/exchain/libs/ibc-go/modules/light-clients/09-localhost/types" 15 ibctesting "github.com/okex/exchain/libs/ibc-go/testing" 16 ) 17 18 type ClientTestSuite struct { 19 suite.Suite 20 21 coordinator *ibctesting.Coordinator 22 23 chainA ibctesting.TestChainI 24 chainB ibctesting.TestChainI 25 } 26 27 func (suite *ClientTestSuite) SetupTest() { 28 types2.UnittestOnlySetMilestoneVenus1Height(-1) 29 suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) 30 31 suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(0)) 32 suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(1)) 33 34 // set localhost client 35 tmpCtx := suite.chainA.GetContext() 36 revision := types.ParseChainID(tmpCtx.ChainID()) 37 localHostClient := localhosttypes.NewClientState( 38 tmpCtx.ChainID(), types.NewHeight(revision, uint64(tmpCtx.BlockHeight())), 39 ) 40 suite.chainA.App().GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), exported.Localhost, localHostClient) 41 } 42 43 func TestClientTestSuite(t *testing.T) { 44 suite.Run(t, new(ClientTestSuite)) 45 } 46 47 func (suite *ClientTestSuite) TestBeginBlocker() { 48 prevHeight := types.GetSelfHeight(suite.chainA.GetContext()) 49 50 localHostClient := suite.chainA.GetClientState(exported.Localhost) 51 suite.Require().Equal(prevHeight, localHostClient.GetLatestHeight()) 52 53 for i := 0; i < 10; i++ { 54 // increment height 55 suite.coordinator.CommitBlock(suite.chainA, suite.chainB) 56 57 suite.Require().NotPanics(func() { 58 client.BeginBlocker(suite.chainA.GetContext(), suite.chainA.App().GetIBCKeeper().ClientKeeper) 59 }, "BeginBlocker shouldn't panic") 60 61 localHostClient = suite.chainA.GetClientState(exported.Localhost) 62 suite.Require().Equal(prevHeight.Increment(), localHostClient.GetLatestHeight()) 63 prevHeight = localHostClient.GetLatestHeight().(types.Height) 64 } 65 }