From cbf43eaf2ea7cdb74f5d03c33e95372c13ee64c7 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 9 Apr 2024 15:59:39 +0100 Subject: [PATCH 01/11] Address linting issues in various modules. --- modules/core/04-channel/keeper/packet_test.go | 4 +++- modules/core/04-channel/types/msgs_test.go | 5 +++-- .../06-solomachine/light_client_module_test.go | 9 ++++++--- .../06-solomachine/solomachine_test.go | 3 ++- modules/light-clients/06-solomachine/store.go | 8 +++++++- modules/light-clients/07-tendermint/store.go | 15 +++++++++++++-- modules/light-clients/07-tendermint/update.go | 5 ++++- 7 files changed, 38 insertions(+), 11 deletions(-) diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index 0791dfdd39c..7fe6fe83fca 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -150,7 +150,9 @@ func (suite *KeeperTestSuite) TestSendPacket() { path.Setup() sourceChannel = path.EndpointA.ChannelID - timeoutHeight = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + var ok bool + timeoutHeight, ok = path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) }, false}, {"timeout timestamp passed", func() { diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index b6d196133af..884700adc3d 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -9,7 +9,7 @@ import ( testifysuite "github.com/stretchr/testify/suite" errorsmod "cosmossdk.io/errors" - log "cosmossdk.io/log" + "cosmossdk.io/log" "cosmossdk.io/store/iavl" "cosmossdk.io/store/metrics" "cosmossdk.io/store/rootmulti" @@ -94,7 +94,8 @@ func (suite *TypesTestSuite) SetupTest() { store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) err := store.LoadVersion(0) suite.Require().NoError(err) - iavlStore := store.GetCommitStore(storeKey).(*iavl.Store) + iavlStore, ok := store.GetCommitStore(storeKey).(*iavl.Store) + suite.Require().True(ok) iavlStore.Set([]byte("KEY"), []byte("VALUE")) _ = store.Commit() diff --git a/modules/light-clients/06-solomachine/light_client_module_test.go b/modules/light-clients/06-solomachine/light_client_module_test.go index 5accf3e0579..d853cbf42d5 100644 --- a/modules/light-clients/06-solomachine/light_client_module_test.go +++ b/modules/light-clients/06-solomachine/light_client_module_test.go @@ -683,7 +683,8 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { // Grab fresh client state after updates. cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), clientID) suite.Require().True(found) - clientState = cs.(*solomachine.ClientState) + clientState, ok = cs.(*solomachine.ClientState) + suite.Require().True(ok) suite.Require().NoError(err) // clientState.Sequence is the most recent view of state. @@ -907,7 +908,8 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { // Grab fresh client state after updates. cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), clientID) suite.Require().True(found) - clientState = cs.(*solomachine.ClientState) + clientState, ok = cs.(*solomachine.ClientState) + suite.Require().True(ok) suite.Require().NoError(err) suite.Require().Equal(expSeq, clientState.Sequence) @@ -1005,7 +1007,8 @@ func (suite *SoloMachineTestSuite) TestRecoverClient() { // assert that status of subject client is now Active clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, subjectClientID) bz = clientStore.Get(host.ClientStateKey()) - smClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, bz).(*solomachine.ClientState) + smClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, bz).(*solomachine.ClientState) + suite.Require().True(ok) suite.Require().Equal(substituteClientState.ConsensusState, smClientState.ConsensusState) suite.Require().Equal(substituteClientState.Sequence, smClientState.Sequence) diff --git a/modules/light-clients/06-solomachine/solomachine_test.go b/modules/light-clients/06-solomachine/solomachine_test.go index 3b43200b4b7..b4c7ae9215c 100644 --- a/modules/light-clients/06-solomachine/solomachine_test.go +++ b/modules/light-clients/06-solomachine/solomachine_test.go @@ -145,7 +145,8 @@ func (suite *SoloMachineTestSuite) GetSequenceFromStore() uint64 { err := suite.chainA.Codec.UnmarshalInterface(bz, &clientState) suite.Require().NoError(err) - smClientState := clientState.(*solomachine.ClientState) + smClientState, ok := clientState.(*solomachine.ClientState) + suite.Require().True(ok) return smClientState.Sequence } diff --git a/modules/light-clients/06-solomachine/store.go b/modules/light-clients/06-solomachine/store.go index 87757942596..561580b6919 100644 --- a/modules/light-clients/06-solomachine/store.go +++ b/modules/light-clients/06-solomachine/store.go @@ -1,6 +1,8 @@ package solomachine import ( + "fmt" + storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -18,5 +20,9 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta } clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) - return clientStateI.(*ClientState), true + var clientState *ClientState + clientState, ok := clientStateI.(*ClientState) + if !ok { + panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState)) + } } diff --git a/modules/light-clients/07-tendermint/store.go b/modules/light-clients/07-tendermint/store.go index 3c0bd6f55a5..4285bba5701 100644 --- a/modules/light-clients/07-tendermint/store.go +++ b/modules/light-clients/07-tendermint/store.go @@ -3,6 +3,7 @@ package tendermint import ( "bytes" "encoding/binary" + "fmt" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" @@ -59,7 +60,12 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta } clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) - return clientStateI.(*ClientState), true + var clientState *ClientState + clientState, ok := clientStateI.(*ClientState) + if !ok { + panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState)) + } + return clientState, true } // setConsensusState stores the consensus state at the given height. @@ -78,7 +84,12 @@ func GetConsensusState(store storetypes.KVStore, cdc codec.BinaryCodec, height e } consensusStateI := clienttypes.MustUnmarshalConsensusState(cdc, bz) - return consensusStateI.(*ConsensusState), true + var consensusState *ConsensusState + consensusState, ok := consensusStateI.(*ConsensusState) + if !ok { + panic(fmt.Errorf("cannot convert %T into %T", consensusStateI, consensusState)) + } + return consensusState, true } // deleteConsensusState deletes the consensus state at the given height diff --git a/modules/light-clients/07-tendermint/update.go b/modules/light-clients/07-tendermint/update.go index 4b3a893706a..e01786a79d1 100644 --- a/modules/light-clients/07-tendermint/update.go +++ b/modules/light-clients/07-tendermint/update.go @@ -145,7 +145,10 @@ func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, client return []exported.Height{header.GetHeight()} } - height := header.GetHeight().(clienttypes.Height) + height, ok := header.GetHeight().(clienttypes.Height) + if !ok { + panic(fmt.Errorf("cannot convert %T to %T", header.GetHeight(), &clienttypes.Height{})) + } if height.GT(cs.LatestHeight) { cs.LatestHeight = height } From c065dc9314729b9ff9431234e649bf2a41722cfd Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 9 Apr 2024 16:03:59 +0100 Subject: [PATCH 02/11] Fixed missing return --- modules/light-clients/06-solomachine/store.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/light-clients/06-solomachine/store.go b/modules/light-clients/06-solomachine/store.go index 561580b6919..0e0e8d779ea 100644 --- a/modules/light-clients/06-solomachine/store.go +++ b/modules/light-clients/06-solomachine/store.go @@ -25,4 +25,5 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta if !ok { panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState)) } + return clientState, true } From 953d20210a0616707d41f4621748dbc16e2bd812 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 9 Apr 2024 16:06:43 +0100 Subject: [PATCH 03/11] Linting issues in 09-localhost. --- modules/light-clients/09-localhost/client_state_test.go | 4 +++- modules/light-clients/09-localhost/store.go | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/light-clients/09-localhost/client_state_test.go b/modules/light-clients/09-localhost/client_state_test.go index 8cde7d01234..2eac5411d97 100644 --- a/modules/light-clients/09-localhost/client_state_test.go +++ b/modules/light-clients/09-localhost/client_state_test.go @@ -116,6 +116,8 @@ func (suite *LocalhostTestSuite) TestUpdateState() { expHeight := clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight())) suite.Require().True(heights[0].EQ(expHeight)) - clientState = suite.chain.GetClientState(exported.LocalhostClientID).(*localhost.ClientState) + var ok bool + clientState, ok = suite.chain.GetClientState(exported.LocalhostClientID).(*localhost.ClientState) + suite.Require().True(ok) suite.Require().True(heights[0].EQ(clientState.LatestHeight)) } diff --git a/modules/light-clients/09-localhost/store.go b/modules/light-clients/09-localhost/store.go index 39ff6e1297c..abe0c46b65a 100644 --- a/modules/light-clients/09-localhost/store.go +++ b/modules/light-clients/09-localhost/store.go @@ -1,6 +1,8 @@ package localhost import ( + "fmt" + storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -18,5 +20,10 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta } clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) - return clientStateI.(*ClientState), true + var clientState *ClientState + clientState, ok := clientStateI.(*ClientState) + if !ok { + panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState)) + } + return clientState, true } From 75e08fb0148662e8ea17b36704d2133b1b11ffde Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 11:51:23 +0100 Subject: [PATCH 04/11] Update modules/light-clients/06-solomachine/store.go Co-authored-by: DimitrisJim --- modules/light-clients/06-solomachine/store.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/light-clients/06-solomachine/store.go b/modules/light-clients/06-solomachine/store.go index 0e0e8d779ea..f0fa1f3829b 100644 --- a/modules/light-clients/06-solomachine/store.go +++ b/modules/light-clients/06-solomachine/store.go @@ -25,5 +25,6 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta if !ok { panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState)) } + return clientState, true } From 0bc72d3bba79b75dd1dac0ddbb94051d370cb6e0 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 11:53:12 +0100 Subject: [PATCH 05/11] Add newlines before return. --- modules/light-clients/06-solomachine/solomachine_test.go | 1 + modules/light-clients/07-tendermint/store.go | 1 + modules/light-clients/09-localhost/store.go | 1 + 3 files changed, 3 insertions(+) diff --git a/modules/light-clients/06-solomachine/solomachine_test.go b/modules/light-clients/06-solomachine/solomachine_test.go index b4c7ae9215c..53289d29069 100644 --- a/modules/light-clients/06-solomachine/solomachine_test.go +++ b/modules/light-clients/06-solomachine/solomachine_test.go @@ -147,6 +147,7 @@ func (suite *SoloMachineTestSuite) GetSequenceFromStore() uint64 { smClientState, ok := clientState.(*solomachine.ClientState) suite.Require().True(ok) + return smClientState.Sequence } diff --git a/modules/light-clients/07-tendermint/store.go b/modules/light-clients/07-tendermint/store.go index 4285bba5701..f53e5c5b2f0 100644 --- a/modules/light-clients/07-tendermint/store.go +++ b/modules/light-clients/07-tendermint/store.go @@ -89,6 +89,7 @@ func GetConsensusState(store storetypes.KVStore, cdc codec.BinaryCodec, height e if !ok { panic(fmt.Errorf("cannot convert %T into %T", consensusStateI, consensusState)) } + return consensusState, true } diff --git a/modules/light-clients/09-localhost/store.go b/modules/light-clients/09-localhost/store.go index abe0c46b65a..c80b371bc22 100644 --- a/modules/light-clients/09-localhost/store.go +++ b/modules/light-clients/09-localhost/store.go @@ -25,5 +25,6 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta if !ok { panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState)) } + return clientState, true } From 3bb7ab38bf19c2cbc11532b20abe51e2abd2323e Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 12:22:15 +0100 Subject: [PATCH 06/11] Address lint issues in 07-tendermint --- .../07-tendermint/header_test.go | 2 + .../07-tendermint/light_client_module_test.go | 12 +- .../07-tendermint/misbehaviour_handle_test.go | 141 ++++++++++++------ .../07-tendermint/proposal_handle_test.go | 22 ++- 4 files changed, 119 insertions(+), 58 deletions(-) diff --git a/modules/light-clients/07-tendermint/header_test.go b/modules/light-clients/07-tendermint/header_test.go index 81957d4c00c..498a9c9631a 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() { + var ok bool header.TrustedHeight = 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 fef8763a836..1277e664d4b 100644 --- a/modules/light-clients/07-tendermint/light_client_module_test.go +++ b/modules/light-clients/07-tendermint/light_client_module_test.go @@ -102,7 +102,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) @@ -196,12 +197,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) @@ -225,7 +228,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..2be9f7da7d9 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), @@ -162,7 +171,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 +181,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 +193,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 +202,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 +218,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 +227,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 +238,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 +255,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 +274,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 +283,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 +296,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 +305,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 +316,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 +325,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 +336,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 +345,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 +368,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 +414,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 +423,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 +435,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) @@ -434,7 +464,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 +478,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 +487,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) @@ -492,7 +525,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 +534,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 +545,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 +562,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 +581,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 +590,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 +603,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 +612,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 +623,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 +632,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 +643,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 +652,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 +675,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, }, { From 333c1be84f7774c2fdbc7c2c7533770a1f9575f1 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 12:41:18 +0100 Subject: [PATCH 07/11] Address more linter issues in 07-tendermint. --- .../07-tendermint/client_state_test.go | 26 ++-- .../07-tendermint/header_test.go | 2 +- .../07-tendermint/misbehaviour_handle_test.go | 15 ++- .../07-tendermint/update_test.go | 123 ++++++++++++------ .../07-tendermint/upgrade_test.go | 12 +- 5 files changed, 120 insertions(+), 58 deletions(-) diff --git a/modules/light-clients/07-tendermint/client_state_test.go b/modules/light-clients/07-tendermint/client_state_test.go index 0fa2222de6e..dd466740ffb 100644 --- a/modules/light-clients/07-tendermint/client_state_test.go +++ b/modules/light-clients/07-tendermint/client_state_test.go @@ -43,7 +43,9 @@ func (suite *TendermintTestSuite) TestStatus() { path.EndpointA.SetClientState(clientState) }, exported.Frozen}, {"client status without consensus state", func() { - clientState.LatestHeight = clientState.LatestHeight.Increment().(clienttypes.Height) + var ok bool + clientState.LatestHeight, ok = clientState.LatestHeight.Increment().(clienttypes.Height) + suite.Require().True(ok) path.EndpointA.SetClientState(clientState) }, exported.Expired}, {"client status is expired", func() { @@ -60,7 +62,9 @@ func (suite *TendermintTestSuite) TestStatus() { path.SetupClients() clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - clientState = path.EndpointA.GetClientState().(*ibctm.ClientState) + var ok bool + clientState, ok = path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) tc.malleate() @@ -91,7 +95,8 @@ func (suite *TendermintTestSuite) TestGetTimestampAtHeight() { { "failure: consensus state not found for height", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) height = clientState.LatestHeight.Increment() }, clienttypes.ErrConsensusStateNotFound, @@ -106,7 +111,8 @@ func (suite *TendermintTestSuite) TestGetTimestampAtHeight() { path = ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupClients() - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) height = clientState.LatestHeight store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) @@ -332,7 +338,8 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { proof, proofHeight = suite.chainB.QueryProof(key) - consensusState := testingpath.EndpointB.GetConsensusState(latestHeight).(*ibctm.ConsensusState) + consensusState, ok := testingpath.EndpointB.GetConsensusState(latestHeight).(*ibctm.ConsensusState) + suite.Require().True(ok) value, err = suite.chainB.Codec.MarshalInterface(consensusState) suite.Require().NoError(err) }, @@ -528,13 +535,15 @@ func (suite *TendermintTestSuite) TestVerifyMembership() { proof, proofHeight = suite.chainB.QueryProof(key) - clientState := testingpath.EndpointB.GetClientState().(*ibctm.ClientState) + clientState, ok := testingpath.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) value, err = suite.chainB.Codec.MarshalInterface(clientState) suite.Require().NoError(err) tc.malleate() // make changes as necessary - clientState = testingpath.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok = testingpath.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) ctx := suite.chainA.GetContext() store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, testingpath.EndpointA.ClientID) @@ -747,7 +756,8 @@ func (suite *TendermintTestSuite) TestVerifyNonMembership() { tc.malleate() // make changes as necessary - clientState := testingpath.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := testingpath.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) ctx := suite.chainA.GetContext() store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, testingpath.EndpointA.ClientID) diff --git a/modules/light-clients/07-tendermint/header_test.go b/modules/light-clients/07-tendermint/header_test.go index 498a9c9631a..42b3fa5de97 100644 --- a/modules/light-clients/07-tendermint/header_test.go +++ b/modules/light-clients/07-tendermint/header_test.go @@ -43,7 +43,7 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() { }, false}, {"trusted height is equal to header height", func() { var ok bool - header.TrustedHeight = header.GetHeight().(clienttypes.Height) + header.TrustedHeight, ok = header.GetHeight().(clienttypes.Height) suite.Require().True(ok) }, false}, {"validator set nil", func() { diff --git a/modules/light-clients/07-tendermint/misbehaviour_handle_test.go b/modules/light-clients/07-tendermint/misbehaviour_handle_test.go index 2be9f7da7d9..f44dd836688 100644 --- a/modules/light-clients/07-tendermint/misbehaviour_handle_test.go +++ b/modules/light-clients/07-tendermint/misbehaviour_handle_test.go @@ -153,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) @@ -450,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) @@ -502,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) @@ -510,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)) 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) From cd4931d48af6fee881e7f854c7c8869be2e51504 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 12:50:38 +0100 Subject: [PATCH 08/11] Revert changes included in different PR --- .../06-solomachine/light_client_module_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/light-clients/06-solomachine/light_client_module_test.go b/modules/light-clients/06-solomachine/light_client_module_test.go index d853cbf42d5..5accf3e0579 100644 --- a/modules/light-clients/06-solomachine/light_client_module_test.go +++ b/modules/light-clients/06-solomachine/light_client_module_test.go @@ -683,8 +683,7 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() { // Grab fresh client state after updates. cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), clientID) suite.Require().True(found) - clientState, ok = cs.(*solomachine.ClientState) - suite.Require().True(ok) + clientState = cs.(*solomachine.ClientState) suite.Require().NoError(err) // clientState.Sequence is the most recent view of state. @@ -908,8 +907,7 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() { // Grab fresh client state after updates. cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), clientID) suite.Require().True(found) - clientState, ok = cs.(*solomachine.ClientState) - suite.Require().True(ok) + clientState = cs.(*solomachine.ClientState) suite.Require().NoError(err) suite.Require().Equal(expSeq, clientState.Sequence) @@ -1007,8 +1005,7 @@ func (suite *SoloMachineTestSuite) TestRecoverClient() { // assert that status of subject client is now Active clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, subjectClientID) bz = clientStore.Get(host.ClientStateKey()) - smClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, bz).(*solomachine.ClientState) - suite.Require().True(ok) + smClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, bz).(*solomachine.ClientState) suite.Require().Equal(substituteClientState.ConsensusState, smClientState.ConsensusState) suite.Require().Equal(substituteClientState.Sequence, smClientState.Sequence) From 4540d155fe4fce683a367baa8a9c90172e38c78f Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 12:51:59 +0100 Subject: [PATCH 09/11] Revert changes included in different PR. --- modules/light-clients/06-solomachine/solomachine_test.go | 3 +-- modules/light-clients/06-solomachine/store.go | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/modules/light-clients/06-solomachine/solomachine_test.go b/modules/light-clients/06-solomachine/solomachine_test.go index 53289d29069..1757b9a48e1 100644 --- a/modules/light-clients/06-solomachine/solomachine_test.go +++ b/modules/light-clients/06-solomachine/solomachine_test.go @@ -145,8 +145,7 @@ func (suite *SoloMachineTestSuite) GetSequenceFromStore() uint64 { err := suite.chainA.Codec.UnmarshalInterface(bz, &clientState) suite.Require().NoError(err) - smClientState, ok := clientState.(*solomachine.ClientState) - suite.Require().True(ok) + smClientState := clientState.(*solomachine.ClientState) return smClientState.Sequence } diff --git a/modules/light-clients/06-solomachine/store.go b/modules/light-clients/06-solomachine/store.go index f0fa1f3829b..c1ab94d78da 100644 --- a/modules/light-clients/06-solomachine/store.go +++ b/modules/light-clients/06-solomachine/store.go @@ -1,8 +1,6 @@ package solomachine import ( - "fmt" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -21,10 +19,5 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) var clientState *ClientState - clientState, ok := clientStateI.(*ClientState) - if !ok { - panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState)) - } - - return clientState, true + return clientStateI.(*ClientState) } From 7fe144857d145bba95a20a835ad27b7122ba3729 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 12:53:10 +0100 Subject: [PATCH 10/11] Revert changes. --- modules/light-clients/06-solomachine/solomachine_test.go | 1 - modules/light-clients/06-solomachine/store.go | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/light-clients/06-solomachine/solomachine_test.go b/modules/light-clients/06-solomachine/solomachine_test.go index 1757b9a48e1..3b43200b4b7 100644 --- a/modules/light-clients/06-solomachine/solomachine_test.go +++ b/modules/light-clients/06-solomachine/solomachine_test.go @@ -146,7 +146,6 @@ func (suite *SoloMachineTestSuite) GetSequenceFromStore() uint64 { suite.Require().NoError(err) smClientState := clientState.(*solomachine.ClientState) - return smClientState.Sequence } diff --git a/modules/light-clients/06-solomachine/store.go b/modules/light-clients/06-solomachine/store.go index c1ab94d78da..2b504f6c48e 100644 --- a/modules/light-clients/06-solomachine/store.go +++ b/modules/light-clients/06-solomachine/store.go @@ -18,6 +18,5 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta } clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) - var clientState *ClientState return clientStateI.(*ClientState) } From 14b9465a82b86ab4a1c55c7ae9403ea8d5ab2f13 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Wed, 10 Apr 2024 12:53:48 +0100 Subject: [PATCH 11/11] Revert changes. --- modules/light-clients/06-solomachine/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/light-clients/06-solomachine/store.go b/modules/light-clients/06-solomachine/store.go index 2b504f6c48e..87757942596 100644 --- a/modules/light-clients/06-solomachine/store.go +++ b/modules/light-clients/06-solomachine/store.go @@ -18,5 +18,5 @@ func getClientState(store storetypes.KVStore, cdc codec.BinaryCodec) (*ClientSta } clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz) - return clientStateI.(*ClientState) + return clientStateI.(*ClientState), true }