Skip to content

Commit

Permalink
test: added test cases for custom validator logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored and damiannolan committed Feb 15, 2024
1 parent 97a1b5a commit 97509fe
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions modules/core/02-client/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,6 @@ func (suite KeeperTestSuite) TestGetAllGenesisMetadata() { //nolint:govet // thi
func (suite *KeeperTestSuite) TestGetConsensusState() {
var height types.Height

suite.ctx = suite.ctx.WithBlockHeight(10)

cases := []struct {
name string
malleate func()
Expand All @@ -377,6 +375,30 @@ func (suite *KeeperTestSuite) TestGetConsensusState() {
{"height > latest height", func() {
height = types.NewHeight(0, uint64(suite.ctx.BlockHeight())+1)
}, stakingtypes.ErrNoHistoricalInfo},
{
name: "custom client validator: failure",
malleate: func() {
clientValidator := &mock.ClientValidator{
GetSelfConsensusStateFn: func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) {
return nil, mock.MockApplicationCallbackError
},
}
suite.keeper.SetSelfClientValidator(clientValidator)
},
expError: mock.MockApplicationCallbackError,
},
{
name: "custom client validator: success",
malleate: func() {
clientValidator := &mock.ClientValidator{
GetSelfConsensusStateFn: func(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) {
return &solomachine.ConsensusState{}, nil
},
}
suite.keeper.SetSelfClientValidator(clientValidator)
},
expError: nil,
},
{"latest height - 1", func() {
height = types.NewHeight(0, uint64(suite.ctx.BlockHeight())-1)
}, nil},
Expand All @@ -386,7 +408,10 @@ func (suite *KeeperTestSuite) TestGetConsensusState() {
}

for i, tc := range cases {
suite.SetupTest()
suite.ctx = suite.ctx.WithBlockHeight(10)
tc := tc

height = types.ZeroHeight()

tc.malleate()
Expand Down

0 comments on commit 97509fe

Please sign in to comment.