Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests: update tests in 03-connection, use expected errors #7666

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 60 additions & 31 deletions modules/core/03-connection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package keeper_test
import (
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/types/query"

clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/keeper"
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
)
Expand All @@ -21,21 +27,21 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connectionID",
func() {
req = &types.QueryConnectionRequest{}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -44,7 +50,10 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
ConnectionId: ibctesting.InvalidID,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "IDisInvalid").Error(),
),
},
{
"success",
Expand All @@ -62,7 +71,7 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
ConnectionId: path.EndpointA.ConnectionID,
}
},
true,
nil,
},
}

Expand All @@ -78,12 +87,13 @@ func (suite *KeeperTestSuite) TestQueryConnection() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.Connection(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(&expConnection, res.Connection)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -104,21 +114,21 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"empty pagination",
func() {
req = &types.QueryConnectionsRequest{}
},
true,
nil,
},
{
"success",
Expand Down Expand Up @@ -155,7 +165,7 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
},
}
},
true,
nil,
},
}

Expand All @@ -171,12 +181,13 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.Connections(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expConnections, res.Connections)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -191,21 +202,21 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connectionID",
func() {
req = &types.QueryClientConnectionsRequest{}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -214,7 +225,10 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
ClientId: ibctesting.InvalidID,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrClientConnectionPathsNotFound, "IDisInvalid").Error(),
),
},
{
"success",
Expand All @@ -236,7 +250,7 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
ClientId: path1.EndpointA.ClientID,
}
},
true,
nil,
},
}

Expand All @@ -252,12 +266,13 @@ func (suite *KeeperTestSuite) TestQueryClientConnections() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.ClientConnections(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expPaths, res.ConnectionPaths)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -272,14 +287,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connection ID",
Expand All @@ -288,7 +303,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: "",
}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -297,7 +312,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: "test-connection-id",
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "connection-id: test-connection-id").Error(),
),
},
{
"client state not found",
Expand All @@ -311,7 +329,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
req = &types.QueryConnectionClientStateRequest{
ConnectionId: path.EndpointA.ConnectionID,
}
}, false,
}, status.Error(
codes.NotFound,
errorsmod.Wrap(clienttypes.ErrClientNotFound, "client-id: ").Error(),
),
},
{
"success",
Expand All @@ -326,7 +347,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
ConnectionId: path.EndpointA.ConnectionID,
}
},
true,
nil,
},
}

Expand All @@ -342,7 +363,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.ConnectionClientState(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState)
Expand All @@ -352,6 +373,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand All @@ -367,14 +389,14 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
testCases := []struct {
msg string
malleate func()
expPass bool
expErr error
}{
{
"empty request",
func() {
req = nil
},
false,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"invalid connection ID",
Expand All @@ -385,7 +407,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: 1,
}
},
false,
status.Error(codes.InvalidArgument, errorsmod.Wrap(host.ErrInvalidID, "identifier cannot be blank").Error()),
},
{
"connection not found",
Expand All @@ -396,7 +418,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: 1,
}
},
false,
status.Error(
codes.NotFound,
errorsmod.Wrap(types.ErrConnectionNotFound, "connection-id: test-connection-id").Error(),
),
},
{
"consensus state not found",
Expand All @@ -409,7 +434,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionNumber: 0,
RevisionHeight: uint64(suite.chainA.GetContext().BlockHeight()), // use current height
}
}, false,
}, status.Error(
codes.NotFound,
errorsmod.Wrap(clienttypes.ErrConsensusStateNotFound, "client-id: 07-tendermint-0").Error(),
),
},
{
"success",
Expand All @@ -429,7 +457,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
RevisionHeight: clientHeight.GetRevisionHeight(),
}
},
true,
nil,
},
}

Expand All @@ -445,7 +473,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
queryServer := keeper.NewQueryServer(suite.chainA.App.GetIBCKeeper().ConnectionKeeper)
res, err := queryServer.ConnectionConsensusState(ctx, req)

if tc.expPass {
if tc.expErr == nil {
suite.Require().NoError(err)
suite.Require().NotNil(res)
consensusState, err := clienttypes.UnpackConsensusState(res.ConsensusState)
Expand All @@ -458,6 +486,7 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
Expand Down
Loading
Loading