Skip to content

Commit

Permalink
fix: use experror (#7737)
Browse files Browse the repository at this point in the history
* fix: use experror:

* fix

---------

Co-authored-by: DimitrisJim <[email protected]>
Co-authored by: iIvaki <[email protected]>
  • Loading branch information
ikalyak authored Dec 19, 2024
1 parent ca15c9a commit 23bc6bd
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions modules/core/02-client/types/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"errors"
"time"

cmttypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -63,12 +64,12 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
testCases := []struct {
name string
genState types.GenesisState
expPass bool
expError error
}{
{
name: "default",
genState: types.DefaultGenesisState(),
expPass: true,
expError: nil,
},
{
name: "valid custom genesis",
Expand Down Expand Up @@ -104,7 +105,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
2,
),
expPass: true,
expError: nil,
},
{
name: "invalid client type",
Expand All @@ -121,7 +122,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("client state type 07-tendermint does not equal client type in client identifier 06-solomachine"),
},
{
name: "invalid clientid",
Expand Down Expand Up @@ -149,7 +150,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("client state type 07-tendermint does not equal client type in client identifier myclient"),
},
{
name: "consensus state client id does not match client id in genesis clients",
Expand Down Expand Up @@ -177,7 +178,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("consensus state in genesis has a client id 07-tendermint-1 that does not map to a genesis client"),
},
{
name: "invalid consensus state height",
Expand Down Expand Up @@ -205,7 +206,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("consensus state height cannot be zero"),
},
{
name: "invalid consensus state",
Expand Down Expand Up @@ -233,7 +234,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("invalid client consensus state timestamp"),
},
{
name: "client in genesis clients is disallowed by params",
Expand Down Expand Up @@ -261,7 +262,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("client type 07-tendermint not allowed by genesis params"),
},
{
name: "metadata client-id does not match a genesis client",
Expand Down Expand Up @@ -297,7 +298,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("metadata in genesis has a client id wrongclientid that does not map to a genesis client"),
},
{
name: "invalid metadata",
Expand Down Expand Up @@ -333,6 +334,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expError: errors.New("invalid client metadata"),
},
{
name: "invalid params",
Expand Down Expand Up @@ -360,7 +362,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("client type 0 cannot be blank"),
},
{
name: "invalid param",
Expand Down Expand Up @@ -388,7 +390,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("client type 0 cannot be blank"),
},
{
name: "next sequence too small",
Expand Down Expand Up @@ -419,7 +421,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
0,
),
expPass: false,
expError: errors.New("next client identifier sequence 0 must be greater than the maximum sequence used in the provided client identifiers 1"),
},
{
name: "failed to parse client identifier in client state loop",
Expand Down Expand Up @@ -447,7 +449,7 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
5,
),
expPass: false,
expError: errors.New("invalid client identifier my-client is not in format"),
},
{
name: "consensus state different than client state type",
Expand All @@ -471,17 +473,17 @@ func (suite *TypesTestSuite) TestValidateGenesis() {
false,
5,
),
expPass: false,
expError: errors.New("consensus state in genesis has a client id 07-tendermint-0 that does not map to a genesis client"),
},
}

for _, tc := range testCases {
tc := tc
err := tc.genState.Validate()
if tc.expPass {
if tc.expError == nil {
suite.Require().NoError(err, tc.name)
} else {
suite.Require().Error(err, tc.name)
suite.Require().ErrorContains(err, tc.expError.Error())
}
}
}

0 comments on commit 23bc6bd

Please sign in to comment.