Skip to content

Commit

Permalink
(chore) update tests in modules/light-clients/07-tendermint/ tests to…
Browse files Browse the repository at this point in the history
… expect specific error (#7665)

* fix: codec test

* chore: make lint-fix

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
NagaTulasi and DimitrisJim authored Dec 12, 2024
1 parent dc91e9c commit 951a148
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 90 deletions.
24 changes: 13 additions & 11 deletions modules/light-clients/07-tendermint/header_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tendermint_test

import (
"errors"
"time"

cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
Expand All @@ -25,37 +26,37 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
testCases := []struct {
name string
malleate func()
expPass bool
expErr error
}{
{"valid header", func() {}, true},
{"valid header", func() {}, nil},
{"header is nil", func() {
header.Header = nil
}, false},
}, errors.New("tendermint header cannot be nil")},
{"signed header is nil", func() {
header.SignedHeader = nil
}, false},
}, errors.New("tendermint signed header cannot be nil")},
{"SignedHeaderFromProto failed", func() {
header.SignedHeader.Commit.Height = -1
}, false},
}, errors.New("header is not a tendermint header")},
{"signed header failed tendermint ValidateBasic", func() {
header = suite.chainA.LatestCommittedHeader
header.SignedHeader.Commit = nil
}, false},
}, errors.New("header failed basic validation")},
{"trusted height is equal to header height", func() {
var ok bool
header.TrustedHeight, ok = header.GetHeight().(clienttypes.Height)
suite.Require().True(ok)
}, false},
}, errors.New("invalid header height")},
{"validator set nil", func() {
header.ValidatorSet = nil
}, false},
}, errors.New("invalid client header")},
{"ValidatorSetFromProto failed", func() {
header.ValidatorSet.Validators[0].PubKey = cmtprotocrypto.PublicKey{}
}, false},
}, errors.New("validator set is not tendermint validator set")},
{"header validator hash does not equal hash of validator set", func() {
// use chainB's randomly generated validator set
header.ValidatorSet = suite.chainB.LatestCommittedHeader.ValidatorSet
}, false},
}, errors.New("validator set does not match hash")},
}

suite.Require().Equal(exported.Tendermint, suite.header.ClientType())
Expand All @@ -72,10 +73,11 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() {

err := header.ValidateBasic()

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
suite.Require().ErrorContains(err, tc.expErr.Error())
}
})
}
Expand Down
Loading

0 comments on commit 951a148

Please sign in to comment.