Skip to content

Commit

Permalink
chore: address linter issues in 04-channel, 06-solomachines, 09-local…
Browse files Browse the repository at this point in the history
…host (#6130)

* Address linting issues in various modules.

* Fixed missing return

* Linting issues in 09-localhost.

* Update modules/light-clients/06-solomachine/store.go

Co-authored-by: DimitrisJim <[email protected]>

* Add newlines before return.

---------

Co-authored-by: DimitrisJim <[email protected]>
Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
3 people authored Apr 12, 2024
1 parent fc5dbed commit eda92ef
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion modules/light-clients/06-solomachine/solomachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 9 additions & 1 deletion modules/light-clients/06-solomachine/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package solomachine

import (
"fmt"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -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
}
16 changes: 14 additions & 2 deletions modules/light-clients/07-tendermint/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tendermint
import (
"bytes"
"encoding/binary"
"fmt"

"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion modules/light-clients/07-tendermint/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion modules/light-clients/09-localhost/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
10 changes: 9 additions & 1 deletion modules/light-clients/09-localhost/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package localhost

import (
"fmt"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -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
}

0 comments on commit eda92ef

Please sign in to comment.