Skip to content

Commit

Permalink
Address more linter issues in 07-tendermint.
Browse files Browse the repository at this point in the history
  • Loading branch information
bznein committed Apr 10, 2024
1 parent 3bb7ab3 commit 333c1be
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 58 deletions.
26 changes: 18 additions & 8 deletions modules/light-clients/07-tendermint/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion modules/light-clients/07-tendermint/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
15 changes: 10 additions & 5 deletions modules/light-clients/07-tendermint/misbehaviour_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -502,15 +505,17 @@ 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)

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))
Expand Down
Loading

0 comments on commit 333c1be

Please sign in to comment.