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..53289d29069 100644 --- a/modules/light-clients/06-solomachine/solomachine_test.go +++ b/modules/light-clients/06-solomachine/solomachine_test.go @@ -145,7 +145,9 @@ 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..f0fa1f3829b 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,11 @@ 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)) + } + + return clientState, true } diff --git a/modules/light-clients/07-tendermint/store.go b/modules/light-clients/07-tendermint/store.go index 3c0bd6f55a5..f53e5c5b2f0 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,13 @@ 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 } 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..c80b371bc22 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,11 @@ 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 }