From 89fdb1ed2baf0f4c60c81b1b7d28bfc571f8baff Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Mon, 15 Apr 2024 09:28:42 +0100 Subject: [PATCH] chore: address linter findings in 07-tendermint (#6136) * Address linting issues in various modules. * Fixed missing return * Linting issues in 09-localhost. * Update modules/light-clients/06-solomachine/store.go Co-authored-by: DimitrisJim * Add newlines before return. * Address lint issues in 07-tendermint * Address more linter issues in 07-tendermint. * Revert changes included in different PR * Revert changes included in different PR. * Revert changes. * Revert changes. --------- Co-authored-by: DimitrisJim Co-authored-by: Charly Co-authored-by: Damian Nolan --- .../07-tendermint/header_test.go | 4 +- .../07-tendermint/light_client_module_test.go | 12 +- .../07-tendermint/misbehaviour_handle_test.go | 156 ++++++++++++------ .../07-tendermint/proposal_handle_test.go | 22 ++- .../07-tendermint/update_test.go | 123 +++++++++----- .../07-tendermint/upgrade_test.go | 12 +- 6 files changed, 221 insertions(+), 108 deletions(-) diff --git a/modules/light-clients/07-tendermint/header_test.go b/modules/light-clients/07-tendermint/header_test.go index 81957d4c00c..42b3fa5de97 100644 --- a/modules/light-clients/07-tendermint/header_test.go +++ b/modules/light-clients/07-tendermint/header_test.go @@ -42,7 +42,9 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() { header.SignedHeader.Commit = nil }, false}, {"trusted height is equal to header height", func() { - header.TrustedHeight = header.GetHeight().(clienttypes.Height) + var ok bool + header.TrustedHeight, ok = header.GetHeight().(clienttypes.Height) + suite.Require().True(ok) }, false}, {"validator set nil", func() { header.ValidatorSet = nil diff --git a/modules/light-clients/07-tendermint/light_client_module_test.go b/modules/light-clients/07-tendermint/light_client_module_test.go index db1a9ea90d3..7c86457bbbc 100644 --- a/modules/light-clients/07-tendermint/light_client_module_test.go +++ b/modules/light-clients/07-tendermint/light_client_module_test.go @@ -341,7 +341,8 @@ func (suite *TendermintTestSuite) TestRecoverClient() { // assert that status of subject client is now Active clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, subjectClientID) - tmClientState := subjectPath.EndpointA.GetClientState().(*ibctm.ClientState) + tmClientState, ok := subjectPath.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().Equal(exported.Active, tmClientState.Status(ctx, clientStore, suite.chainA.App.AppCodec())) } else { suite.Require().Error(err) @@ -435,12 +436,14 @@ func (suite *TendermintTestSuite) TestVerifyUpgradeAndUpdateState() { suite.Require().NoError(err) // change upgraded client state height to be lower than current client state height - tmClient := upgradedClientState.(*ibctm.ClientState) + tmClient, ok := upgradedClientState.(*ibctm.ClientState) + suite.Require().True(ok) newLatestheight, ok := path.EndpointA.GetClientLatestHeight().Decrement() suite.Require().True(ok) - tmClient.LatestHeight = newLatestheight.(clienttypes.Height) + tmClient.LatestHeight, ok = newLatestheight.(clienttypes.Height) + suite.Require().True(ok) upgradedClientStateAny, err = codectypes.NewAnyWithValue(tmClient) suite.Require().NoError(err) @@ -464,7 +467,8 @@ func (suite *TendermintTestSuite) TestVerifyUpgradeAndUpdateState() { path.SetupClients() clientID = path.EndpointA.ClientID - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) revisionNumber := clienttypes.ParseChainID(clientState.ChainId) newUnbondindPeriod := ubdPeriod + trustingPeriod diff --git a/modules/light-clients/07-tendermint/misbehaviour_handle_test.go b/modules/light-clients/07-tendermint/misbehaviour_handle_test.go index 835f586f7d5..f44dd836688 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_handle_test.go +++ b/modules/light-clients/07-tendermint/misbehaviour_handle_test.go @@ -39,7 +39,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }{ { "valid fork misbehaviour", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -47,7 +48,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -58,7 +60,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid time misbehaviour", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -72,7 +75,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid time misbehaviour, header 1 time strictly less than header 2 time", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -86,7 +90,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid misbehavior at height greater than last consensusState", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -99,7 +104,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid misbehaviour with different trusted heights", func() { - trustedHeight1 := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight1, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals1, err := suite.chainB.GetTrustedValidators(int64(trustedHeight1.RevisionHeight)) suite.Require().NoError(err) @@ -107,7 +113,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - trustedHeight2 := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight2, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals2, err := suite.chainB.GetTrustedValidators(int64(trustedHeight2.RevisionHeight)) suite.Require().NoError(err) @@ -121,7 +128,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid misbehaviour at a previous revision", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -129,7 +137,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -144,12 +153,14 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid misbehaviour at a future revision", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) futureRevision := fmt.Sprintf("%s-%d", strings.TrimSuffix(suite.chainB.ChainID, fmt.Sprintf("-%d", clienttypes.ParseChainID(suite.chainB.ChainID))), height.GetRevisionNumber()+1) @@ -162,7 +173,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "valid misbehaviour with trusted heights at a previous revision", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -171,7 +183,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointB.UpgradeChain() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -182,7 +195,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "consensus state's valset hash different from misbehaviour should still pass", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -190,7 +204,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) // Create bothValSet with both suite validator and altVal bothValSet := cmttypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altValSet.Proposer)) @@ -205,7 +220,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "invalid misbehaviour: misbehaviour from different chain", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -213,7 +229,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader("evmos", int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -223,12 +240,14 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "misbehaviour trusted validators does not match validator hash in trusted consensus state", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) err := path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, altValSet, suite.chainB.Signers), @@ -238,7 +257,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "trusted consensus state does not exist", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -256,7 +276,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "trusting period expired", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -264,7 +285,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) suite.chainA.ExpireClient(path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod) @@ -276,7 +298,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "header 1 valset has too much change", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -284,7 +307,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), @@ -294,7 +318,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "header 2 valset has too much change", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -302,7 +327,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -312,7 +338,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { }, { "both header 1 and header 2 valsets have too much change", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -320,7 +347,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), @@ -342,7 +370,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviour() { tc.malleate() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, misbehaviour) @@ -387,7 +416,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }{ { "valid fork misbehaviour", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -395,7 +425,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -406,7 +437,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "valid time misbehaviour", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -420,7 +452,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "valid time misbehaviour, header 1 time strictly less than header 2 time", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -434,7 +467,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "valid misbehavior at height greater than last consensusState", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -447,7 +481,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "valid misbehaviour with different trusted heights", func() { - trustedHeight1 := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight1, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals1, err := suite.chainB.GetTrustedValidators(int64(trustedHeight1.RevisionHeight)) suite.Require().NoError(err) @@ -455,7 +490,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - trustedHeight2 := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight2, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals2, err := suite.chainB.GetTrustedValidators(int64(trustedHeight2.RevisionHeight)) suite.Require().NoError(err) @@ -469,7 +505,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "consensus state's valset hash different from misbehaviour should still pass", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -477,7 +514,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) // Create bothValSet with both suite validator and altVal bothValSet := cmttypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altValSet.Proposer)) @@ -492,7 +530,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "invalid misbehaviour: misbehaviour from different chain", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -500,7 +539,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader("evmos", int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -510,12 +550,14 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "misbehaviour trusted validators does not match validator hash in trusted consensus state", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, altValSet, suite.chainB.Signers), @@ -525,7 +567,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "trusted consensus state does not exist", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -543,7 +586,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "trusting period expired", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -551,7 +595,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) suite.chainA.ExpireClient(path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod) @@ -563,7 +608,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "header 1 valset has too much change", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -571,7 +617,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), @@ -581,7 +628,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "header 2 valset has too much change", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -589,7 +637,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), @@ -599,7 +648,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { }, { "both header 1 and header 2 valsets have too much change", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -607,7 +657,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviour = &ibctm.Misbehaviour{ Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), @@ -629,7 +680,8 @@ func (suite *TendermintTestSuite) TestVerifyMisbehaviourNonRevisionChainID() { tc.malleate() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, misbehaviour) diff --git a/modules/light-clients/07-tendermint/proposal_handle_test.go b/modules/light-clients/07-tendermint/proposal_handle_test.go index 7f9b14a27fa..f7eb58e91d3 100644 --- a/modules/light-clients/07-tendermint/proposal_handle_test.go +++ b/modules/light-clients/07-tendermint/proposal_handle_test.go @@ -48,7 +48,8 @@ func (suite *TendermintTestSuite) TestCheckSubstituteUpdateStateBasic() { substitutePath = ibctesting.NewPath(suite.chainA, suite.chainB) subjectPath.SetupClients() - subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*ibctm.ClientState) + subjectClientState, ok := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) // expire subject client suite.coordinator.IncrementTimeBy(subjectClientState.TrustingPeriod) @@ -92,7 +93,8 @@ func (suite *TendermintTestSuite) TestCheckSubstituteAndUpdateState() { // construct subject using test case parameters subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) subjectPath.SetupClients() - subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*ibctm.ClientState) + subjectClientState, ok := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) if tc.FreezeClient { subjectClientState.FrozenHeight = frozenHeight @@ -102,7 +104,8 @@ func (suite *TendermintTestSuite) TestCheckSubstituteAndUpdateState() { substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB) substitutePath.SetupClients() - substituteClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*ibctm.ClientState) + substituteClientState, ok := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) // update trusting period of substitute client state substituteClientState.TrustingPeriod = time.Hour * 24 * 7 suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID, substituteClientState) @@ -116,7 +119,8 @@ func (suite *TendermintTestSuite) TestCheckSubstituteAndUpdateState() { } // get updated substitute - substituteClientState = suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*ibctm.ClientState) + substituteClientState, ok = suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) // test that subject gets updated chain-id newChainID := "new-chain-id" @@ -137,7 +141,8 @@ func (suite *TendermintTestSuite) TestCheckSubstituteAndUpdateState() { if tc.expPass { suite.Require().NoError(err) - updatedClient := subjectPath.EndpointA.GetClientState().(*ibctm.ClientState) + updatedClient, ok := subjectPath.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().Equal(clienttypes.ZeroHeight(), updatedClient.FrozenHeight) subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) @@ -178,8 +183,11 @@ func (suite *TendermintTestSuite) TestIsMatchingClientState() { }{ { "matching clients", func() { - subjectClientState = suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*ibctm.ClientState) - substituteClientState = suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*ibctm.ClientState) + var ok bool + subjectClientState, ok = suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) + substituteClientState, ok = suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) }, true, }, { diff --git a/modules/light-clients/07-tendermint/update_test.go b/modules/light-clients/07-tendermint/update_test.go index 7b6a6032248..b28b928babb 100644 --- a/modules/light-clients/07-tendermint/update_test.go +++ b/modules/light-clients/07-tendermint/update_test.go @@ -47,7 +47,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "successful verify header for header with a previous height", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -66,7 +67,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "successful verify header: header with future height and different validator set", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -83,7 +85,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "successful verify header: header with next height and different validator set", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -100,7 +103,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful updates, passed in incorrect trusted validators for given consensus state", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) // Create bothValSet with both suite validator and altVal bothValSet := cmttypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) @@ -114,7 +118,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful verify header with next height: update header mismatches nextValSetHash", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -127,7 +132,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful update with future height: too much change in validator set", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -139,7 +145,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful verify header: header height revision and trusted height revision mismatch", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -150,7 +157,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful verify header: header height < consensus height", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -173,7 +181,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful verify header: header timestamp is not past last client timestamp", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -185,7 +194,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful verify header: header with incorrect header chain-id", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -197,7 +207,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful update: trusting period has passed since last client timestamp", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight)) suite.Require().NoError(err) @@ -211,7 +222,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful update for a previous revision", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -228,7 +240,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "successful update with identical header to a previous update", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -246,7 +259,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful update to a future revision", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -259,7 +273,8 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { { name: "unsuccessful update: header height revision and trusted height revision mismatch", malleate: func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -285,13 +300,15 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { // ensure counterparty state is committed suite.coordinator.CommitBlock(suite.chainB) - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) header, err = path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) tc.malleate() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) @@ -333,7 +350,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { tmHeader, ok := clientMessage.(*ibctm.Header) suite.Require().True(ok) - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().True(clientState.LatestHeight.EQ(tmHeader.GetHeight())) // new update, updated client state should have changed suite.Require().True(clientState.LatestHeight.EQ(consensusHeights[0])) }, true, @@ -353,7 +371,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { prevClientState = path.EndpointA.GetClientState() }, func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().Equal(clientState, prevClientState) // fill in height, no change to client state suite.Require().True(clientState.LatestHeight.GT(consensusHeights[0])) }, true, @@ -365,7 +384,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { suite.Require().NoError(err) // use the same header which just updated the client - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) clientMessage, err = path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) @@ -377,7 +397,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { prevConsensusState = path.EndpointA.GetConsensusState(tmHeader.GetHeight()) }, func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().Equal(clientState, prevClientState) suite.Require().True(clientState.LatestHeight.EQ(consensusHeights[0])) @@ -391,7 +412,9 @@ func (suite *TendermintTestSuite) TestUpdateState() { // this height will be expired and pruned err := path.EndpointA.UpdateClient() suite.Require().NoError(err) - pruneHeight = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + var ok bool + pruneHeight, ok = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) // Increment the time by a week suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) @@ -408,7 +431,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { // ensure counterparty state is committed suite.coordinator.CommitBlock(suite.chainB) - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) clientMessage, err = path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) }, @@ -416,7 +440,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { tmHeader, ok := clientMessage.(*ibctm.Header) suite.Require().True(ok) - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().True(clientState.LatestHeight.EQ(tmHeader.GetHeight())) // new update, updated client state should have changed suite.Require().True(clientState.LatestHeight.EQ(consensusHeights[0])) @@ -430,7 +455,9 @@ func (suite *TendermintTestSuite) TestUpdateState() { // this height will be expired and pruned err := path.EndpointA.UpdateClient() suite.Require().NoError(err) - pruneHeight = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + var ok bool + pruneHeight, ok = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) // assert that a consensus state exists at the prune height consensusState, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) @@ -451,7 +478,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { suite.Require().NoError(err) // use the same header which just updated the client - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) clientMessage, err = path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) }, @@ -459,7 +487,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { tmHeader, ok := clientMessage.(*ibctm.Header) suite.Require().True(ok) - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().True(clientState.LatestHeight.EQ(tmHeader.GetHeight())) // new update, updated client state should have changed suite.Require().True(clientState.LatestHeight.EQ(consensusHeights[0])) @@ -488,19 +517,23 @@ func (suite *TendermintTestSuite) TestUpdateState() { // ensure counterparty state is committed suite.coordinator.CommitBlock(suite.chainB) - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) clientMessage, err = path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) tc.malleate() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) if tc.expPass { consensusHeights = clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) - header := clientMessage.(*ibctm.Header) + header, ok := clientMessage.(*ibctm.Header) + suite.Require().True(ok) + expConsensusState := &ibctm.ConsensusState{ Timestamp: header.GetTime(), Root: commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), @@ -542,7 +575,8 @@ func (suite *TendermintTestSuite) TestPruneConsensusState() { // this height will be expired but not pruned err := path.EndpointA.UpdateClient() suite.Require().NoError(err) - expiredHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + expiredHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) // expected values that must still remain in store after pruning expectedConsState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) @@ -644,7 +678,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { }, { "invalid fork misbehaviour: identical headers", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -652,7 +687,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - height := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + height, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) misbehaviourHeader := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.ProposedHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) clientMessage = &ibctm.Misbehaviour{ @@ -663,7 +699,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { }, { "invalid time misbehaviour: monotonically increasing time", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -722,7 +759,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { { "valid fork misbehaviour returns true", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) header1, err := path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) @@ -731,7 +769,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { err = path.EndpointA.UpdateClient() suite.Require().NoError(err) - trustedHeight = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) header2, err := path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) @@ -748,7 +787,8 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { }, { "valid time misbehaviour: not monotonically increasing time", func() { - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) trustedVals, err := suite.chainB.GetTrustedValidators(int64(trustedHeight.RevisionHeight) + 1) suite.Require().NoError(err) @@ -773,13 +813,15 @@ func (suite *TendermintTestSuite) TestCheckForMisbehaviour() { // ensure counterparty state is committed suite.coordinator.CommitBlock(suite.chainB) - trustedHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + trustedHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) clientMessage, err = path.EndpointA.Counterparty.Chain.IBCClientHeader(path.EndpointA.Counterparty.Chain.LatestCommittedHeader, trustedHeight) suite.Require().NoError(err) tc.malleate() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) foundMisbehaviour := clientState.CheckForMisbehaviour( @@ -826,7 +868,8 @@ func (suite *TendermintTestSuite) TestUpdateStateOnMisbehaviour() { tc.malleate() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) clientState.UpdateStateOnMisbehaviour(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, nil) diff --git a/modules/light-clients/07-tendermint/upgrade_test.go b/modules/light-clients/07-tendermint/upgrade_test.go index 4715aad3961..cf71574c377 100644 --- a/modules/light-clients/07-tendermint/upgrade_test.go +++ b/modules/light-clients/07-tendermint/upgrade_test.go @@ -320,7 +320,8 @@ func (suite *TendermintTestSuite) TestVerifyUpgrade() { upgradedConsensusStateProof, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), tmCs.LatestHeight.GetRevisionHeight()) // SetClientState with empty upgrade path - tmClient, _ := cs.(*ibctm.ClientState) + tmClient, ok := cs.(*ibctm.ClientState) + suite.Require().True(ok) tmClient.UpgradePath = []string{""} suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID, tmClient) }, @@ -469,7 +470,8 @@ func (suite *TendermintTestSuite) TestVerifyUpgrade() { path.SetupClients() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) revisionNumber := clienttypes.ParseChainID(clientState.ChainId) var err error @@ -489,7 +491,8 @@ func (suite *TendermintTestSuite) TestVerifyUpgrade() { tc.setup() - cs := suite.chainA.GetClientState(path.EndpointA.ClientID).(*ibctm.ClientState) + cs, ok := suite.chainA.GetClientState(path.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) // Call ZeroCustomFields on upgraded clients to clear any client-chosen parameters in test-case upgradedClient @@ -508,7 +511,8 @@ func (suite *TendermintTestSuite) TestVerifyUpgrade() { if tc.expPass { suite.Require().NoError(err, "verify upgrade failed on valid case: %s", tc.name) - clientState := suite.chainA.GetClientState(path.EndpointA.ClientID).(*ibctm.ClientState) + clientState, ok := suite.chainA.GetClientState(path.EndpointA.ClientID).(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().NotNil(clientState, "verify upgrade failed on valid case: %s", tc.name) consensusState, found := suite.chainA.GetConsensusState(path.EndpointA.ClientID, clientState.LatestHeight)