From cbf43eaf2ea7cdb74f5d03c33e95372c13ee64c7 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 9 Apr 2024 15:59:39 +0100 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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 }