From b1c65fdc6a702863b97445d9f516445276c3042b Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Tue, 9 Apr 2024 11:29:21 +0100 Subject: [PATCH] chore: address linting issues for more modules. (#6121) * Addressed lint issues for 03-connection * Address linter findings of 04-channel and 23-commitments * Address more findings. --- .../03-connection/keeper/grpc_query_test.go | 3 +- .../03-connection/keeper/handshake_test.go | 6 ++-- .../core/03-connection/keeper/verify_test.go | 36 ++++++++++++------- modules/core/03-connection/types/msgs_test.go | 5 +-- .../core/03-connection/types/params_legacy.go | 2 +- modules/core/04-channel/keeper/packet_test.go | 4 ++- modules/core/04-channel/types/msgs_test.go | 5 +-- .../23-commitment/types/commitment_test.go | 4 ++- modules/core/23-commitment/types/utils.go | 2 +- .../core/23-commitment/types/utils_test.go | 2 +- modules/core/exported/client.go | 2 +- modules/core/keeper/msg_server_test.go | 9 +++-- 12 files changed, 52 insertions(+), 28 deletions(-) diff --git a/modules/core/03-connection/keeper/grpc_query_test.go b/modules/core/03-connection/keeper/grpc_query_test.go index 694ca794379..3ffdee2eef8 100644 --- a/modules/core/03-connection/keeper/grpc_query_test.go +++ b/modules/core/03-connection/keeper/grpc_query_test.go @@ -412,7 +412,8 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() { path := ibctesting.NewPath(suite.chainA, suite.chainB) path.SetupConnections() - clientHeight := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + clientHeight, ok := path.EndpointA.GetClientLatestHeight().(clienttypes.Height) + suite.Require().True(ok) expConsensusState, _ = suite.chainA.GetConsensusState(path.EndpointA.ClientID, clientHeight) suite.Require().NotNil(expConsensusState) expClientID = path.EndpointA.ClientID diff --git a/modules/core/03-connection/keeper/handshake_test.go b/modules/core/03-connection/keeper/handshake_test.go index 4b27757e50e..5632e924790 100644 --- a/modules/core/03-connection/keeper/handshake_test.go +++ b/modules/core/03-connection/keeper/handshake_test.go @@ -200,7 +200,8 @@ func (suite *KeeperTestSuite) TestConnOpenTry() { // modify counterparty client without setting in store so it still passes validate but fails proof verification tmClient, ok := counterpartyClient.(*ibctm.ClientState) suite.Require().True(ok) - tmClient.LatestHeight = tmClient.LatestHeight.Increment().(clienttypes.Height) + tmClient.LatestHeight, ok = tmClient.LatestHeight.Increment().(clienttypes.Height) + suite.Require().True(ok) }, false}, {"consensus state verification failed", func() { // retrieve client state of chainA to pass as counterpartyClient @@ -460,7 +461,8 @@ func (suite *KeeperTestSuite) TestConnOpenAck() { // modify counterparty client without setting in store so it still passes validate but fails proof verification tmClient, ok := counterpartyClient.(*ibctm.ClientState) suite.Require().True(ok) - tmClient.LatestHeight = tmClient.LatestHeight.Increment().(clienttypes.Height) + tmClient.LatestHeight, ok = tmClient.LatestHeight.Increment().(clienttypes.Height) + suite.Require().True(ok) err = path.EndpointB.ConnOpenTry() suite.Require().NoError(err) diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index 7867d2271d3..12de9813240 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -36,12 +36,14 @@ func (suite *KeeperTestSuite) TestVerifyClientState() { heightDiff = 5 }, false}, {"verification failed", func() { - counterpartyClient := path.EndpointB.GetClientState().(*ibctm.ClientState) + counterpartyClient, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) counterpartyClient.ChainId = "wrongChainID" path.EndpointB.SetClientState(counterpartyClient) }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -112,7 +114,8 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { suite.coordinator.CommitBlock(suite.chainB) }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -172,7 +175,8 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() { path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.State = types.TRYOPEN }) }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -233,7 +237,8 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() { path.EndpointA.UpdateChannel(func(channel *channeltypes.Channel) { channel.State = channeltypes.TRYOPEN }) }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -309,7 +314,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() { packet.Data = []byte(ibctesting.InvalidID) }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointB.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointB.SetClientState(clientState) }, false}, @@ -399,7 +405,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() { ack = ibcmock.MockFailAcknowledgement }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -503,7 +510,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { suite.Require().NoError(err) }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -532,7 +540,8 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() { connection := path.EndpointA.GetConnection() connection.DelayPeriod = delayTimePeriod - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) if clientState.FrozenHeight.IsZero() { // need to update height to prove absence or receipt suite.coordinator.CommitBlock(suite.chainA, suite.chainB) @@ -602,7 +611,8 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() { offsetSeq = 1 }, false}, {"client status is not active - client is expired", func() { - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointA.SetClientState(clientState) }, false}, @@ -678,7 +688,8 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() { { name: "fails when client state is frozen", malleate: func() { - clientState := path.EndpointB.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointB.SetClientState(clientState) }, @@ -759,7 +770,8 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() { { name: "fails when client state is frozen", malleate: func() { - clientState := path.EndpointB.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.FrozenHeight = clienttypes.NewHeight(0, 1) path.EndpointB.SetClientState(clientState) }, diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index b125baa6e56..9106e3aa15f 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" - log "cosmossdk.io/log" + "cosmossdk.io/log" "cosmossdk.io/store/iavl" "cosmossdk.io/store/metrics" "cosmossdk.io/store/rootmulti" @@ -60,7 +60,8 @@ func (suite *MsgTestSuite) 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/core/03-connection/types/params_legacy.go b/modules/core/03-connection/types/params_legacy.go index c57c3e359e5..99f32271e6d 100644 --- a/modules/core/03-connection/types/params_legacy.go +++ b/modules/core/03-connection/types/params_legacy.go @@ -7,7 +7,7 @@ for migration purposes and will be removed in a future release. package types import ( - fmt "fmt" + "fmt" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) 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/core/23-commitment/types/commitment_test.go b/modules/core/23-commitment/types/commitment_test.go index 6d8a2d227af..2000a4814d7 100644 --- a/modules/core/23-commitment/types/commitment_test.go +++ b/modules/core/23-commitment/types/commitment_test.go @@ -31,7 +31,9 @@ func (suite *MerkleTestSuite) SetupTest() { err := suite.store.LoadVersion(0) suite.Require().NoError(err) - suite.iavlStore = suite.store.GetCommitStore(suite.storeKey).(*iavl.Store) + var ok bool + suite.iavlStore, ok = suite.store.GetCommitStore(suite.storeKey).(*iavl.Store) + suite.Require().True(ok) } func TestMerkleTestSuite(t *testing.T) { diff --git a/modules/core/23-commitment/types/utils.go b/modules/core/23-commitment/types/utils.go index 79530fc51fd..8c5416262d0 100644 --- a/modules/core/23-commitment/types/utils.go +++ b/modules/core/23-commitment/types/utils.go @@ -5,7 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" - crypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + "github.com/cometbft/cometbft/proto/tendermint/crypto" ) // ConvertProofs converts crypto.ProofOps into MerkleProof diff --git a/modules/core/23-commitment/types/utils_test.go b/modules/core/23-commitment/types/utils_test.go index 0cd24b66323..22afcf60a52 100644 --- a/modules/core/23-commitment/types/utils_test.go +++ b/modules/core/23-commitment/types/utils_test.go @@ -7,7 +7,7 @@ import ( storetypes "cosmossdk.io/store/types" - crypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + "github.com/cometbft/cometbft/proto/tendermint/crypto" "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" ) diff --git a/modules/core/exported/client.go b/modules/core/exported/client.go index 8a1bdd980dc..2259b9fdc20 100644 --- a/modules/core/exported/client.go +++ b/modules/core/exported/client.go @@ -1,7 +1,7 @@ package exported import ( - proto "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/gogoproto/proto" storetypes "cosmossdk.io/store/types" diff --git a/modules/core/keeper/msg_server_test.go b/modules/core/keeper/msg_server_test.go index 512b307809c..a6855b0b6a9 100644 --- a/modules/core/keeper/msg_server_test.go +++ b/modules/core/keeper/msg_server_test.go @@ -288,7 +288,8 @@ func (suite *KeeperTestSuite) TestRecoverClient() { // Assert that client status is now Active clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) - tmClientState := subjectPath.EndpointA.GetClientState().(*ibctm.ClientState) + tmClientState, ok := subjectPath.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) suite.Require().Equal(tmClientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec()), exported.Active) } else { suite.Require().Error(err) @@ -870,7 +871,8 @@ func (suite *KeeperTestSuite) TestUpgradeClient() { path.SetupClients() var err error - clientState := path.EndpointA.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointA.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) revisionNumber := clienttypes.ParseChainID(clientState.ChainId) newChainID, err = clienttypes.SetRevisionNumber(clientState.ChainId, revisionNumber+1) @@ -2515,7 +2517,8 @@ func (suite *KeeperTestSuite) TestIBCSoftwareUpgrade() { Height: 1000, } // update trusting period - clientState := path.EndpointB.GetClientState().(*ibctm.ClientState) + clientState, ok := path.EndpointB.GetClientState().(*ibctm.ClientState) + suite.Require().True(ok) clientState.TrustingPeriod += 100 var err error